Description
The current stable behavior of the test = false
option for targets is:
The test field indicates whether or not the target is tested by default by
cargo test
.
Passing any target selection option that matches the target, including --all-targets
, or even a test filter, overrides test = false
and causes the target to be tested. (This is somewhat inconsistent with the documentation, which implies that this override occurs particularly when the target is specifically named on the command line.)
However, PR #15007 was written with the assumption that test = false
should be understood to mean “this target contains no tests”, and will cause tests and cfg(test)
code inside test = false
targets to issue warnings as if test code is useless inside such targets. This behavior is inconsistent and misleading, because it is possible to run such test code, even unintentionally via --all-targets
, yet a user encountering those warnings would reasonably conclude that test = false
means the crate is never compiled with cfg(test)
.
It would be valuable to have a way to actually mark targets as containing no test code (to reduce wasted build effort and to eliminate compilation errors from crates that can’t be compiled as tests, when --all-targets
is used), but test = false
is not, in fact, such a way, and so should not be treated as if it is. Therefore, I believe #15007 should be reverted, and some thought should be given to adding a true “this target contains no tests” option.
@rustbot label +C-bug +regression-from-stable-to-nightly