-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 tidy check for lang gate tests #38914
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
.count(); | ||
|
||
// FIXME get this number down to zero. | ||
let gate_untested_expected = 94; |
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.
Maybe we can open up a follow-up issue with a list of each of these tests and try to distribute the work.
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.
Sure, good idea! Most of the features already have gate tests (see issue #22820 for an outdated list). If the general direction of this issue is agreed upon, I volunteer to add // gate-test-
comments to the already existing tests (that I can find), and for the small remaining number we can open a tracking issue. Probably a good thing to ask contributions for from first time contributors (like the error message refactoring).
@bors r+ |
📌 Commit 9d04411 has been approved by |
@bors r- |
Actually, one thing -- I think we should edit COMPILER_TESTS.md to document what is expected. It'd be nice if the error message also directed the user at some instructions on how to fix (or directly gave those instructions). |
if gate_untested < gate_untested_expected { | ||
println!("Did you forget to reduce the expected number?"); | ||
} else { | ||
println!("Did you forget to add a gate test for your new feature?"); |
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.
Also, I think we should make the "expected" list be a hash set or something. This way we can actually print out the names of the features here, along with some directions like "make a test with a // gate-test-foo
comment"
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.
This is not the aspired end state. I'm sure most features already have gate tests, there should only be very few without one. And once we have all features gate tested, so gate_untested_expected
is zero, we can change this code to print the ungated features in the error message.
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 think the idea is very good but I feel like the experience of getting a tidy error here will be kind of annoying. With a bit more effort we can help direct people as to what they have to do.
See my reply above. The tidy error will/can be improved once the list is complete. |
Hmm. That seems potentially OK, but I am concerned we will stall in this interim state for some time. =) |
Okay, updated, and docs added. I've now added a whitelist of currently 20 features for which I couldn't find gate tests. They either don't have a test, or are already removed, but feature_gate.rs didn't get updated, Thanks to the whitelist, we can now fail with messages like:
|
14fab21
to
66718ed
Compare
Oh sorry, forgot to push. Now it should be okay. r? @nikomatsakis |
Updated PR description. |
let gate_untested = features.iter() | ||
.filter(|&(_, f)| f.level == Status::Unstable) | ||
.filter(|&(_, f)| !f.has_gate_test) | ||
.filter(|&(n, _)| !whitelist.contains(&n.as_str())) |
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'm happy to land it as is, but I have a mild concern that people will add tests for something in the whitelist, but forget to remove it from the whitelist. Either we have to be vigilant, or we could tweak this code such that if it is in the whitelist, we error out if it is found to be tested.
@bors r+ |
📌 Commit 66718ed has been approved by |
I'll enqueue it for now, can always submit a follow-up PR if you think it's worth tweaking it. |
Its non trivial to test lang feature gates, and people forget to add such tests. So we extend the features lint of the tidy tool to ensure that all new lang features contain a new compile-fail test. Of course, one could drop this requirement and just grep all tests in run-pass for #![feature(abc)] and then run this test again, removing the mention, requiring that it fails. But this only tests for the existence of a compilation failure. Manual tests ensure that also the correct lines spawn the error, and also test the actual error message. For library features, it makes no sense to require such a test, as here code is used that is generic for all library features.
Now, no feature outside of the whitelist is without a test marked as its gate test.
Rebase on top of PR 38814 made required this.
66718ed
to
c6f99b4
Compare
As #38814 got merged, I had to rebase and mark the test it added. re-r? @nikomatsakis |
@bors r+ |
📌 Commit c6f99b4 has been approved by |
Make tidy check for lang gate tests Add gate tests to the checks that tidy performs. Excerpt from the commit message of the main commit: Require compile-fail tests for new lang features Its non trivial to test lang feature gates, and people forget to add such tests. So we extend the features lint of the tidy tool to ensure that all new lang features contain a new compile-fail test. Of course, one could drop this requirement and just grep all tests in run-pass for #![feature(abc)] and then run this test again, removing the mention, requiring that it fails. But this only tests for the existence of a compilation failure. Manual tests ensure that also the correct lines spawn the error, and also test the actual error message. For library features, it makes no sense to require such a test, as here code is used that is generic for all library features. The tidy lint extension now checks the compile-fail test suite for occurences of "gate-test-X" where X is a feature. Alternatively, it also accepts file names with the form "feature-gate-X.rs". If a lang feature is found that has no such check, we emit a tidy error. I've applied the markings to all tests I could find in the test suite. I left a small (20 elements) whitelist of features that right now have no gate test, or where I couldn't find one. Once this PR gets merged, I'd like to close issue #22820 and open a new one on suggestion of @nikomatsakis to track the removal of all elements from that whitelist (already have a draft). Writing such a small test can be a good opportunity for a first contribution, so I won't touch it (let others have the fun xD). cc @brson , @pnkfelix (they both discussed about this in the issue linked above).
☀️ Test successful - status-appveyor, status-travis |
Add gate tests to the checks that tidy performs. Excerpt from the commit message of the main commit:
The tidy lint extension now checks the compile-fail test suite for occurences of "gate-test-X" where X is a feature. Alternatively, it also accepts file names with the form "feature-gate-X.rs". If a lang feature is found that has no such check, we emit a tidy error.
I've applied the markings to all tests I could find in the test suite. I left a small (20 elements) whitelist of features that right now have no gate test, or where I couldn't find one. Once this PR gets merged, I'd like to close issue #22820 and open a new one on suggestion of @nikomatsakis to track the removal of all elements from that whitelist (already have a draft). Writing such a small test can be a good opportunity for a first contribution, so I won't touch it (let others have the fun xD).
cc @brson , @pnkfelix (they both discussed about this in the issue linked above).