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.
The
matches!macro is really useful, but like others I'm interested in std getting anassert_matches!macro to mirrorassert_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 implementPartialEq.https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=745f68d5c14ab80b8b1a9be509fd8f26 illustrates an example that produces this error message:
If this were
assert_matches!(bar, Some(x) if x < 2), it could have error output like this:I don't think it's possible to achieve error messages on par with
assert_eqwithout this approach -- could be wrong though.