macro_rules! verify_that {
($actual:expr, $($expected:tt)+) => { ... };
}Expand description
Checks whether the Matcher given by the second argument matches the first
argument.
Evaluates to Result::Ok(()) if the matcher matches and
Result::Err(TestAssertionFailure) if it does not. The caller must then
decide how to handle the Err variant. It has a few options:
- Abort the current function with the
?operator. This requires that the function return a suitableResult. - Log the test failure and continue by calling the method
and_log_failure.
Of course, one can also use all other standard methods on Result.
Invoking this macro by itself does not cause a test failure to be recorded
or output. The resulting Result must be handled as described above to
cause the test to be recorded as a failure.
Example:
verify_that!(42, eq(42))?; // This will pass.
verify_that!(42, eq(123)).and_log_failure();
// This will log a test failure and allow execution to continue.
let _ = verify_that!(42, eq(123)); // This will do nothing.
verify_that!(42, eq(123))?; // This will fail, returning immediately.
verify_that!(42, eq(0))?; // This will not run.This macro has special support for matching against containers. Namely:
verify_that!(actual, [m1, m2, ...])is equivalent toverify_that!(actual, contains_exactly![m1, m2, ...].in_order())verify_that!(actual, {m1, m2, ...})is equivalent toverify_that!(actual, contains_exactly![m1, m2, ...])