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 test ignores test flags when testing specific keyword #10268

Closed
dist1ll opened this issue Jan 6, 2022 · 4 comments · Fixed by #10305
Closed

Cargo test ignores test flags when testing specific keyword #10268

dist1ll opened this issue Jan 6, 2022 · 4 comments · Fixed by #10305
Labels

Comments

@dist1ll
Copy link

dist1ll commented Jan 6, 2022

Problem

When running cargo test xyz, cargo ignores all test flags in the cargo.toml file.

Steps

  1. create project cargo init xyz
  2. add #[test] fn random{} to your main.rs
  3. add the following to your Cargo.toml
[[bin]]
name = "main"
path = "src/main.rs"
test = false
  1. type cargo test and then type cargo test xyz

Result:
Capture

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.59.0-nightly (358e79fe5 2022-01-04)
@dist1ll dist1ll added the C-bug Category: bug label Jan 6, 2022
@weihanglo
Copy link
Member

I guess it's #6683 that causes the compilation not respecting the default target selection rules. In contrast, it compiles all bin and test targets in order to filter unit tests. Is this a desired change?

Personally I feel like when running cargo test [testname] without specifying targets, cargo should always compile the default targets. The alternative solution is reusing the logic of CompileFilter to determine which target is required to run in ops::run_tests, but it don't feel good in this way.

@dist1ll
Copy link
Author

dist1ll commented Jan 7, 2022

What do you mean by "cargo should always compile the default targets"? (I'm not so familiar with the lingo)

I don't think cargo test [testname] should compile more than cargo test. I put test = false because I don't want to test that target. What other reason could exist to add test = false in your .toml

I rarely use cargo test when developing, only once before a commit. cargo test [testname] on the other hand is done in a much tighter loop.

@weihanglo
Copy link
Member

Each build command in cargo has its own target selection rule. For example, cargo test by default compiles and runs unit tests under bins, tests, and lib with respecting your target settings (test = ture|false in Cargo.toml).
Your concern is valid, when you execute cargo test [testname] it behaves like compiling and running unit tests under all bins, tests, and lib targets no matter what is set in Cargo.toml. That's what #6683 did. I'm unsure if it is expected.

@ehuss
Copy link
Contributor

ehuss commented Jan 17, 2022

I think in this particular situation, it probably shouldn't be building the test=false entries.

It might be a little tricky code-wise. Cargo allows you to override the test=false by specifying the test specifically (like cargo test --test foo. However, I think this shouldn't be too hard to fix.

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

Successfully merging a pull request may close this issue.

3 participants