Auto merge of #83857 - ABouttefeux:master, r=jyn514

added --no-run option for rustdoc

resolve #59053

add `--no-run` option for `rustdoc` for compiling doc test but not running them.
Intended for use with `--persist-doctests`.
This commit is contained in:
bors 2021-05-01 15:36:23 +00:00
commit 5f304a5d79
7 changed files with 71 additions and 1 deletions

View File

@ -120,6 +120,8 @@ fn try_from(value: &str) -> Result<Self, Self::Error> {
/// For example, using ignore-foo to ignore running the doctest on any target that
/// contains "foo" as a substring
crate enable_per_target_ignores: bool,
/// Do not run doctests, compile them if should_test is active.
crate no_run: bool,
/// The path to a rustc-like binary to build tests with. If not set, we
/// default to loading from `$sysroot/bin/rustc`.
@ -197,6 +199,7 @@ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
.field("runtool_args", &self.runtool_args)
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
.field("run_check", &self.run_check)
.field("no_run", &self.no_run)
.finish()
}
}
@ -466,6 +469,12 @@ fn println_condition(condition: Condition) {
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
let should_test = matches.opt_present("test");
let no_run = matches.opt_present("no-run");
if !should_test && no_run {
diag.err("the `--test` flag must be passed to enable `--no-run`");
return Err(1);
}
let output =
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
@ -666,6 +675,7 @@ fn println_condition(condition: Condition) {
enable_per_target_ignores,
test_builder,
run_check,
no_run,
render_options: RenderOptions {
output,
external_html,

View File

@ -940,13 +940,14 @@ fn add_test(&mut self, test: String, config: LangString, line: usize) {
let report_unused_externs = |uext| {
unused_externs.lock().unwrap().push(uext);
};
let no_run = config.no_run || options.no_run;
let res = run_test(
&test,
&cratename,
line,
options,
config.should_panic,
config.no_run,
no_run,
config.test_harness,
runtool,
runtool_args,

View File

@ -595,6 +595,7 @@ fn opts() -> Vec<RustcOptGroup> {
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
)
}),
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
]
}

View File

@ -0,0 +1,6 @@
// test the behavior of the --no-run flag without the --test flag
// compile-flags:-Z unstable-options --no-run --test-args=--test-threads=1
// error-pattern: the `--test` flag must be passed
pub fn f() {}

View File

@ -0,0 +1,2 @@
error: the `--test` flag must be passed to enable `--no-run`

View File

@ -0,0 +1,38 @@
// test the behavior of the --no-run flag
// check-pass
// compile-flags:-Z unstable-options --test --no-run --test-args=--test-threads=1
// normalize-stdout-test: "src/test/rustdoc-ui" -> "$$DIR"
// normalize-stdout-test "finished in \d+\.\d+s" -> "finished in $$TIME"
/// ```
/// let a = true;
/// ```
/// ```should_panic
/// panic!()
/// ```
/// ```ignore (incomplete-code)
/// fn foo() {
/// ```
/// ```no_run
/// loop {
/// println!("Hello, world");
/// }
/// ```
/// fails to compile
/// ```compile_fail
/// let x = 5;
/// x += 2; // shouldn't compile!
/// ```
/// Ok the test does not run
/// ```
/// panic!()
/// ```
/// Ok the test does not run
/// ```should_panic
/// loop {
/// println!("Hello, world");
/// panic!()
/// }
/// ```
pub fn f() {}

View File

@ -0,0 +1,12 @@
running 7 tests
test $DIR/no-run-flag.rs - f (line 11) ... ok
test $DIR/no-run-flag.rs - f (line 14) ... ignored
test $DIR/no-run-flag.rs - f (line 17) ... ok
test $DIR/no-run-flag.rs - f (line 23) ... ok
test $DIR/no-run-flag.rs - f (line 28) ... ok
test $DIR/no-run-flag.rs - f (line 32) ... ok
test $DIR/no-run-flag.rs - f (line 8) ... ok
test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out; finished in $TIME