Skip to content

Commit ca19cd2

Browse files
authored
subscriber: add feature flags to tests (#1532)
## 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>
1 parent 06ecec4 commit ca19cd2

File tree

12 files changed

+15
-3
lines changed

12 files changed

+15
-3
lines changed

tracing-subscriber/src/layer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,6 @@ impl Identity {
13011301

13021302
#[cfg(test)]
13031303
pub(crate) mod tests {
1304-
use std::sync::{Arc, Mutex};
13051304

13061305
use super::*;
13071306

@@ -1419,7 +1418,9 @@ pub(crate) mod tests {
14191418
}
14201419

14211420
#[test]
1421+
#[cfg(feature = "registry")]
14221422
fn context_event_span() {
1423+
use std::sync::{Arc, Mutex};
14231424
let last_event_span = Arc::new(Mutex::new(None));
14241425

14251426
struct RecordingLayer {

tracing-subscriber/src/registry/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ where
474474
}
475475
}
476476

477-
#[cfg(test)]
477+
#[cfg(all(test, feature = "registry"))]
478478
mod tests {
479479
use crate::{
480480
layer::{Context, Layer},

tracing-subscriber/tests/duplicate_spans.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(all(feature = "env-filter", feature = "fmt"))]
12
mod support;
23
use tracing::{self, subscriber::with_default, Span};
34
use tracing_subscriber::{filter::EnvFilter, FmtSubscriber};

tracing-subscriber/tests/field_filter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "env-filter")]
12
mod support;
23
use self::support::*;
34
use tracing::{self, subscriber::with_default, Level};

tracing-subscriber/tests/filter.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(feature = "env-filter")]
2+
13
mod support;
24
use self::support::*;
35
use tracing::{self, subscriber::with_default, Level};

tracing-subscriber/tests/filter_log.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(all(feature = "env-filter", feature = "tracing-log"))]
12
mod support;
23
use self::support::*;
34
use tracing::{self, Level};

tracing-subscriber/tests/fmt_max_level_hint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "fmt")]
12
use tracing_subscriber::filter::LevelFilter;
23

34
#[test]

tracing-subscriber/tests/registry_max_level_hint.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(all(feature = "registry", feature = "fmt"))]
12
use tracing_subscriber::{filter::LevelFilter, prelude::*};
23

34
#[test]

tracing-subscriber/tests/registry_with_subscriber.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "registry")]
12
use tracing_futures::{Instrument, WithSubscriber};
23
use tracing_subscriber::prelude::*;
34

tracing-subscriber/tests/reload.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![cfg(feature = "reload")]
12
use std::sync::atomic::{AtomicUsize, Ordering};
23
use tracing_core::{
34
span::{Attributes, Id, Record},

0 commit comments

Comments
 (0)