-
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
Make cargo check also check unit tests #4039
Conversation
This allows users to check their unit test code with cargo check. This functionality is associated with --tests, and is enabled by default when no arguments are passed.
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @brson (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
Thanks for the PR! This isn't 100% what I had in mind though per se, but is certainly a possibility! My thinking was that In theory it's possible to check any target through the standard filters that Cargo has, e.g. Another possibility is to add a |
@alexcrichton Seems like the However, unless I'm missing something, wouldn't switching to the |
Oh we can make sure that Although... I just ran |
I've opened #4059 for that issue |
@alexcrichton I'm not sure I understand what you mean with the What we could do is modify the code in |
Ah yes so #4059 stems from the fact that we don't have a Let's say we've got a Cargo project with a binary, a library, and an integration tests. We should then have:
I think that this PR covers the second case above, but not the other two? Currently today I think Cargo takes care of the first and third (but does too much work on the third), and doesn't include the library's unit tests in the second case. |
@alexcrichton Alright, I think I got what you meant. I'll work on that soon and send a new commit. |
Sorry the complexity is growing here, but let me know if you've got any questions! |
@alexcrichton Let me know how this looks to you, I think it behaves correctly for the 3 examples you mentioned. EDIT: it does not fix the |
This may be an existing issue, but I think that this may not be handled correctly?
I think with your PR it wouldn't compile the |
@alexcrichton Well since |
…lect the check_test profile even when not in Check mode
Ping @alexcrichton ? |
sorry for the delay, I haven't forgotten about this! I may have run out of time to get around to this this week but I can try to get to it next week. @matklad if you've got some spare cycles though you may be able to get to this sooner! |
@burningmind sorry for the delay with this! I think that the I think we'll want to change this to instead generate a list of targets from the manifest and then afterwards match them to a profile to compile in. |
☔ The latest upstream changes (presumably #4259) made this pull request unmergeable. Please resolve the merge conflicts. |
Hi, just letting you all know that this is conflicting with flycheck/flycheck-rust#51 in today's release, because flycheck needs |
We have also switched over to Previously with |
Sorry for taking awhile to get back to this! I think this still suffers the problem though where it's not quite solving all the use cases here. What we really need is to make these lines and the |
@alexcrichton I don't have a lot of time to take care of that right now. Is it okay if this is momentarily put on hold for a 2 or 3 weeks? |
Sure yeah, no worries! |
@tbourvon gentle ping about this. I also just noticed that |
@jonhoo Thanks for the ping. Unfortunately, I don't have the time nor the motivation to take care of this anymore. If someone else wants to look into it, please be my guest! As for your question, I believe that this is because |
Ah, I see. I wonder if @alexcrichton might have some more insight on this that he can share? |
I'm willing to take this on. I've been trying to sort through the different issues (#4003, #3431, #4059, #4330), and I'd like to ensure that there is a way to check the unittests of a particular target. The only way I've seen proposed to do that is to add a I'd like to be absolutely clear about what the different flags should do. Here's a summary of how I think it could work:
† = different behavior from today Does this behavior sound good? Potentially in the future I imagine EDIT: A big caveat with doing both check and check_test on |
Thanks so much for the table there @ehuss! That looks great to me! Would you be interested in starting a PR for that? |
Yea, I'll try to post a PR soon. |
Awesome, thanks! |
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
I believe this mostly landed with #4592, so closing. |
This PR is a POC not to be merged immediately.
These first changes demonstrate basic
cargo check
ing of unit tests by default, and with--tests
(in conjunction with--lib
or--bin
).There are a few points I would like to discuss and improve upon:
--tests
?--tests
is the best solution, as it binds integration tests checking and unit tests checking. Should we use a separate option like--unit-tests
?--test NAME
. Do we want this to be possible? It doesn't seem very useful to me.cargo check
unit benchmarks and doctests. Should we also add this possibility?cargo_rustc
was to add anotherProfile
. However, if we are also going to addcheck_benchmark
andcheck_doctest
, changing some code to abstract that away might be wiser.(This PR is related to #4003 )