assert_matches!
As briefly discussed in https://github.com/bitcoindevkit/bdk/pull/341#discussion_r627858886 and following
we should add https://docs.rs/crate/assert_matches/1.5.0 as a dev-dep which will also be standardized one day https://doc.rust-lang.org/nightly/std/macro.assert_matches.html
And changes our pattern matching test to be like:
assert_matches!(wallet.sign(&mut psbt, options), Err(Error::Signer(SignerError::InputIndexOutOfRange)))
The matches! macro has been stabilized since 1.42.0.
We can (and already do) use it like this: assert!(matches!(...)) to have behavior similar to assert_matches! (though the errors may be less informative).
This way we'll avoid an additional dev-dependency.
though the errors may be less informative
Yeah that's what I like, when assert!(matches!()) test fails I end up printing the values before and launch tests with --nocapture which is unpleasant
what's wrong with
assert_eq!(wallet.sign(&mut psbt, options), Err(Error::Signer(SignerError::InputIndexOutOfRange)))
?
what's wrong with
assert_eq!(wallet.sign(&mut psbt, options), Err(Error::Signer(SignerError::InputIndexOutOfRange)))?
You may want to test something that doesn't impl Eq or do stuff like:
assert_matches!(&policy.item, Signature(pk_or_f) if pk_or_f.fingerprint.unwrap() == fingerprint));
By the way, I think it would be good to have assert_matches! but if people have doubts it's absolutely fine without it
closed by #821