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

Add little is_test_crate function #109985

Merged
merged 2 commits into from
Apr 10, 2023
Merged

Add little is_test_crate function #109985

merged 2 commits into from
Apr 10, 2023

Conversation

blyxyas
Copy link
Member

@blyxyas blyxyas commented Apr 5, 2023

Ok, this is quite a story.
I'm mainly a Clippy contributor, so I was fixing this Clippy issue about a lint having to ignore test modules but that wasn't ignoring test files (integration test, test/ dirs and such).

As test files don't tend to have an inner #[cfg(test)] module inside them, I tried everything, looking for filenames, looking for item's parents in the HIR Map, doing black magic...

I even asked on Zulip, and jyn answered something about --cfg test. Aha! That's something that I might be looking for, so I started looking at rustc_driver_impl flag parsing and configuration and all that.

Then, I stumbled on this function right here, and noticed the argument config: Config. That's a hint.

So Config has the field opts: Options, and Options has the field test.

This journey has been ~7 or 8 hours in 3 days, it's a very hard thing to find, so this PR adds a mini-function to check if the current crate is a testing one. So that no one has to travel through the same as me, and can just search for is_test_crate in the documentation.

@rustbot
Copy link
Collaborator

rustbot commented Apr 5, 2023

r? @jackh726

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Apr 5, 2023
Copy link
Member

@compiler-errors compiler-errors left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to test for --cfg test, then you're gonna have to do something like tcx.sess.parse_sess.config.contains(sym::test), I think. --test implies --cfg test, but --cfg test does not imply --test.

I don't have enough background about what you needed this for to know whether that's what you wanted.

Also, side-note, this should be squashed into one commit.

@blyxyas
Copy link
Member Author

blyxyas commented Apr 5, 2023

It seems like it isn't necessary.
Edit: It isn't necessary because it isn't searching for the specific --cfg test, but only if the compiler session is a test one. --cfg test was just an inspiration

@compiler-errors
Copy link
Member

compiler-errors commented Apr 9, 2023

Please also migrate all of the other usages of sess.opts.test to use this helper -- there are 9 that I can see in the compiler source.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2023
@blyxyas
Copy link
Member Author

blyxyas commented Apr 9, 2023

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 9, 2023
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Apr 9, 2023

📌 Commit 2c97676 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 9, 2023
@bors
Copy link
Contributor

bors commented Apr 10, 2023

⌛ Testing commit 2c97676 with merge f036f34036470ab3d5cdc9e762051e9588ef9321...

@bors
Copy link
Contributor

bors commented Apr 10, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Apr 10, 2023
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 10, 2023
…iaskrgr

Rollup of 6 pull requests

Successful merges:

 - rust-lang#108843 (Instantiate instead of erasing binder when probing param methods)
 - rust-lang#109985 (Add little `is_test_crate` function)
 - rust-lang#110028 (Migrate `rustc_hir_analysis` to session diagnostic [Part 3])
 - rust-lang#110095 (Migrate remainder of rustc_ty_utils to `SessionDiagnostic`)
 - rust-lang#110108 (Add renaming of ignore-git to changelog)
 - rust-lang#110114 (compiletest: Give a better error message if `node` isn't installed)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@ehuss
Copy link
Contributor

ehuss commented Apr 10, 2023

@bors retry

crates.io network blip

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 10, 2023
@bors bors merged commit 3dfda2c into rust-lang:master Apr 10, 2023
@rustbot rustbot added this to the 1.70.0 milestone Apr 10, 2023
@rust-log-analyzer
Copy link
Collaborator

The job dist-i686-msvc failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants