[][src]Macro assert2::check

macro_rules! check {
    ($($tokens:tt)*) => { ... };

Check if an expression evaluates to true or matches a pattern.

Use a let expression to test an expression against a pattern: check!(let pattern = expr). For other tests, just give a boolean expression to the macro: check!(1 + 2 == 2).

If the expression evaluates to false or if the pattern doesn't match, an assertion failure is printed but the macro does not panic immediately. The check macro will cause the running test to fail eventually.

Use assert! if you want the test to panic instantly.

Currently, this macro uses a scope guard to delay the panic. However, this may change in the future if there is a way to signal a test failure without panicking. Do not rely on check!() to panic.

Custom messages

You can pass additional arguments to the macro. These will be used to print a custom message in addition to the normal message.

check!(3 * 4 == 12, "Oh no, math is broken! 1 + 1 == {}", 1 + 1);