mirror of
https://github.com/tokio-rs/tracing.git
synced 2025-10-02 23:34:40 +00:00

... instead of `#[path = ""]` importing it everywhere.
Make sure to use a diff review tool that understands file renaming 😅
(GitHub's diff view does.)
## Motivation
Transparency: I want to use the mocking functionality in the development
of a tracing component out-of-tree.
Additionally, this reduces the use of `#[path] mod` and file
multiple-inclusion, which aren't that great of a practice.
## Solution
The tracing test support module was already well self-contained, due to
being `#[path] mod` used in multiple places. As such, extracting it to
its own crate is rather mechanical, with no surprising blockers.
We additionally move the tracing-futures support module contents into
tracing_mock, for convenience. The one function which relies on
tokio-test is made optional.
It's a reasonable result for this functionality to stay unpublished, and
only used inside the repo, but pulling it out into a directly reusable
chunk instead of abusing the module system to reuse it via
multiple-inclusion is an improvement to code structure and
modularization.
40 lines
963 B
Rust
40 lines
963 B
Rust
#![cfg(feature = "std")]
|
|
|
|
use tracing_mock::*;
|
|
use tracing_subscriber::prelude::*;
|
|
|
|
#[test]
|
|
fn init_ext_works() {
|
|
let (subscriber, finished) = subscriber::mock()
|
|
.event(
|
|
event::mock()
|
|
.at_level(tracing::Level::INFO)
|
|
.with_target("init_works"),
|
|
)
|
|
.done()
|
|
.run_with_handle();
|
|
|
|
let _guard = subscriber.set_default();
|
|
tracing::info!(target: "init_works", "it worked!");
|
|
finished.assert_finished();
|
|
}
|
|
|
|
#[test]
|
|
#[cfg(feature = "fmt")]
|
|
fn builders_are_init_ext() {
|
|
tracing_subscriber::fmt().set_default();
|
|
let _ = tracing_subscriber::fmt()
|
|
.with_target(false)
|
|
.compact()
|
|
.try_init();
|
|
}
|
|
|
|
#[test]
|
|
#[cfg(all(feature = "fmt", feature = "env-filter"))]
|
|
fn layered_is_init_ext() {
|
|
tracing_subscriber::registry()
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.with(tracing_subscriber::EnvFilter::new("foo=info"))
|
|
.set_default();
|
|
}
|