From c5ba3d364f82009efb94b77f313e1cae55eca045 Mon Sep 17 00:00:00 2001 From: David Barsky Date: Sat, 4 Sep 2021 13:48:09 -0400 Subject: [PATCH] chore: run tracing-subscriber's tests under `--no-default-features` (#1537) ## Motivation When reviewing https://github.com/tokio-rs/tracing/pull/1523, I suggested that the examples use `fmt::Layer` directly to allow readers to copy-and-paste examples into their own code. However, @hawkw pointed out that rustdoc doesn't receive feature flags from Cargo, which means that running tracing-subscriber's tests under `--no-default-features` would fail. ## Solution It turned out that that we're only running `cargo check --no-default-features` for tracing-subscriber. Running `cargo test --no-default-features` resulted in compilation failures, but it seems like nobody noticed. Building on https://github.com/tokio-rs/tracing/pull/1532, this branch argues that running tracing-subscriber's tests under `cargo test --lib --tests --no-default-features` is _probably_ fine if we're able to skip the doctests (which are _not_ aware of Cargo's feature flags). --- .github/workflows/CI.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 87a5ff52f4..ac50c9855f 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -217,6 +217,9 @@ jobs: features-stable: # Feature flag tests that run on stable Rust. + # TODO(david): once tracing's MSRV goes up to Rust 1.51, we should be able to switch to + # using cargo's V2 feature resolver (https://doc.rust-lang.org/cargo/reference/resolver.html#resolver-versions) + # and avoid cd'ing into each crate's directory. needs: check runs-on: ubuntu-latest steps: @@ -234,6 +237,10 @@ jobs: run: (cd tracing-core && cargo test --no-default-features) - name: "Test tracing no-std support" run: (cd tracing && cargo test --no-default-features) + # this skips running doctests under the `--no-default-features` flag, + # as rustdoc isn't aware of cargo's feature flags. + - name: "Test tracing-subscriber with all features disabled" + run: (cd tracing-subscriber && cargo test --lib --tests --no-default-features) style: # Check style.