What’s the most idiomatic way of testing that a #Rust function returns the correct error enum variant? I’ve been using this pattern as it doesn’t require the error enum to be PartialEq:
Edit: Thank you everyone for suggesting the matches! macro (https://doc.rust-lang.org/std/macro.matches.html), which I somehow wasn’t aware of 🤦🏻♀️
matches in std - Rust
Returns whether the given expression matches any of the given patterns.doc.rust-lang.org
This entry was edited (9 months ago)
silwol
•There is also an assert_matches! macro, but that's available on nightly only for now. Really looking forward to the release that brings this to stable.
https://doc.rust-lang.org/std/assert_matches/macro.assert_matches.html
assert_matches in std::assert_matches - Rust
doc.rust-lang.org