macro_rules! assert_err_eq {
($cond:expr, $expected:expr,) => { ... };
($cond:expr, $expected:expr) => { ... };
($cond:expr, $expected:expr, $($arg:tt)+) => { ... };
}Expand description
Asserts that expression returns Err(E) variant
and its value of E type equals to the right expression.
§Uses
Assertions are always checked in both debug and release builds, and cannot be disabled.
See debug_assert_err_eq! for assertions that are not enabled in release builds by default.
§Custom messages
This macro has a second form, where a custom panic message can be provided
with or without arguments for formatting. See std::fmt for syntax for this form.
§Examples
use testutils::assert_err_eq;
let res: Result<(), i32> = Err(1);
assert_err_eq!(res, 1);
// With custom messages
assert_err_eq!(res, 1, "Everything is good with {:?}", res);Value of E type from Err(E) will be returned from the macro call:
use testutils::assert_err_eq;
let res: Result<(), i32> = Err(1);
let value = assert_err_eq!(res, 1);
assert_eq!(value, 1);Ok(..) variant will cause panic:
ⓘ
use testutils::assert_err_eq;
let res: Result<(), i32> = Ok(());
assert_err_eq!(res, 1); // Will panic
//