Function loggy::assert_panics
source · Expand description
Ensure that executing some code will panic with a specific error message (ignoring the log).
TODO: This crate isn’t really the best place for this.
Unlike #[should_panic(expected = "...")]
, this:
- Allows isolating a specific part of the test instead of decorating a whole test;
- Does not pollute stderr with the panic indication and back trace;
- Allows the caller to dynamically generate the expected panic message;
- Insists on the exact panic string rather than just a sub-string if it.
Notes
The rust log
facade mandates using a single global logger. Therefore, only one test can capture the log at any
given time, using a global Mutex
. Therefore, nesting this inside itself, assert_logs
or
assert_logs_panics
will deadlock.
Panics
If the code does not panic, or panics with a different message than expected.