Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add assert_only_contains_regex! #119

Merged
merged 1 commit into from
Dec 11, 2021
Merged

Add assert_only_contains_regex! #119

merged 1 commit into from
Dec 11, 2021

Conversation

mgeisler
Copy link
Owner

@mgeisler mgeisler commented Dec 5, 2021

This macro compliments the existing assert_contains_regex!. While assert_contains_regex! implements the “exists” quantifier, the new macro implements a “for all” quantifier.

In more details, the macro uses two steps:

  1. Replace {version} in the template by a regular expression which will match any SemVer version number. This allows, say, docs.rs/{name}/{version}/ to match old and outdated occurrences of your package.

  2. Find all matches in the file and check each match against template. This time we replace {version} with pkg_version so that we can do an accurate comparison with the actual package version.

This allows you to ensure that, say, all docs.rs links are updated.

Fixes #72.

@mgeisler
Copy link
Owner Author

mgeisler commented Dec 5, 2021

Hi @alecmocatta, I looked at #72 and this PR should implement your idea. If you're still interested, then please let me know if this does what you expect. Thanks!

@mgeisler mgeisler force-pushed the only-contains-regex branch from 927b9df to a04a360 Compare December 5, 2021 10:20
@alecmocatta
Copy link

Thanks for the ping @mgeisler!

Yeah this addresses exactly what I was looking for, so many thanks and I look forward to adopting it!

One thing maybe worth considering is accepting abridged semver versions where they're "compatible", e.g. permitting https://docs.rs/serde/1/serde/trait.Deserialize.html for version numbers 1.*.*. Per https://doc.rust-lang.org/cargo/reference/semver.html "only changes in the left-most non-zero component are considered incompatible".

@mgeisler
Copy link
Owner Author

One thing maybe worth considering is accepting abridged semver versions where they're "compatible", e.g. permitting https://docs.rs/serde/1/serde/trait.Deserialize.html for version numbers 1.*.*. Per https://doc.rust-lang.org/cargo/reference/semver.html "only changes in the left-most non-zero component are considered incompatible".

Oh, that's a good idea, let me see if I can implement this somehow!

@mgeisler mgeisler force-pushed the only-contains-regex branch 2 times, most recently from 327c1a9 to 63652d6 Compare December 11, 2021 21:42
@mgeisler
Copy link
Owner Author

Okay, I've pushed a new version which compares the versions in the same way as the other macros: so 1.2 is now seen as being compatible with {version} when the package version is 1.2.3. Seems to work pretty well.

This macro compliments the existing `assert_contains_regex!`. While
`assert_contains_regex!` implements the “exists” quantifier, the new
macro implements a “for all” quantifier.

In more details, the macro uses two steps:

1. Replace `{version}` in the `template` by a regular expression which
   will match _any_ SemVer version number. This allows, say,
   `docs.rs/{name}/{version}/` to match old and outdated occurrences
   of your package.

2. Find all matches in the file and check each match against
   `template`. This time we replace `{version}` with `pkg_version` so
   that we can do an accurate comparison with the actual package
   version.

This allows you to ensure that, say, all `docs.rs` links are updated.

Fixes #72.
@mgeisler mgeisler force-pushed the only-contains-regex branch from 50d6c59 to 19b1ed5 Compare December 11, 2021 23:00
@mgeisler mgeisler merged commit 99b5a8b into master Dec 11, 2021
@mgeisler mgeisler deleted the only-contains-regex branch December 11, 2021 23:03
@github-actions github-actions bot mentioned this pull request Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Check all links to docs.rs in README are correct
2 participants