Skip to content

Don't pass doctest feature by default #65190

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,10 +343,7 @@ impl Options {
let output = matches.opt_str("o")
.map(|s| PathBuf::from(&s))
.unwrap_or_else(|| PathBuf::from("doc"));
let mut cfgs = matches.opt_strs("cfg");
if should_test {
cfgs.push("doctest".to_string());
}
let cfgs = matches.opt_strs("cfg");

let extension_css = matches.opt_str("e").map(|s| PathBuf::from(&s));

Expand Down
1 change: 1 addition & 0 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ pub fn run(options: Options) -> i32 {

let mut cfgs = options.cfgs.clone();
cfgs.push("rustdoc".to_owned());
cfgs.push("doctest".to_owned());
let config = interface::Config {
opts: sessopts,
crate_cfg: config::parse_cfgspecs(cfgs),
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc-ui/doc-test-doctest-feature.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// build-pass
// compile-flags:--test
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"

#![feature(cfg_doctest)]

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

/// ```
/// #![feature(cfg_doctest)]
/// assert!(!cfg!(doctest));
/// ```
#[cfg(doctest)]
pub struct Foo;
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/doc-test-doctest-feature.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

running 1 test
test $DIR/doc-test-doctest-feature.rs - Foo (line 10) ... ok

test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out