macro_rules! assert_err {
($val:expr, $($msg:tt)+) => { ... };
($val:expr) => { ... };
}Available on crate feature
assert-no-tracing only.Expand description
Asserts that the provided expression, that returns a Result, is Err.
§Motivation
The standard pattern for asserting a value is Err using the assert! macro is:
assert!(x.is_err());The issue with this pattern is when the assertion fails it only prints false
and not the value contained in the Ok(_) variant which makes debugging difficult.
§Examples
§Basic Use
ⓘ
use mz_ore::assert_err;
let error: Result<usize, usize> = Ok(42);
assert_err!(error);§With extra message
ⓘ
use mz_ore::assert_err;
let other_val = 100;
let error: Result<usize, usize> = Ok(42);
assert_err!(error, "ohh noo! x {other_val}");