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_matches! based on matches! to mirror assert_eq!? #72991

Closed
anp opened this issue Jun 4, 2020 · 2 comments
Closed

Add assert_matches! based on matches! to mirror assert_eq!? #72991

anp opened this issue Jun 4, 2020 · 2 comments
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@anp
Copy link
Member

anp commented Jun 4, 2020

The matches! macro is really useful, but like others I'm interested in std getting an assert_matches! macro to mirror assert_eq!. While it's nice for readability and concision, my main desire is to get better error messages for tests which assert properties on types that don't implement PartialEq.

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=745f68d5c14ab80b8b1a9be509fd8f26 illustrates an example that produces this error message:

thread 'main' panicked at 'assertion failed: matches!(bar, Some (x) if x < 2)', src/main.rs:7:1

If this were assert_matches!(bar, Some(x) if x < 2), it could have error output like this:

thread 'main' panicked at 'assertion failed: assert_matches!(Some(4), Some (x) if x < 2)', src/main.rs:7:1

I don't think it's possible to achieve error messages on par with assert_eq without this approach -- could be wrong though.

@tamird
Copy link
Contributor

tamird commented Jun 4, 2020

Sounds like #59260 just went stale. Perhaps a similar CL can be considered.

@jonas-schievink jonas-schievink added C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Jun 4, 2020
@joshtriplett
Copy link
Member

We now have an assert_matches!: #82770

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: A feature request, i.e: not implemented / a PR. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants