macro_rules! expect { ( $a:expr ) => { ... }; }
Expand description
Expects that the given condition evaluates to true
; otherwise returns early.
§Examples
fn passing_test() -> Result<()> {
expect!(1 + 1 == 2);
Ok(())
}
fn failing_test() -> Result<()> {
expect!(1 + 1 == 69); // returns early
Ok(()) // won't be reached
}
failing_test()
will return early after calling expect!
. The Err
will be wrapped in a
descriptive error message such as:
[my/file.rs:12] “expect!(condition)” Expected true but was false.
[ … wrapped Err details …]