Skip to content

Add little is_test_crate function#109985

Merged
bors merged 2 commits into
rust-lang:masterfrom
blyxyas:is_test_crate
Apr 10, 2023
Merged

Add little is_test_crate function#109985
bors merged 2 commits into
rust-lang:masterfrom
blyxyas:is_test_crate

Conversation

@blyxyas

@blyxyas blyxyas commented Apr 5, 2023

Copy link
Copy Markdown
Member

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

rustbot commented Apr 5, 2023

Copy link
Copy Markdown
Collaborator

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

@compiler-errors compiler-errors left a comment

Copy link
Copy Markdown
Contributor

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.

Comment thread compiler/rustc_session/src/session.rs Outdated
@blyxyas

blyxyas commented Apr 5, 2023

Copy link
Copy Markdown
Member Author

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

compiler-errors commented Apr 9, 2023

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

@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

blyxyas commented Apr 9, 2023

Copy link
Copy Markdown
Member Author

@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
Copy Markdown
Contributor

@bors r+

@bors

bors commented Apr 9, 2023

Copy link
Copy Markdown
Collaborator

📌 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

bors commented Apr 10, 2023

Copy link
Copy Markdown
Collaborator

⌛ Testing commit 2c97676 with merge f036f34036470ab3d5cdc9e762051e9588ef9321...

@bors

bors commented Apr 10, 2023

Copy link
Copy Markdown
Collaborator

💔 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

ehuss commented Apr 10, 2023

Copy link
Copy Markdown
Contributor

@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
Copy Markdown
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