macro_rules! assert_that_code {
($subject:expr) => { ... };
}
Available on crate feature
panic
only.Expand description
Starts an assertion for some piece of code in the PanicOnFail
mode.
It takes a closure and wraps it into a Spec
. On the Spec
any
assertion method that is implemented for closures can be called.
Assertions started with assert_that_code!
will panic on the first failing
assertion.
ยงExamples
use asserting::prelude::*;
fn divide(a: i32, b: i32) -> i32 {
a / b
}
assert_that_code!(|| { divide(7, 0); }).panics();
assert_that_code!(|| { divide(7, 0); })
.panics_with_message("attempt to divide by zero");
assert_that_code!(|| { divide(7, 3); }).does_not_panic();