-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add option to cargo check
to check all targets, including test code
#3431
Comments
cargo check
cargo check
to also check test code
See also discussion following #3296 (comment) for motivation |
IIRC Cargo does support
|
cargo check
to also check test codecargo check
to check all targets, including test code
Actually, to be more precise: this should an option that checks all targets (lib, bin, test, examples, doc). The full-build equivalent ( |
Ah yeah that makes sense to me to have some form of as well. We may be able to emulate that with |
Don't know about checking tests specifically, but |
I've added check --all in #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 |
Just a warning for whoever works on this, when the test harness is included (rustc --test), it disables the |
I'd really like to see this implememented, but I can't really see how it should be implemented -- naively conditionally adding 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 #3112 which @BenWiederhake is working on, and after that it'd be relatively easy to add |
Not sure how you think about interface consistency, but |
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
but it does not seem to check my |
I have no idea how to apply |
Having a |
Yes, that's exactly what I wanted. Thanks for the PR pointer! |
Just to give a newbie's perspective I would expect that 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 |
Add unit test checking to `cargo check` This is an extension of PR #4039, fixing #3431, #4003, #4059, #4330. The fixes for #4059 can potentially be separated into a separate PR, though there may be some overlap. The general gist of the changes: - Add `--profile test` flag to `cargo check` that will enable checking of unit tests. - `--tests` will implicitly enable checking of unit tests within the lib (checks the same targets as `cargo test`). This affects the `check`, `test`, and `build` commands. - `--benches` behaves similarly by using the same targets as `cargo bench`. - Fix erroneously linking tests when run with `--test`. There is one thing I did not do because I wanted more feedback on what others think the expected behavior should be. What should the behavior of `--all-targets` be? This patch does not (yet) make any changes to its behavior. My initial thinking is that it should *add* a target of `--lib --bins --profile test`, but that essentially means the lib and bin targets will be checked twice (and thus any errors/warnings outside of `#[cfg(test)]` will appear twice, which may be confusing, and generally take twice as long to run). I can add that, but I think it would require adding a new `All` variant to `CompileFilter` so that the code in `generate_targets` can detect this scenario. I wanted feedback before making a more extensive change like that. The downside of not adding it is that `--all-targets` will ignore unit tests (if you don't specify `--profile test`). Summary of the profiles used with this patch: Command | Lib | Bin foo | Test t1 | Example e1 | Bench b1 | ------- | --- | ------- | ------- | ---------- | -------- | `check` | check | check | - | - | - | `check --profile test` | check_test† | check_test† | - | - | - | `check --lib` | check | - | - | - | - | `check --lib --profile test` | check_test† | - | - | - | - | `check --bin foo` | check | check | - | - | - | `check -–bin foo –profile test` | check_test† | check_test† | - | - | - | `check --bins` | check | check | - | - | - | `check --test t1` | check | check | check_test | - | - | `check --tests` | check, check_test† | check, check_test† | check_test | check†, check_test† | - | `check --all-targets` | check, check_test† | check, check_test† | check_test | check, check_test† | check_test | † = different behavior from today
For people who find this via search, the solution to typecheck tests is |
Basically more or less the check version of
cargo test --no-run
The text was updated successfully, but these errors were encountered: