Skip to content

Commit

Permalink
subscriber: add feature flags to tests (tokio-rs#1532)
Browse files Browse the repository at this point in the history
## 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 <[email protected]>
  • Loading branch information
hawkw authored and kaffarell committed May 22, 2024
1 parent 182449a commit c426287
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tracing-subscriber/src/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,6 @@ impl Identity {

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

use super::*;

Expand Down Expand Up @@ -1419,7 +1418,9 @@ pub(crate) mod tests {
}

#[test]
#[cfg(feature = "registry")]
fn context_event_span() {
use std::sync::{Arc, Mutex};
let last_event_span = Arc::new(Mutex::new(None));

struct RecordingLayer {
Expand Down

0 comments on commit c426287

Please sign in to comment.