Expand description
An assertions framework for tracing.
Simpler and faster than the alternatives.
use tracing_subscriber::layer::SubscriberExt;
// Initialize a subscriber with the layer.
let asserter = tracing_assertions::Layer::default();
let registry = tracing_subscriber::Registry::default();
let subscriber = registry.with(asserter.clone());
let guard = tracing::subscriber::set_default(subscriber);
let one = asserter.matches("one");
let two = asserter.matches("two");
let and = &one & &two;
tracing::info!("one");
one.assert();
tracing::info!("two");
two.assert();
and.assert();
drop(guard); // Drop `subscriber` as the current subscriber.
§Failing
When failing e.g.
ⓘ
let one = asserter.matches("one");
let two = asserter.matches("two");
let and = &one & &two;
tracing::info!("one");
and.assert();
Outputs:
thread 'main' panicked at src/lib.rs:14:5: ("one" && "two")
§Operations
Logical operations clone the underlying assertions.
let one = asserter.matches("one");
let two = asserter.matches("two");
let and = &one & &two;
tracing::info!("one");
tracing::info!("two");
one.assert().reset();
and.assert().reset();
two.assert();
(!one).assert();
(!and).assert();
Calling Assertion::reset
on one
does not affect the value of and
and calling Assertion::reset
on and
does not affect the value of two
.
§Similar crates
- test-log: A replacement of the
#[test]
attribute that initializes logging and/or tracing infrastructure before running tests. - tracing_test: Helper functions and macros that allow for easier testing of crates that use
tracing
. - tracing-fluent-assertions: An fluent assertions framework for tracing.