-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 lint warning for inner function marked as #[test]
#2471
Conversation
I have a quick question, why do inner test functions not run? a good use case for inner test function is the outer function you have a const you dont want to expose to the world. but in the inner function, you need test the outer function with the const as input for example something like sin function with pi as input but obviously the const is supposed to be hidden. |
@warlord500 they cannot run because test functions need to be addressable, and inner functions aren't. |
Does this need an RFC? It sounds like a bug fix to me. |
CC @rust-lang/lang |
Yeah, this doesn’t need an RFC.
…On Tue, Jun 12, 2018 at 12:51 AM Esteban Kuber ***@***.***> wrote:
CC @rust-lang/lang <https://github.com/orgs/rust-lang/teams/lang>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#2471 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/ABY2UT2CUmkHggvV0hvcBJqgUAMjwOk1ks5t73LsgaJpZM4Uh52H>
.
|
What if we use hygiene to force name resolution of the harness paths (well, they can be just single identifiers then) to occur in the definition scope of the test functions? |
Looks like for each
Sounds possible if expansion of |
@petrochenkov That's an interesting approach, but wouldn't it suffice to only have a single |
Ah, I see, then it should look something like:
|
However, if we can do what I wrote above, then we can probably directly assign resolution to the |
@petrochenkov Yeah, the main reason I wanted to avoid dealing with resolution directly is for moving the test harness into a library macro, so it would literally only get one ident token per |
We would still meet to make sure there are no rest functions nested inside another test function, right? |
@estebank I don't see how that would be a problem. |
We discussed this in the lang team meeting. Our conclusion: because this doesn't work today, we should have a lint about it. If someone wants to propose a separate RFC that defines a behavior for this, they can also propose a change to the lint. @rfcbot fcp merge |
Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged teams: No concerns currently listed. Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
As an aside, perhaps things like putting |
One possible way it wouldn't need an RFC might be if it's a fix-a-false-negative extension of the existing trait Foo {
#[test]
fn foo() {}
}
|
I agree with @scottmcm, if we can make the |
Per rust-lang/rust#36629 (comment), this was done without the RFC being accepted? |
(This is currently not implemented on stable but it is implemented in the beta compiler, which becomes stable on 2018-09-13) |
It can safely be reverted. I forgot about the RFCS I'd opened when I pinged on the PR and it got approved. |
I still think this should be @rfcbot reviewed |
Hmm, does For either, I think we can move the bit that looks at |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period, with a disposition to merge, as per the review above, is now complete. |
Huzzah! This RFC has been merged! Tracking issue: rust-lang/rust#53911 |
…trochenkov Make test harness lint about unnnameable tests. Implementation of rust-lang#113734 (comment) About the options suggested in rust-lang#36629 (comment): adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in rust-lang/rfcs#2471 (comment) This was just simpler to do in a standalone PR. I'll remove the corresponding changes from rust-lang#113734 later. r? `@petrochenkov`
Make test harness lint about unnnameable tests. Implementation of rust-lang/rust#113734 (comment) About the options suggested in rust-lang/rust#36629 (comment): adding this case to unused_attribute was just more complicated. I'll try to understand a bit more what you had in mind in rust-lang/rfcs#2471 (comment) This was just simpler to do in a standalone PR. I'll remove the corresponding changes from rust-lang/rust#113734 later. r? `@petrochenkov`
Rendered
Tracking issue
Add a lint that warns when marking an inner function as
#[test]
.#[test]
is used to mark functions to be run as part of a test suite. Thefunctions being marked need to be addressable for this to work. Currently,
marking an inner function as
#[test]
will not raise any errors or warnings,but the test will silently not be run. By adding a lint that identifies these
cases, users are less likely to fail to notice.
Implemented in rust-lang/rust#51450.