Skip to content

Commit 5f304a5

Browse files
committed
Auto merge of rust-lang#83857 - ABouttefeux:master, r=jyn514
added --no-run option for rustdoc resolve rust-lang#59053 add `--no-run` option for `rustdoc` for compiling doc test but not running them. Intended for use with `--persist-doctests`.
2 parents 603a42e + 03c710b commit 5f304a5

File tree

7 files changed

+71
-1
lines changed

7 files changed

+71
-1
lines changed

src/librustdoc/config.rs

+10
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ crate struct Options {
120120
/// For example, using ignore-foo to ignore running the doctest on any target that
121121
/// contains "foo" as a substring
122122
crate enable_per_target_ignores: bool,
123+
/// Do not run doctests, compile them if should_test is active.
124+
crate no_run: bool,
123125

124126
/// The path to a rustc-like binary to build tests with. If not set, we
125127
/// default to loading from `$sysroot/bin/rustc`.
@@ -197,6 +199,7 @@ impl fmt::Debug for Options {
197199
.field("runtool_args", &self.runtool_args)
198200
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
199201
.field("run_check", &self.run_check)
202+
.field("no_run", &self.no_run)
200203
.finish()
201204
}
202205
}
@@ -466,6 +469,12 @@ impl Options {
466469
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
467470

468471
let should_test = matches.opt_present("test");
472+
let no_run = matches.opt_present("no-run");
473+
474+
if !should_test && no_run {
475+
diag.err("the `--test` flag must be passed to enable `--no-run`");
476+
return Err(1);
477+
}
469478

470479
let output =
471480
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
@@ -666,6 +675,7 @@ impl Options {
666675
enable_per_target_ignores,
667676
test_builder,
668677
run_check,
678+
no_run,
669679
render_options: RenderOptions {
670680
output,
671681
external_html,

src/librustdoc/doctest.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -940,13 +940,14 @@ impl Tester for Collector {
940940
let report_unused_externs = |uext| {
941941
unused_externs.lock().unwrap().push(uext);
942942
};
943+
let no_run = config.no_run || options.no_run;
943944
let res = run_test(
944945
&test,
945946
&cratename,
946947
line,
947948
options,
948949
config.should_panic,
949-
config.no_run,
950+
no_run,
950951
config.test_harness,
951952
runtool,
952953
runtool_args,

src/librustdoc/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -595,6 +595,7 @@ fn opts() -> Vec<RustcOptGroup> {
595595
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
596596
)
597597
}),
598+
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
598599
]
599600
}
600601

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// test the behavior of the --no-run flag without the --test flag
2+
3+
// compile-flags:-Z unstable-options --no-run --test-args=--test-threads=1
4+
// error-pattern: the `--test` flag must be passed
5+
6+
pub fn f() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
error: the `--test` flag must be passed to enable `--no-run`
2+

src/test/rustdoc-ui/no-run-flag.rs

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// test the behavior of the --no-run flag
2+
3+
// check-pass
4+
// compile-flags:-Z unstable-options --test --no-run --test-args=--test-threads=1
5+
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
6+
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
7+
8+
/// ```
9+
/// let a = true;
10+
/// ```
11+
/// ```should_panic
12+
/// panic!()
13+
/// ```
14+
/// ```ignore (incomplete-code)
15+
/// fn foo() {
16+
/// ```
17+
/// ```no_run
18+
/// loop {
19+
/// println!("Hello, world");
20+
/// }
21+
/// ```
22+
/// fails to compile
23+
/// ```compile_fail
24+
/// let x = 5;
25+
/// x += 2; // shouldn't compile!
26+
/// ```
27+
/// Ok the test does not run
28+
/// ```
29+
/// panic!()
30+
/// ```
31+
/// Ok the test does not run
32+
/// ```should_panic
33+
/// loop {
34+
/// println!("Hello, world");
35+
/// panic!()
36+
/// }
37+
/// ```
38+
pub fn f() {}
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
running 7 tests
3+
test $DIR/no-run-flag.rs - f (line 11) ... ok
4+
test $DIR/no-run-flag.rs - f (line 14) ... ignored
5+
test $DIR/no-run-flag.rs - f (line 17) ... ok
6+
test $DIR/no-run-flag.rs - f (line 23) ... ok
7+
test $DIR/no-run-flag.rs - f (line 28) ... ok
8+
test $DIR/no-run-flag.rs - f (line 32) ... ok
9+
test $DIR/no-run-flag.rs - f (line 8) ... ok
10+
11+
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME
12+

0 commit comments

Comments
 (0)