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

cargo check --all-targets gives bad error details when tests are disabled but benches aren't #14571

Open
Nemo157 opened this issue Sep 20, 2024 · 0 comments
Labels
A-build-execution Area: anything dealing with executing the compiler A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@Nemo157
Copy link
Member

Nemo157 commented Sep 20, 2024

Problem

When running cargo check --all-targets on a crate that can't compile tests (e.g. for an embedded target) where you have explicitly disabled tests via test = false, the build failure does not mention that it's trying to build a bench target, making it appear like --all-targets is just ignoring the test = false. cargo metadata also doesn't mention anything about whether a bench target is enabled or not.

Steps

> cargo new foo && cd foo
    Creating binary (application) `foo` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

> cat >> src/main.rs <<<'#[cfg(test)] compile_error!("no tests");'
> cat >> Cargo.toml <<<$'[[bin]]\nname = "foo"\ntest = false'

> cargo metadata --format-version=1 | jq '.packages[] | select(.name == "foo") | .targets'
[
  {
    "kind": [
      "bin"
    ],
    "crate_types": [
      "bin"
    ],
    "name": "foo",
    "src_path": "/tmp/scratch.rust-unwrapped.2024-09-20T14-32.Jn27OQ/foo/src/main.rs",
    "edition": "2021",
    "doc": true,
    "doctest": false,
    "test": false
  }
]

> cargo check --all-targets
    Checking foo v0.1.0 (/tmp/scratch.rust-unwrapped.2024-09-20T14-32.Jn27OQ/foo)
error: no tests
 --> src/main.rs:4:14
  |
4 | #[cfg(test)] compile_error!("no tests");
  |              ^^^^^^^^^^^^^^^^^^^^^^^^^^

error: could not compile `foo` (bin "foo" test) due to 1 previous error

> cat >> Cargo.toml <<<'bench = false'

> cargo check --all-targets
    Checking foo v0.1.0 (/tmp/scratch.rust-unwrapped.2024-09-20T14-32.Jn27OQ/foo)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.04s

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.82.0-nightly (8f40fc5 2024-08-21)
release: 1.82.0-nightly
commit-hash: 8f40fc5
commit-date: 2024-08-21
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w 11 Sep 2023
os: NixOS 24.5.0 [64-bit]

@Nemo157 Nemo157 added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Sep 20, 2024
@epage epage added A-build-execution Area: anything dealing with executing the compiler A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) labels Sep 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-build-execution Area: anything dealing with executing the compiler A-cargo-targets Area: selection and definition of targets (lib, bins, examples, tests, benches) C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants