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

target.cfg() section in config doesn't seem to detect test option #11382

Closed
aleksanderkrauze opened this issue Nov 16, 2022 · 1 comment
Closed
Labels
C-bug Category: bug

Comments

@aleksanderkrauze
Copy link

Problem

I have a use case where I want to have two different runners depending on run/test mode. I tried to create following configuration file:

# .cargo/config.toml

[target.'cfg(not(test))']
runner = "./runner.sh"

[target.'cfg(test)']
runner = "./test-runner.sh"

This however doesn't work and cargo always executes runner.sh. Documentation says that I can use a cfg() expression and it shows here that I can use test value to detect if runner was executed by cargo test.

As far I understand this is either a cargo bug, or misleading documentation. If it is the former, I would like to report it. And if it is the latter I would ask for updating documentation and possibly telling me if I can achieve my objective in a different way (other than analyzing executable path name).

Steps

  1. Create new cargo project.
  2. Create two different scripts runner.sh and test-runner.sh in the root of new project.
  3. Create .cargo/toml with contents as above.
  4. Try running cargo run and cargo test and observe how the latter doesn't work.

Possible Solution(s)

No response

Notes

This happens on all stable, beta and nightly release channels.

Version

cargo 1.65.0 (4bc8f24d3 2022-10-20)
release: 1.65.0
commit-hash: 4bc8f24d3e899462e43621aab981f6383a370365
commit-date: 2022-10-20
host: x86_64-unknown-linux-gnu
libgit2: 1.5.0 (sys:0.15.0 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: Arch Linux [64-bit]
@aleksanderkrauze aleksanderkrauze added the C-bug Category: bug label Nov 16, 2022
@ehuss
Copy link
Contributor

ehuss commented Nov 16, 2022

Thanks for the report! I believe this is a duplicate of #8170, so closing in favor of that.

Cargo should probably be issuing a warning for keys that it doesn't support. It has this ability for [target.cfg().dependencies] tables, but not for [target] config tables. It should probably be calling check_cfg_attributes (and that function would need the wording fixed since it is specific to dependencies).

@ehuss ehuss closed this as not planned Won't fix, can't repro, duplicate, stale Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug
Projects
None yet
Development

No branches or pull requests

2 participants