should_error
NOTE: This crate is deprecated in favor of
should_match.
Pass a test if an error is returned.
Setup
This crate is primarily intended for use in tests, so add it to your dev-dependencies instead of dependencies:
cargo add --dev should_error
Recommended to work with macro_rules_attr:
cargo add --dev macro_rules_attr should_error
Usage
With macro_rules_attr
Simply apply the should_error macro (the order does not matter):
use apply;
use should_error;
// This test will pass
// This test will also pass
To further specify the pattern that's expected to match, use the expected argument:
# use apply;
# use should_error;
#
You can also match anything else other than an Err:
# use apply;
# use should_error;
#
Directly
Wrap your tests with should_error! (note that the #[test] attribute must be wrapped inside the macro):
use should_error;
// This test will pass
should_error!
// This is not a valid test: the `#[test]` attribute may only be used on a non-associated function
should_error!
To further specify the pattern that's expected to match, use the expected argument:
# use should_error;
#
should_error!
You can also match anything else other than an Err:
# use should_error;
#
#
should_error!