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

Set cfg(test) when rustdoc is running with --test option #59940

Merged
merged 2 commits into from Apr 26, 2019

Conversation

Projects
None yet
9 participants
@GuillaumeGomez
Copy link
Member

commented Apr 13, 2019

Following a discussion on twitter, I proposed this change. What do you think about it?

r? @QuietMisdreavus

cc @BurntSushi

@BurntSushi

This comment has been minimized.

Copy link
Member

commented Apr 13, 2019

I'm not sure what the rustdoc team procedures are here, but you might want to consider this as a normal public API addition. That is, if you accept this change and it makes it to stable Rust, then removing this would be a breaking change AIUI. For example, one thing I think this would allow you to do is to write doc tests using code that is gated behind a cfg(test).

@ehuss

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2019

There is some discussion about this in #45599.

@QuietMisdreavus

This comment has been minimized.

Copy link
Member

commented Apr 13, 2019

(Sorry about closing this, i misclicked the button when typing my initial comment. 😓)

This looks like it's not the same as #45599 - this is about setting cfg(test) when collecting doctests, not when compiling them. This is probably fine, since there's been a slight pattern of having non-public doctests to test when something should not compile, or (in the case of the linked twitter thread) to check the doctests of the README without directly including it in the crate's docs. I originally learned about this when trying to block doctests on private items (#54438). It looks like this is a way to properly support that.

@ehuss

This comment has been minimized.

Copy link
Contributor

commented Apr 13, 2019

Ah, sorry for misinterpreting.

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 24, 2019

So is it ok to merge it?

@QuietMisdreavus QuietMisdreavus changed the title Set test flag when rustdoc is running with --test option Set cfg(test) when rustdoc is running with --test option Apr 24, 2019

@QuietMisdreavus
Copy link
Member

left a comment

This seems fine to me, though i'm a little worried that there will be some subtle ramifications that we haven't thought about. I'd like someone from @rust-lang/docs or @rust-lang/rustdoc to see whether i'm overthinking this, but in the meantime there doesn't seem to be much harm from landing it into nightly for now - we have plenty of time to revert it if things go awry.

@QuietMisdreavus

This comment has been minimized.

Copy link
Member

commented Apr 24, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 24, 2019

📌 Commit 1ce17e6 has been approved by QuietMisdreavus

@ollie27

This comment has been minimized.

Copy link
Contributor

commented Apr 24, 2019

I'm a bit worried that doctests on items marked #[cfg(not(test))] will no longer be run but I don't know how common that would be in the wild.

Also can we add a rustdoc-ui test like the following to test this behavior?

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

/// this doctest will be ignored:
///
/// ```
/// assert!(false);
/// ```
#[cfg(not(test))]
pub struct Foo;

/// this doctest will be tested:
///
/// ```
/// assert!(true);
/// ```
#[cfg(test)]
pub struct Foo;
@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 24, 2019

@ollie27: Hum good point, they won't be tested indeed. I don't see it as an issue since there are workarounds though. I'll add the test shortly.

@bors: r-

@GuillaumeGomez GuillaumeGomez force-pushed the GuillaumeGomez:rustdoc-test branch from 1ce17e6 to 459d677 Apr 24, 2019

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 24, 2019

Updated!

@GuillaumeGomez

This comment has been minimized.

Copy link
Member Author

commented Apr 25, 2019

r? @ollie27 (since @QuietMisdreavus was ok with the changes, I guess it's up to you to validate the tests :p)

@ollie27

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

📌 Commit 459d677 has been approved by ollie27

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 25, 2019

⌛️ Testing commit 459d677 with merge b3ad6a6...

bors added a commit that referenced this pull request Apr 25, 2019

Auto merge of #59940 - GuillaumeGomez:rustdoc-test, r=ollie27
Set cfg(test) when rustdoc is running with --test option

Following a [discussion on twitter](https://twitter.com/burntsushi5/status/1117091914199785473), I proposed this change. What do you think about it?

r? @QuietMisdreavus

cc @BurntSushi
@Centril

This comment has been minimized.

Copy link
Member

commented Apr 25, 2019

@bors retry

yielding to r0llup

@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 26, 2019

⌛️ Testing commit 459d677 with merge 3ae1afd...

bors added a commit that referenced this pull request Apr 26, 2019

Auto merge of #59940 - GuillaumeGomez:rustdoc-test, r=ollie27
Set cfg(test) when rustdoc is running with --test option

Following a [discussion on twitter](https://twitter.com/burntsushi5/status/1117091914199785473), I proposed this change. What do you think about it?

r? @QuietMisdreavus

cc @BurntSushi

Centril added a commit to Centril/rust that referenced this pull request Apr 26, 2019

Rollup merge of rust-lang#59940 - GuillaumeGomez:rustdoc-test, r=ollie27
Set cfg(test) when rustdoc is running with --test option

Following a [discussion on twitter](https://twitter.com/burntsushi5/status/1117091914199785473), I proposed this change. What do you think about it?

r? @QuietMisdreavus

cc @BurntSushi
@Centril

This comment has been minimized.

Copy link
Member

commented Apr 26, 2019

@bors retry

@Centril Centril added this to the 1.36 milestone Apr 26, 2019

bors added a commit that referenced this pull request Apr 26, 2019

Auto merge of #60296 - Centril:rollup-qh9la7k, r=Centril
Rollup of 12 pull requests

Successful merges:

 - #59734 (Prevent failure in case no space left on device in rustdoc)
 - #59940 (Set cfg(test) when rustdoc is running with --test option)
 - #60134 (Fix index-page generation)
 - #60165 (Add Pin::{into_inner,into_inner_unchecked})
 - #60183 (Chalkify: Add builtin Copy/Clone)
 - #60225 (Introduce hir::ExprKind::Use and employ in for loop desugaring.)
 - #60247 (Implement Debug for Place using Place::iterate)
 - #60259 (Derive Default instead of new in applicable lint)
 - #60267 (Add feature-gate for f16c target feature)
 - #60284 (Do not allow const generics to depend on type parameters)
 - #60285 (Do not ICE when checking types against foreign fn)
 - #60289 (Make `-Z allow-features` work for stdlib features)

Failed merges:

r? @ghost
@bors

This comment has been minimized.

Copy link
Contributor

commented Apr 26, 2019

⌛️ Testing commit 459d677 with merge 180edc2...

@bors bors merged commit 459d677 into rust-lang:master Apr 26, 2019

1 of 2 checks passed

homu Testing commit 459d677bfffa0adeef75218d1cfa5f686e413f4d with merge 180edc21eeca50d0d597de091c8eb712667b5dd2...
Details
Travis CI - Pull Request Build Passed
Details

@GuillaumeGomez GuillaumeGomez deleted the GuillaumeGomez:rustdoc-test branch Apr 26, 2019

dvdhrm added a commit to r-util/r-efi-string that referenced this pull request May 6, 2019

build: enable doctests again
The rustdoc program now sets `cfg(test)` if run with `--test`. Hence,
the r-efi-string crate will now compile properly under all
circumstances. Therefore, re-enable the doctests for better test
coverage. Note that this will be released with rust-1.36.

For details, see:

    rust-lang/rust#59940

Signed-off-by: David Rheinsberg <david.rheinsberg@gmail.com>

@ehuss ehuss referenced this pull request May 13, 2019

Closed

Fix tests on nightly. #1958

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.