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

## Motivation Currently we can't run ```bash cargo test -p tracing-subscriber --no-default-features ``` successfully, because there are a bunch of tests for feature flagged APIs that are always enabled. ## Solution This commit adds feature flags to the modules and/or individual test cases that test feature-flagged APIs. There are still a few doctests that use feature-flagged APIs, and will fail with `--no-default-features`. These are primarily the examples for various `Layer::context` methods that rely on `LookupSpan`, and use the `Registry` type, as it's the only subscriber that *implements* `LookupSpan`. We could consider changing these examples, either by removing the actual use of the layers in them, or by changing them to use a mocked-out version of the registry. However, I think it's nicer to show how the API would be used in real life. Perhaps we should just run ```bash cargo test -p tracing-subscriber --no-default-features--tests --lib ``` to ignore doctests when testing without default features. Signed-off-by: Eliza Weisman <eliza@buoyant.io>
39 lines
951 B
Rust
39 lines
951 B
Rust
mod support;
|
|
use self::support::*;
|
|
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();
|
|
}
|