Macro credibility::aver [−][src]
macro_rules! aver { ($block:ident, $($arg:tt)+) => { ... }; }
Ensure that a boolean expression is true
and cause a test block
to fail if it is false.
This macro behaves the same way as assert!
does, except it will
not immediately halt execution of a code block. This is most
useful in tests where you want to see the result of multiple
inputs in a given configuration (e.g. in table-driven tests.)
Examples
test_block!(tb, "An example test block", { aver!(tb, true, "A working assertion"); Ok(()) });
And an example of failing test cases; note that all the cases will be checked and contribute to the panic at the end:
test_block!(tb, "An example test block", { let cases = vec![ (2, 3, 5), // will be checked (1, 1, 2), // will also be checked! (1, 1, 3), // and this, too (the single successful test case) ]; for (in1, in2, output) in cases { aver!(tb, in1+in2 != output); } Ok(()) });