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

subscriber: add feature flags to tests #1532

Merged
merged 1 commit into from
Sep 2, 2021
Merged

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Sep 2, 2021

Motivation

Currently we can't run

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

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

Currently we can't run

```shell
$ cargo test -p tracing-subscriber --no-default-features
```
successfully, because there are a bunch of tests for feature flagged
APIs that are always enabled. This commit adds feature flags to the
modules and/or individual test cases that test feature-flagged APIs.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
@hawkw hawkw requested a review from a team as a code owner September 2, 2021 17:27
@hawkw hawkw merged commit ca19cd2 into v0.1.x Sep 2, 2021
@hawkw hawkw deleted the eliza/feature-flag-tests branch September 2, 2021 17:43
davidbarsky added a commit that referenced this pull request Sep 2, 2021
## 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>
davidbarsky added a commit that referenced this pull request Sep 2, 2021
* 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>
Co-authored-by: David Barsky <me@davidbarsky.com>
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).
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).
kaffarell pushed a commit to kaffarell/tracing that referenced this pull request May 22, 2024
## 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>
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