substance_panic

Macro substance_panic 

Source
macro_rules! substance_panic {
    () => { ... };
    ($fmt:expr) => { ... };
    ($fmt:expr, $($arg:tt)*) => { ... };
}
Expand description

Provide a panic-like macro that can be used in the framework to detect a test failure and save that status with a message for later screen printing.

std unit tests rely heavily on unwinding. Each unit test is run inside a catch_unwind block. If the unit test panics then the panic is caught and the test is marked as ‘failed’ (or as ‘passed’ if the unit test was marked with #[should_panic]).

The framework attempts to emulate this behavior by by-passing the panic macro to mark the test failed and then early return instead of unwind. Of course, this emulation doesn’t work on panic! originates from outside the crate under test, because panic is not overridden in that scope. This macro provides a way to differentiate between true panic and test failure one.

This emulation has some limitations. For instance, it can only causes one panicking function to return. To remediate on that, any subsequent panic! call will directly return causing some panic to be invisible until they get the chance to be the first one. To provide a bit of insight, the macro also sets a panicking flag to let you know that another panic was thrown after the first one (but without any messages or context). If a panicking panic is triggered again, the framework will consider either the tests are ill written or the failure is too fatal. In this case real panic will cause an abort!