Description
Problem
cargo test
has flags --libs
, --bins
, --tests
, --doc
, which I thought (based on their documentation) would control whether the lib crate unit tests / bin crate unit tests / integration tests / doc tests, respectively, are being run. But that does not seem to be what happens, so either the documentation is wrong or it is very confusing.
Steps
- Run
cargo test --tests
. - Notice how it runs not just the integration tests, but also the unit tests!
- However,
cargo test --bins
runs only the binary crate unit tests.
This seems clearly inconsistent. I would expect cargo test --tests
to be the same as cargo test --test a --test b
(manually listing all tests), which is how cargo test --bins
seems to behave.
Possible Solution(s)
No response
Notes
Generally the cargo test
documentation for all these many flags that control which tests are being run, is unclear on whether the flag adds tests to the default test set, or remove the default test set to only run a small select set of tests. (This also affects other commands like cargo check
.) For instance, cargo test --benches
tests more than the default test set, but cargo test --bins
tests less than the default test set, but the documentation for these two flags reads exactly the same. Some flags use the word 'only', which is maybe meant to indicate "reduce default test set", but --bins
does not use that word and anyway this is not at all clear.
The behavior I would have expected is along the lines of "if any of these flags is present, then only what is specified by the flags is being run, no default test set", but that does not match implemented behavior. This then makes me wonder how I would even say "run only integration tests" (cargo test --tests
doesn't do that), or "check only the benchmarks" (cargo check --benches
doesn't do that).
Version
cargo 1.64.0-nightly (85b500cca 2022-07-24)
release: 1.64.0-nightly
commit-hash: 85b500ccad8cd0b63995fd94a03ddd4b83f7905b
commit-date: 2022-07-24
host: x86_64-unknown-linux-gnu
libgit2: 1.4.2 (sys:0.14.2 vendored)
libcurl: 7.83.1-DEV (sys:0.4.55+curl-7.83.1 vendored ssl:OpenSSL/1.1.1q)
os: Debian testing (bookworm) [64-bit]
Metadata
Metadata
Assignees
Labels
Type
Projects
Status