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:
commit
5f304a5d79
7 changed files with 71 additions and 1 deletions
|
@ -120,6 +120,8 @@ crate struct Options {
|
||||||
/// For example, using ignore-foo to ignore running the doctest on any target that
|
/// For example, using ignore-foo to ignore running the doctest on any target that
|
||||||
/// contains "foo" as a substring
|
/// contains "foo" as a substring
|
||||||
crate enable_per_target_ignores: bool,
|
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
|
/// The path to a rustc-like binary to build tests with. If not set, we
|
||||||
/// default to loading from `$sysroot/bin/rustc`.
|
/// default to loading from `$sysroot/bin/rustc`.
|
||||||
|
@ -197,6 +199,7 @@ impl fmt::Debug for Options {
|
||||||
.field("runtool_args", &self.runtool_args)
|
.field("runtool_args", &self.runtool_args)
|
||||||
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
|
.field("enable-per-target-ignores", &self.enable_per_target_ignores)
|
||||||
.field("run_check", &self.run_check)
|
.field("run_check", &self.run_check)
|
||||||
|
.field("no_run", &self.no_run)
|
||||||
.finish()
|
.finish()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,6 +469,12 @@ impl Options {
|
||||||
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
|
test_args.iter().flat_map(|s| s.split_whitespace()).map(|s| s.to_string()).collect();
|
||||||
|
|
||||||
let should_test = matches.opt_present("test");
|
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 =
|
let output =
|
||||||
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
|
matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc"));
|
||||||
|
@ -666,6 +675,7 @@ impl Options {
|
||||||
enable_per_target_ignores,
|
enable_per_target_ignores,
|
||||||
test_builder,
|
test_builder,
|
||||||
run_check,
|
run_check,
|
||||||
|
no_run,
|
||||||
render_options: RenderOptions {
|
render_options: RenderOptions {
|
||||||
output,
|
output,
|
||||||
external_html,
|
external_html,
|
||||||
|
|
|
@ -940,13 +940,14 @@ impl Tester for Collector {
|
||||||
let report_unused_externs = |uext| {
|
let report_unused_externs = |uext| {
|
||||||
unused_externs.lock().unwrap().push(uext);
|
unused_externs.lock().unwrap().push(uext);
|
||||||
};
|
};
|
||||||
|
let no_run = config.no_run || options.no_run;
|
||||||
let res = run_test(
|
let res = run_test(
|
||||||
&test,
|
&test,
|
||||||
&cratename,
|
&cratename,
|
||||||
line,
|
line,
|
||||||
options,
|
options,
|
||||||
config.should_panic,
|
config.should_panic,
|
||||||
config.no_run,
|
no_run,
|
||||||
config.test_harness,
|
config.test_harness,
|
||||||
runtool,
|
runtool,
|
||||||
runtool_args,
|
runtool_args,
|
||||||
|
|
|
@ -595,6 +595,7 @@ fn opts() -> Vec<RustcOptGroup> {
|
||||||
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
|
"[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]",
|
||||||
)
|
)
|
||||||
}),
|
}),
|
||||||
|
unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")),
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
src/test/rustdoc-ui/no-run-flag-error.rs
Normal file
6
src/test/rustdoc-ui/no-run-flag-error.rs
Normal 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() {}
|
2
src/test/rustdoc-ui/no-run-flag-error.stderr
Normal file
2
src/test/rustdoc-ui/no-run-flag-error.stderr
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
error: the `--test` flag must be passed to enable `--no-run`
|
||||||
|
|
38
src/test/rustdoc-ui/no-run-flag.rs
Normal file
38
src/test/rustdoc-ui/no-run-flag.rs
Normal 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() {}
|
12
src/test/rustdoc-ui/no-run-flag.stdout
Normal file
12
src/test/rustdoc-ui/no-run-flag.stdout
Normal 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
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue