Skip to content
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

audit: ensure every gated feature has a compile-fail test #22820

Closed
27 of 40 tasks
pnkfelix opened this issue Feb 25, 2015 · 19 comments
Closed
27 of 40 tasks

audit: ensure every gated feature has a compile-fail test #22820

pnkfelix opened this issue Feb 25, 2015 · 19 comments
Assignees
Labels
E-needs-test Call for participation: Writing correctness tests.

Comments

@pnkfelix
Copy link
Member

pnkfelix commented Feb 25, 2015

I was sloppy when I implemented #22173 and did not include a test. So, surprise, a follow-on commit a few days later broke it.

As self-punishment for neglecting to include a regression test, I am assigning myself the task of reviewing our test suite to make sure that every feature-gate has a test.


Here is a transcribed list of feature gates, based on feature_gate.rs, that I have annotated according to whether the feature is Accepted/Removed (and thus needs no tests), Active/Deprecated but has tests already (marked with an x, or Active/Deprecated but has no tests that I saw via a cursory grep/skim.

@pnkfelix pnkfelix self-assigned this Feb 25, 2015
@pnkfelix
Copy link
Member Author

(but hey, if other people want to add such missing tests in the meantime, while I am asleep, I will not mind. :)

@steveklabnik steveklabnik added the E-needs-test Call for participation: Writing correctness tests. label Feb 26, 2015
@pnkfelix pnkfelix added the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Mar 9, 2015
pnkfelix added a commit to pnkfelix/rust that referenced this issue Mar 9, 2015
…atures.

Namely:

 * `quote`
 * `link_args`
 * `link_llvm_intrinsics`
 * `thread_local`
 * `unsafe_destructor`

Also updates test for `plugin_registrar` to make it clear that
it is only testing the `plugin_registrar` feature gate.

Cc rust-lang#22820.
@pnkfelix
Copy link
Member Author

pnkfelix commented Mar 9, 2015

In case its not clear: If you want to help, just find a case above that does not have a check-mark and also does not have a pull request number attached beneath it. (And I guess write your name so that other people do not waste time adding a test for the same feature gate).

Manishearth added a commit to Manishearth/rust that referenced this issue Mar 10, 2015
…-gates, r=alexcrichton

 Add tests checking that a number of feature gates are gating their features

Namely:

 * `quote`
 * `link_args`
 * `link_llvm_intrinsics`
 * `thread_local`
 * `unsafe_destructor`

Also updates test for `plugin_registrar` to make it clear that
it is only testing the `plugin_registrar` feature gate.

Cc rust-lang#22820.  (Latter is not fixed, since there are still a bunch more feature-gates that need tests. But I wanted to stop here and move on to something else.)
fhahn added a commit to fhahn/rust that referenced this issue Mar 21, 2015
…eatures.

Namely:

 * `box_syntax`
 * `box_patterns`
 * `simd_ffi`
 * `macro_reexport`

 cc rust-lang#22820
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 21, 2015
…s1, r=alexcrichton

 ...ures.

Namely:

 * `box_syntax`
 * `box_patterns`
 * `simd_ffi`
 * `macro_reexport`

cc rust-lang#22820
Manishearth added a commit to Manishearth/rust that referenced this issue Mar 22, 2015
…s1, r=alexcrichton

 ...ures.

Namely:

 * `box_syntax`
 * `box_patterns`
 * `simd_ffi`
 * `macro_reexport`

cc rust-lang#22820
@lgrz
Copy link
Contributor

lgrz commented Apr 16, 2015

The test for custom_attribute is located in custom_attribute.rs

@pnkfelix
Copy link
Member Author

I am not surprised that I "overlooked" that ... the expected error message prefix does not say anything about a feature gate. Let me just confirm that the whole message does ...

Update: Okay, the help output for that test (custom_attribute.rs) does mention the feature gate:

help: add #![feature(custom_attribute)] to the crate attributes to enable

So I have now checked off that box, though I wonder if I should add this help message to the expected test output there.

@lgrz
Copy link
Contributor

lgrz commented Apr 17, 2015

I was wondering the same thing about the help message. It is not very clear what that custom_attribute test is doing, the only hint was the filename.

From reading #23974 some help messages were removed, would there be any concern for adding help messages to the expected test output in this case?

It could be worth adding a comment in there similar to the other gated tests:

// Test that `#[...]` attribute is gated by `...` feature gate.

In addition, would it be worth going as far as to rename custom_attribute.rs to gated-custom_attribute.rs (and doing the same for any other gated tests that do not have a gated- prefix in their filename)?

@lgrz
Copy link
Contributor

lgrz commented Apr 17, 2015

In relation to the feature gate list above I'm going to start off by looking into the following:

update: removed items that had tests, and added optin_builtin_traits, advanced_slice_patterns

  • rustc_attrs
  • on_unimplemented
  • custom_derive
  • box_patterns
  • optin_builtin_traits
  • advanced_slice_patterns

@pnkfelix
Copy link
Member Author

@Lstat ah yes, #23974 is (correctly) why the help mag is missing .... hmm .... that complicates things

@lgrz
Copy link
Contributor

lgrz commented Apr 18, 2015

I've done a pass through of the unchecked feature gates and have found tests for the following:

@pnkfelix Could these be marked as complete?

@pnkfelix
Copy link
Member Author

@Lstat thanks!

@lgrz
Copy link
Contributor

lgrz commented Apr 20, 2015

Ok, so I've had a look through everything, here's my findings:

@pnkfelix I have some questions below for the three outstanding feature gates (at the very bottom of this comment) and was wondering if you could help confirm the status of those feature gate tests?

My previous comment listed feature gates that had existing tests. I've since found a few more to add to that list.

Here is the full list of feature gates with existing tests. New findings are in bold:

The following feature gates were removed after this issue was initially created. Since they are no longer around they can be considered complete or crossed out of the task list above:

The following feature gates appear to have duplicate tests introduced in #23578, the initial tests were added in #20723 and #21233:

  • box_patterns
  • simd_ffi

The following are not in the above task list as they have been added since the issue was initially created:

The following are remaining feature gates needing tests (excluding the feature gates I had questions for, see below). I'm cooking up a PR for these:

  • on_unimplemented
  • rust_attr
  • optin_builtin_traits
  • plugin
  • slice_patterns
  • negate_unsigned

The following items are ones that I had trouble completing because I have questions and need some feedback:

  • unmarked_api
  • visible_private_types
  • rustc_diagnostic_macros

unmarked_api

The unmarked_api was introduced in #21910, and tests for unmarked_api were replaced with tests for missing stability attributes: missing-stability.rs.

In addition, it seems that there is no way to trigger this code path unless there is a bug in a library or the compiler itself.

Are the tests in missing-stability.rs enough to consider unmarked_api complete?

visible_private_types

These appear to be the tests we're looking for relating to visible_private_types, could someone confirm this?

rustc_diagnostic_macros

This appears to be the rustc_diagnostic_macros feature gate test, but was removed in #19362 (14f9127) rustc-diagnostics-3.rs

Should we reinstate the test in this issue or let it be handled by #19624 which is in the works?

steveklabnik added a commit to steveklabnik/rust that referenced this issue Apr 24, 2015
As part of the audit for rust-lang#22820 the following duplicate feature
gate tests were removed:

* `box_patterns`
* `simd_ffi`

These tests for `box_patterns` and `simd_ffi` were added in rust-lang#23578,
however there were existing tests in rust-lang#20723 and rust-lang#21233 respectively.

r? @nrc
steveklabnik added a commit to steveklabnik/rust that referenced this issue Apr 24, 2015
As part of the audit for rust-lang#22820 the following duplicate feature
gate tests were removed:

* `box_patterns`
* `simd_ffi`

These tests for `box_patterns` and `simd_ffi` were added in rust-lang#23578,
however there were existing tests in rust-lang#20723 and rust-lang#21233 respectively.

r? @nrc
steveklabnik added a commit to steveklabnik/rust that referenced this issue Apr 25, 2015
As part of the audit for rust-lang#22820 the following feature gate tests have been
added:

* `negate_unsigned`
* `on_unimplemented`
* `optin_builtin_traits`
* `plugin`
* `rustc_attrs`
* `rustc_diagnostic_macros`
* `slice_patterns`

In addition some feature gate error message typos fixed.
steveklabnik added a commit to steveklabnik/rust that referenced this issue Apr 25, 2015
As part of the audit for rust-lang#22820 the following duplicate feature
gate tests were removed:

* `box_patterns`
* `simd_ffi`

These tests for `box_patterns` and `simd_ffi` were added in rust-lang#23578,
however there were existing tests in rust-lang#20723 and rust-lang#21233 respectively.

r? @nrc
@abhijeetbhagat
Copy link
Contributor

For visible_private_types, i found src/test/run-pass/visible-private-types-feature-gate.rs
Not sure if item this should be ticked as well.

@brson brson removed the E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. label Jun 27, 2016
@brson
Copy link
Contributor

brson commented Jun 27, 2016

There appear to be a lot of new unstable features since this was touched. It seems hopeless to ever catch up on this issue without an automatic tidy script verifying the tests exist. @pnkfelix do you want this issue to continue? Should we try to augment tidy to check the existence of compile-fail tests mentioning unstable features?

@pnkfelix
Copy link
Member Author

@brson I agree that it seems like we'll never be able to close this without having some sort of automation (e.g. a tidy script, as you say) to verify that the tests exist.

I don't have any immediate idea about the best way to write such a script. I guess it could just be based on some naming convention for the test itself; i.e. it would be just a heuristic check, not a true verification of it.

@brson
Copy link
Contributor

brson commented Jun 28, 2016

I think it could be written like so: after featureck, search everything in src/compile-fail for #![deny($feature_name)]. If this makes sense I can mentor.

@brson brson added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jun 28, 2016
@pnkfelix
Copy link
Member Author

@brson but requiring the test to explicitly deny the feature defeats the point, doesn't it?

That is, the goal here is to catch code that makes use of a feature without explicitly opting into that feature. ..

Though I suppose you might be thinking that if there is enough infrastructure present to support some kind of deny(feature) attribute, then that is a sign that the necessary gating is in place, regardless of what the default lint settings actually are?

@brson
Copy link
Contributor

brson commented Jun 29, 2016

@pnkfelix Good point. I think yes, I was considering that just confirming that the compiler has code that correctly can deny the feature is good enough, but there is some room for error by making the deny explicit. The deny attribute also wouldn't actually confirm that the compile failed for the correct reason. We could also just require tests to annotate in some other way that yes, it is testing that a particular feature is denied.

As an extension to my previous suggestion, the test runner could take the test case that is annotated to be a 'deny feature' test, run it once with allow(feature) then run it again with no feature attribute, and compare the results.

@brson
Copy link
Contributor

brson commented Jun 29, 2016

Similarly to the above, but to avoid creating another custom test runner. The featureck lint could require that compile-test and run-pass contain pairs of feature tests that are identical, one with #[allow(feature)] and one without.

@brson brson removed E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. labels Jun 29, 2016
bors added a commit that referenced this issue Jan 14, 2017
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).
@est31
Copy link
Member

est31 commented Mar 15, 2017

With #39059 fixed, maybe this issue can be closed as resolved?

@brson brson closed this as completed May 23, 2017
@brson
Copy link
Contributor

brson commented May 23, 2017

Thanks @est31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: Writing correctness tests.
Projects
None yet
Development

No branches or pull requests

6 participants