Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: run tracing-subscriber's tests under --no-default-features #1537

Merged
merged 4 commits into from
Sep 4, 2021

Conversation

davidbarsky
Copy link
Member

@davidbarsky davidbarsky commented Sep 3, 2021

Motivation

When reviewing #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 #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).

@davidbarsky davidbarsky requested review from hawkw and a team as code owners September 3, 2021 19:52
Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

In the long run, we may want to do this for other crates that have a large number of feature flags, as well. However, I think tracing-subscriber, tracing-core, and tracing are the main crates that expose a significant amount of flags...

# 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: i believe that if we switched the workspace to use resolver = "2", we wouldn't have to cd into each crate's directory. but, this only works on Rust 1.51+, so we would have to wait until our MSRV is 1.51 (e.g., we can't make that change today).

it might be worth leaving a TODO comment for that, though...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh, another thought. while we're changing this, we may want to change this to use the github actions working-directory key, rather than (cd tracing-subscriber && ...). this is what the cargo hack checks already do:

working-directory: ${{ matrix.subcrate }}

Suggested change
run: (cd tracing-subscriber && cargo test --lib --tests --no-default-features)
run: cargo test --lib --tests --no-default-features
working-directory: tracing-subscriber

We may want to change the other runs in this CI job as well. However, we can also do this in a separate branch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a todo assigned to myself!

Copy link
Member

@hawkw hawkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually...while looking at the CI config, I noticed we have a separate job for tracing-subscriber feature combinations, which does include no-default-features. However, it only runs cargo check:

cargo-check-subscriber:
runs-on: ubuntu-latest
strategy:
matrix:
featureset:
- ""
- fmt
- fmt ansi
- fmt json
- fmt json ansi
- fmt registry
- fmt env-filter
- registry
- env-filter
steps:
- uses: actions/checkout@main
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true
- name: cargo check
working-directory: tracing-subscriber
run: cargo check --no-default-features --features "${{ matrix.featureset }}"

perhaps what we really should do, rather than adding a new run to the tracing features run, is change that job to use cargo test rather than cargo check?

@hawkw hawkw merged commit e7115fe into master Sep 4, 2021
@hawkw hawkw deleted the davidbarsky/test-subscriber-without-default-features branch September 4, 2021 17:48
hawkw pushed a commit that referenced this pull request Sep 4, 2021
…1537)

## Motivation

When reviewing #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
#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).
hawkw pushed a commit that referenced this pull request Sep 4, 2021
…1537)

## Motivation

When reviewing #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
#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).
@davidbarsky
Copy link
Member Author

For posterity: I reverted my changes as suggested in #1537 (review) because that uncovered some feature combinations that, under test, would not compile, and I was not interested in resolving them at the time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants