Basically more or less the check version of cargo test --no-run
See also discussion following https://github.com/rust-lang/cargo/pull/3296#issuecomment-267402673 for motivation
IIRC Cargo does support cargo test --test foo to check a particular test, but I think we need two more additions here:
cargo rustc, --profile test. This'd allow cargo check --lib --profile test to test compiling the library with testscargo check --tests to just check all tests, etc. Also things like cargo check --bins, cargo check --examples, etc.Support cargo check --tests to just check all tests, etc. Also things like cargo check --bins, cargo check --examples, etc.
Actually, to be more precise: this should an option that checks all targets (lib, bin, test, examples, doc). The full-build equivalent (cargo test --no-run) does that already, it build all targets - not just test targets but bin, doc, examples, too. (dunno if that behaviour was the original intention, but it's good that it does that)
Ah yeah that makes sense to me to have some form of as well. We may be able to emulate that with cargo check --all or something like that.
Don't know about checking tests specifically, but cargo build has the --all option to build all targets in a workspace. It feels unsymmetrical that cargo check doesn't have this option.
I've added check --all in https://github.com/rust-lang/cargo/pull/3731, but it doesn't handle tests (e.g. the default current behavior), so I'm going to clleave this open.
@alexcrichton any idea when --all will get support for running test (or when we'll see --test)? It'd be really nice to have in the vim syntax checker (see https://github.com/neomake/neomake/issues/843#issuecomment-287432264)
Just a warning for whoever works on this, when the test harness is included (rustc --test), it disables the missing_docs lint. Also, it disables the "main function not found" error for binaries. I'm not sure how it will be implemented in the context of cargo check, but something to watch out for.
I'd really like to see this implememented, but I can't really see how it should be implemented -- naively conditionally adding --test to rustc args in src/bin/check.rs was not the right solution.
Does someone already have a plan of how this should be implemented? If you do, and are too busy to work on this yourself, please share your thoughts so perhaps I or someone else could come up with at least the initial PR.
@koivunej this is likely related to https://github.com/rust-lang/cargo/issues/3112 which @BenWiederhake is working on, and after that it'd be relatively easy to add --all to just apply to all targets.
Not sure how you think about interface consistency, but --all very often stands for "all packages", so this might be confusing.
That's true yeah, we may want to hold off on implementing this just yet, just mentioning that it should be relatively easy to support with that added in #3112
Just tried against latest nightly cargo 0.19.0-nightly (fa7584c14 2017-04-26) and it'd seem that cargo check --tests is supported, from help:
--tests Check all tests
but it does not seem to check my #[test] function, as in cargo check && cargo check --tests && cargo test fails at last stage (cargo test) due to type checking error. As this issue is still open this is probably expected, as in --tests is for code in tests/ directory, not inline #[test] code?
--tests only means that the files in the tests/ folder are included. so yes, you are correct.
I have no idea how to apply check on the in-line #[test]s, but I guess it involves some feature-magic.
Having a --tests that actually checks all tests code would be a hugely welcome addition. In the current scheme of things, editors are generally forced to use cargo test --no-run if they want to provide error highlighting for all errors, which is quite unfortunate. @alexcrichton how much work is this likely to be?
@jonhoo I think https://github.com/rust-lang/cargo/pull/4039 is a PR targeted at solving @koivunej's concern, although is that the feature you're thinking of?
Yes, that's exactly what I wanted. Thanks for the PR pointer!
Just to give a newbie's perspective I would expect that cargo check --all would check everything. Period. If --all is intended to mean "all packages", then I'd suggest a --packages or --all-packages option instead which mirrors --all-features or --benches.
Consistency and intuitive APIs are important, especially for people just learning.
I don't see that it was explicitly stated here, but I would also expect cargo check --tests or cargo check --docs to check documentation tests (and by extension cargo check --all should do the same).
Most helpful comment
Just to give a newbie's perspective I would expect that
cargo check --allwould check everything. Period. If--allis intended to mean "all packages", then I'd suggest a--packagesor--all-packagesoption instead which mirrors--all-featuresor--benches.Consistency and intuitive APIs are important, especially for people just learning.