When I first tried using assert_contains_match!, I encountered this compile error:
error[E0433]: failed to resolve: use of unresolved module or unlinked crate `regex`
--> src/../tests/uv_test.rs:238:9
|
238 | / assert_contains_match!(
239 | | context.pack_stdout,
240 | | &formatdoc! {"
241 | | [Determining Python version]
... |
258 | | "}
259 | | );
| |_________^ use of unresolved module or unlinked crate `regex`
|
= help: if you wanted to use a crate named `regex`, use `cargo add regex` to add it to your `Cargo.toml`
= note: this error originates in the macro `assert_contains_match` (in Nightly builds, run with -Z macro-backtrace for more info)
This is because the Python CNB didn't have the regex crate in its own dependency list, and while libcnb-test does (so the crate will have been pulled in transitively), since the regex usage is in a macro, after expansion it's as though I've written a use of regex in my own code, and so the dependency needs to be available in the top-level project too.
We should either:
- Mention this in the rustdocs for
assert_contains_match!
- Or, have
libcnb-test re-export the regex crate, and update assert_contains_match! to use that re-export rather than regex directly
Option (2) seems preferable, since:
- it means less manual setup
- if regex were ever to have a breaking change in the future, it will ensure that
libcnb-test's usage of the regex APIs stay consistent with the version actually being used once the macro is expanded (otherwise the parent project might upgrade regex for their own usages, and find the macro breaks)
When I first tried using
assert_contains_match!, I encountered this compile error:This is because the Python CNB didn't have the
regexcrate in its own dependency list, and whilelibcnb-testdoes (so the crate will have been pulled in transitively), since theregexusage is in a macro, after expansion it's as though I've written a use ofregexin my own code, and so the dependency needs to be available in the top-level project too.We should either:
assert_contains_match!libcnb-testre-export theregexcrate, and updateassert_contains_match!to use that re-export rather thanregexdirectlyOption (2) seems preferable, since:
libcnb-test's usage of theregexAPIs stay consistent with the version actually being used once the macro is expanded (otherwise the parent project might upgraderegexfor their own usages, and find the macro breaks)