Skip to content

Commit

Permalink
Rollup merge of rust-lang#59940 - GuillaumeGomez:rustdoc-test, r=ollie27
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Centril committed Apr 26, 2019
2 parents 294e89d + 459d677 commit 09a7051
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/librustdoc/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,9 @@ impl Options {
.unwrap_or_else(|| PathBuf::from("doc"));
let mut cfgs = matches.opt_strs("cfg");
cfgs.push("rustdoc".to_string());
if should_test {
cfgs.push("test".to_string());
}

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

Expand Down
19 changes: 19 additions & 0 deletions src/test/rustdoc-ui/cfg-test.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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;
6 changes: 6 additions & 0 deletions src/test/rustdoc-ui/cfg-test.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

running 1 test
test $DIR/cfg-test.rs - Foo (line 15) ... ok

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

0 comments on commit 09a7051

Please sign in to comment.