Macro version_sync::assert_only_contains_regex[][src]

macro_rules! assert_only_contains_regex {
    ($path : expr, $format : expr) => { ... };
}
Expand description

Assert that all versions numbers are up to date via a regex.

This macro allows you verify that the current version number is mentioned in a particular file, such as a README file. You do this by specifying a regular expression which will be matched against the contents of the file.

The macro calls check_only_contains_regex on the file name given. The package name and current package version is automatically taken from the $CARGO_PKG_NAME and $CARGO_PKG_VERSION environment variables. These environment variables are automatically set by Cargo when compiling your crate.

This macro is enabled by the contains_regex feature.

Usage

The typical way to use this macro is from an integration test:

#[test]
fn test_readme_links_are_updated() {
    version_sync::assert_only_contains_regex!("README.md", "docs.rs/{name}/{version}/");
}

Tests are run with the current directory set to directory where your Cargo.toml file is, so this will find a README.md file next to your Cargo.toml file. It will then check that all links to docs.rs for your crate contain the current version of your crate.

The regular expression can contain placeholders which are replaced as follows:

  • {version}: the version number of your package.
  • {name}: the name of your package.

The {version} placeholder will match compatible versions, meaning that {version} will match all of 1.2.3, 1.2, and 1 when your package is at version 1.2.3.

Panics

If the regular expression cannot be found or if some matches are not updated, panic! will be invoked and your integration test will fail.