Skip to content

libcnb-test: assert_contains_match! fails to compile unless regex crate manually added #944

Description

@edmorley

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:

  1. Mention this in the rustdocs for assert_contains_match!
  2. 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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions