Macro loggy::test_loggy

source ·
macro_rules! test_loggy {
    ($(#[$attr:meta])*, $name:ident, $test:block) => { ... };
    ($name:ident, $test:block) => { ... };
}
Expand description

Create a test case using loggy.

test_loggy!(name, { ... }); creates a test case which captures all log messages (except for LogLevel::Debug messages). It is expected to use either assert_log or clear_log to clear the buffered log before the test ends. It is possible to provide additional attributes in addition to #[test] by specifying them before the name, as in test_loggy!(#[cfg(debug_assertions)], name, { ... });

Since loggy collects messages from all threads, test_loggy! tests must be run with RUST_TEST_THREADS=1, otherwise “bad things will happen”. However, such tests may freely spawn multiple new threads.

If the environment variable LOGGY_MIRROR_TO_STDERR is set to any non empty value, then all log messages will be mirrored to the standard error stream, in addition to being captured. This places the LogLevel::Debug messages in the context of the other log messages, to help in debugging.