macro_rules! assert_contains_substring { ($path:expr, $format:expr) => { ... }; }
Expand description
Assert that versions numbers are up to date via substring matching.
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 template which will be matched against the content of the file.
The macro calls check_contains_substring
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.
Usage
The typical way to use this macro is from an integration test:
#[test]
fn test_readme_mentions_version() {
version_sync::assert_contains_substring!("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 template can contain placeholders which are replaced before the 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.
See assert_contains_regex
if you want to search for a regular
expression instead.
Panics
If the substring cannot be found, panic!
will be invoked and
your integration test will fail.