macro_rules! assert_contains_regex {
($path:expr, $format:expr) => { ... };
}Expand description
Assert that 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 changelog file. You do this by specifying a regular expression which will be matched against the contents of the file.
The macro calls check_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_mentions_version() {
version_sync::assert_contains_regex!("README.md", "^### Version {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 there is a
heading mentioning the current version of your crate.
The regular expression can contain placeholders which are replaced before the regular expression search begins:
{version}: the current version number of your package.{name}: the name of your package.
This way you can search for things like "Latest version of {name} is: {version}" and make sure you update your READMEs and
changelogs consistently.
§Panics
If the regular expression cannot be found, panic! will be
invoked and your integration test will fail.