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

Prevent rustdoc feature doctests #64741

Merged

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Sep 24, 2019

Part of #61351

cc @ollie27

let mut test_args = options.test_args.clone();
let mut test_args = options.test_args
.iter()
.filter_map(|arg| {
Copy link
Contributor

Choose a reason for hiding this comment

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

.filter(..).cloned() seems cleaner here.

Copy link
Member

Choose a reason for hiding this comment

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

I continue to be deeply confused why we're altering test_args here.

test_args is the array of arguments that's passed to test::test_main -- that's way too late for cfg to matter, I believe, and test_main certainly is not a compiler.

Can you at least check manually that this works? A comment that explains how this works (e.g., why is this applying to cfg, despite not mentioning cfg at all?) would also be good.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just thought about it when you said something was wrong in this implementation the other day: it's incorrect since I don't check the cfg. However, test_args are passed to each code sample rustdoc compiles and run. Therefore, it seems accurate to me to have this check here. However I need to fix it.

Copy link
Member

Choose a reason for hiding this comment

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

But... they're not? These are not the arguments to rustc. These are the arguments to the test 'binary'. I would expect you to never find a --cfg in these arguments; they're not (AFAICT) used at all for compilation. Right now the code is removing a test filter for rustdoc -- not a cfg gate or anything like that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Then I completely misunderstood this part of the code... I'll take a step back and check what I missed...

@GuillaumeGomez GuillaumeGomez force-pushed the prevent-rustdoc-feature-doctests branch 2 times, most recently from d19f3f3 to b69ae4a Compare September 25, 2019 14:48
@GuillaumeGomez
Copy link
Member Author

Indeed, I wasn't looking at the good place at all... Thanks a lot for catching up my error @Mark-Simulacrum !

@@ -251,7 +251,9 @@ fn run_test(
let mut compiler = Command::new(std::env::current_exe().unwrap().with_file_name("rustc"));
compiler.arg("--crate-type").arg("bin");
for cfg in &options.cfgs {
compiler.arg("--cfg").arg(&cfg);
if cfg != "rustdoc" {
Copy link
Member

Choose a reason for hiding this comment

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

This also feels like the wrong place :)

I would expect us to not add the rustdoc cfg ourselves -- looking at it, I guess here -- not remove it later on. We don't want to remove it if the user has passed it.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's a good point I didn't think about... Checking more globally why we even need to do this. However, I think we need it at some point to check for the documentation build (not the tests build). I'm looking around to confirm it.

@GuillaumeGomez GuillaumeGomez force-pushed the prevent-rustdoc-feature-doctests branch from b69ae4a to e4e674b Compare September 25, 2019 15:08
@GuillaumeGomez
Copy link
Member Author

@Mark-Simulacrum Just like you suggested, instead of adding it into the options directly, I removed it from there and add it before the doc build. Sorry about all the fuss...

@JohnCSimon JohnCSimon added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 28, 2019
@GuillaumeGomez
Copy link
Member Author

ping @Mark-Simulacrum

@Mark-Simulacrum
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Sep 30, 2019

📌 Commit e4e674bec91e364f290ab8b708d960a292d2678a has been approved by Mark-Simulacrum

@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 Sep 30, 2019
@ollie27
Copy link
Member

ollie27 commented Sep 30, 2019

Shouldn't cfg(rustdoc) be set when looking for doctests as well:

crate_cfg: config::parse_cfgspecs(options.cfgs.clone()),

@bors r-

We need tests for this, a rustdoc-ui test like the following should be sufficient:

// build-pass
// compile-flags:--test
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"

#![feature(doc_cfg)]

// Make sure `cfg(rustdoc)` is set when finding doctests but not inside the doctests.

/// ```
/// #![feature(doc_cfg)]
/// assert!(!cfg!(rustdoc));
/// ```
#[cfg(rustdoc)]
pub struct Foo;

@bors bors 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Sep 30, 2019
@Mark-Simulacrum
Copy link
Member

r? @ollie27

I assumed that setting it in core would've done that...

@GuillaumeGomez
Copy link
Member Author

I did as well since we use this one for it. Adding the test.

@GuillaumeGomez GuillaumeGomez force-pushed the prevent-rustdoc-feature-doctests branch from e4e674b to 57faf0f Compare September 30, 2019 14:19
@GuillaumeGomez
Copy link
Member Author

@ollie27 It seems like the test passed whereas I didn't change the code. Did we misunderstood your message?

@ollie27
Copy link
Member

ollie27 commented Sep 30, 2019

If you look at the stdout it shows that it didn't actually run the doctest. It should say "running 1 test".

@GuillaumeGomez
Copy link
Member Author

Oh I see! Indeed, good catch!

@GuillaumeGomez GuillaumeGomez force-pushed the prevent-rustdoc-feature-doctests branch from 57faf0f to 366fdeb Compare October 1, 2019 12:38
@GuillaumeGomez
Copy link
Member Author

Now we have it as well.

@QuietMisdreavus
Copy link
Member

This looks like it's ready to go, and that @ollie27's test has been added and is working, so i'm going to push this along...

@bors r+

@bors
Copy link
Contributor

bors commented Oct 3, 2019

📌 Commit 366fdeb has been approved by QuietMisdreavus

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 3, 2019
Centril added a commit to Centril/rust that referenced this pull request Oct 3, 2019
…ure-doctests, r=QuietMisdreavus

Prevent rustdoc feature doctests

Part of rust-lang#61351

cc @ollie27
Centril added a commit to Centril/rust that referenced this pull request Oct 3, 2019
…ure-doctests, r=QuietMisdreavus

Prevent rustdoc feature doctests

Part of rust-lang#61351

cc @ollie27
tmandry added a commit to tmandry/rust that referenced this pull request Oct 3, 2019
…ure-doctests, r=QuietMisdreavus

Prevent rustdoc feature doctests

Part of rust-lang#61351

cc @ollie27
tmandry added a commit to tmandry/rust that referenced this pull request Oct 3, 2019
…ure-doctests, r=QuietMisdreavus

Prevent rustdoc feature doctests

Part of rust-lang#61351

cc @ollie27
bors added a commit that referenced this pull request Oct 3, 2019
Rollup of 11 pull requests

Successful merges:

 - #61879 (Stabilize todo macro)
 - #64675 (Deprecate `#![plugin]` & `#[plugin_registrar]`)
 - #64690 (proc_macro API: Expose `macro_rules` hygiene)
 - #64706 (add regression test for #60218)
 - #64741 (Prevent rustdoc feature doctests)
 - #64842 (Disallow Self in type param defaults of ADTs)
 - #65004 (Replace mentions of IRC with Discord)
 - #65018 (Set RUST_BACKTRACE=0 in tests that include a backtrace in stderr)
 - #65055 (Add long error explanation for E0556)
 - #65056 (Make visit projection iterative)
 - #65057 (typo: fix typo in E0392)

Failed merges:

r? @ghost
@bors bors merged commit 366fdeb into rust-lang:master Oct 4, 2019
@GuillaumeGomez GuillaumeGomez deleted the prevent-rustdoc-feature-doctests branch October 4, 2019 08:24
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants