-
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 requirements to cargo_test. #9892
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
I'm opening this up as a draft to get some feedback to see if this is a worthwhile direction to go. This is something I've wanted for a while, as it would help understand which tests are disabled. One issue is that there is some code duplication in cargo-test-macro that is hard to share (would need to create yet another crate to hold that shared code and keep build times down). Ideally there would be a better way to have runtime test skipping (as described in https://internals.rust-lang.org/t/pre-rfc-skippable-tests/14611). |
I think this is a fine direction to go in. If possible I'd ideally like to leverage code generation to share code where the checks are in the generated code rather than the macro itself (so the macro doesn't have to do things like spawn rustc and such). This is generating a literal |
☔ The latest upstream changes (presumably #9889) made this pull request unmergeable. Please resolve the merge conflicts. |
As @ehuss said, the generation of Yet, is it a problem that the tests and |
4d26ed8
to
aebea40
Compare
This appears to no longer be necessary since we have migrated to GitHub Actions.
5c5b46e
to
9d43ffc
Compare
@epage or @weihanglo, I'd like to move forward with this. Would either of you be willing to review this? I updated it for the latest master. There are also some docs in the contrib guide which explain what has changed. |
I would take a look then. Thank you for updating this! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks nice!
I notice that there are two widely used requirement rules are not covered: symlink support and cross compilation. Do we want to integrate them into this proc macro? It could be done by a separate PR tho.
crates/cargo-test-macro/src/lib.rs
Outdated
let mut ignore = false; | ||
let mut requires_reason = false; | ||
let mut found_reason = false; | ||
let is_not_nightly = || !version().1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder why is_not_nightly
is closure. Is it possible to call version()
only once and reuse the return value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea. I think I was thinking of avoiding the overhead of the atomic load for each test, but I suspect it is tiny.
From what I can tell, it is no longer necessary on GitHub Actions. This removes it to help simplify things.
35a6dee
to
8e35e2f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to go. Thanks!
@bors r+ |
☀️ Test successful - checks-actions |
Fix formats_source test requiring rustfmt. The requirements added in #9892 that `rustfmt` must be present doesn't work in the `rust-lang/rust` environment. There are two issues: * Cargo is run without using rustup. If you also have rustup installed, the test will fail because the `rustfmt` binary found in `PATH` will fail to choose a toolchain because HOME points to the sandbox home which does not have a rustup configuration. * rust-lang/rust CI uninstalls rustup, and does not have rustfmt in PATH at all. It is not practical to make rustfmt available there. The solution here is to just revert the behavior back to where it was where it checks if it can run `rustfmt` in the sandbox. This should work for anyone who has a normal rustup installation (including Cargo's CI). If running the testsuite without rustup, then the test will be skipped. This also includes a small enhancement to provide better error information when rustfmt fails.
Fix formats_source test requiring rustfmt. The requirements added in #9892 that `rustfmt` must be present doesn't work in the `rust-lang/rust` environment. There are two issues: * Cargo is run without using rustup. If you also have rustup installed, the test will fail because the `rustfmt` binary found in `PATH` will fail to choose a toolchain because HOME points to the sandbox home which does not have a rustup configuration. * rust-lang/rust CI uninstalls rustup, and does not have rustfmt in PATH at all. It is not practical to make rustfmt available there. The solution here is to just revert the behavior back to where it was where it checks if it can run `rustfmt` in the sandbox. This should work for anyone who has a normal rustup installation (including Cargo's CI). If running the testsuite without rustup, then the test will be skipped. This also includes a small enhancement to provide better error information when rustfmt fails.
Update cargo, rls 14 commits in 85b500ccad8cd0b63995fd94a03ddd4b83f7905b..4fd148c47e733770c537efac5220744945d572ef 2022-07-24 21:10:46 +0000 to 2022-08-03 15:03:52 +0000 - Revert "Drop check for mingw32-make." (rust-lang/cargo#10934) - Add reasons to all ignored tests. (rust-lang/cargo#10929) - Grammar fixup unused patch message (rust-lang/cargo#10933) - Always allow hg to be missing on CI. (rust-lang/cargo#10931) - Fix formats_source test requiring rustfmt. (rust-lang/cargo#10918) - Disable scrape_examples_complex_reverse_dependencies (rust-lang/cargo#10921) - Contrib: Add docs on the rustbot ready command (rust-lang/cargo#10916) - Support for negative --jobs parameter, counting backwards from max CPUs (rust-lang/cargo#10844) - Add requirements to cargo_test. (rust-lang/cargo#9892) - Contrib: Document submodule update process (rust-lang/cargo#10913) - Contrib: Add docs on how to use crater (rust-lang/cargo#10912) - Contrib: Document new-release process (rust-lang/cargo#10914) - Override to resolver=1 in published package (rust-lang/cargo#10911) - fix(add): Update the lock file (rust-lang/cargo#10902) 1 commits in fcf1f94c9ab2acc18cfd4368a4aeb38e77da9649..4d8b0a19986a4daab37287a5b5fe2da0775d1873 2022-07-14 17:19:11 +0200 to 2022-08-02 22:34:34 -0400 - Update cargo (rust-lang/rls#1782)
Update cargo, rls 14 commits in 85b500ccad8cd0b63995fd94a03ddd4b83f7905b..4fd148c47e733770c537efac5220744945d572ef 2022-07-24 21:10:46 +0000 to 2022-08-03 15:03:52 +0000 - Revert "Drop check for mingw32-make." (rust-lang/cargo#10934) - Add reasons to all ignored tests. (rust-lang/cargo#10929) - Grammar fixup unused patch message (rust-lang/cargo#10933) - Always allow hg to be missing on CI. (rust-lang/cargo#10931) - Fix formats_source test requiring rustfmt. (rust-lang/cargo#10918) - Disable scrape_examples_complex_reverse_dependencies (rust-lang/cargo#10921) - Contrib: Add docs on the rustbot ready command (rust-lang/cargo#10916) - Support for negative --jobs parameter, counting backwards from max CPUs (rust-lang/cargo#10844) - Add requirements to cargo_test. (rust-lang/cargo#9892) - Contrib: Document submodule update process (rust-lang/cargo#10913) - Contrib: Add docs on how to use crater (rust-lang/cargo#10912) - Contrib: Document new-release process (rust-lang/cargo#10914) - Override to resolver=1 in published package (rust-lang/cargo#10911) - fix(add): Update the lock file (rust-lang/cargo#10902) 1 commits in fcf1f94c9ab2acc18cfd4368a4aeb38e77da9649..4d8b0a19986a4daab37287a5b5fe2da0775d1873 2022-07-14 17:19:11 +0200 to 2022-08-02 22:34:34 -0400 - Update cargo (rust-lang/rls#1782)
Update cargo, rls 14 commits in 85b500ccad8cd0b63995fd94a03ddd4b83f7905b..4fd148c47e733770c537efac5220744945d572ef 2022-07-24 21:10:46 +0000 to 2022-08-03 15:03:52 +0000 - Revert "Drop check for mingw32-make." (rust-lang/cargo#10934) - Add reasons to all ignored tests. (rust-lang/cargo#10929) - Grammar fixup unused patch message (rust-lang/cargo#10933) - Always allow hg to be missing on CI. (rust-lang/cargo#10931) - Fix formats_source test requiring rustfmt. (rust-lang/cargo#10918) - Disable scrape_examples_complex_reverse_dependencies (rust-lang/cargo#10921) - Contrib: Add docs on the rustbot ready command (rust-lang/cargo#10916) - Support for negative --jobs parameter, counting backwards from max CPUs (rust-lang/cargo#10844) - Add requirements to cargo_test. (rust-lang/cargo#9892) - Contrib: Document submodule update process (rust-lang/cargo#10913) - Contrib: Add docs on how to use crater (rust-lang/cargo#10912) - Contrib: Document new-release process (rust-lang/cargo#10914) - Override to resolver=1 in published package (rust-lang/cargo#10911) - fix(add): Update the lock file (rust-lang/cargo#10902) 1 commits in fcf1f94c9ab2acc18cfd4368a4aeb38e77da9649..4d8b0a19986a4daab37287a5b5fe2da0775d1873 2022-07-14 17:19:11 +0200 to 2022-08-02 22:34:34 -0400 - Update cargo (rust-lang/rls#1782)
This extends the
#[cargo_test]
attribute to support some additional requirements to control whether or not a test can run. The motivation for this is:The form is a comma separated list of requirements, and if they don't pass the test is ignored. The requirements can be:
nightly
— The test only runs on nightly.>=1.55
— The test only runs on rustc with the given version or newer.requires_git
— Requires the given command to be installed. Can be things likerequires_rustfmt
orrequires_hg
, etc.This also enforces that the author must write a reason why it is ignored (for some of the requirements) so that when I look for tests to update, I know why it is disabled.
This also removes the
CARGO_TEST_DISABLE_GIT_CLI
option, which appears to no longer be necessary since we have migrated to GitHub Actions.