about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-05-01 15:36:23 +0000
committerbors <bors@rust-lang.org>2021-05-01 15:36:23 +0000
commit5f304a5d7908d9dd55dda3baadd3cf564d907369 (patch)
tree12ab8af58bb825bf6ab44246a1d1ab063a449dcc /src
parent603a42ec5458c547b51173cfa48c23ad37b03c3f (diff)
parent03c710bf8923057ae2050f4300527ff922a2f081 (diff)
downloadrust-5f304a5d7908d9dd55dda3baadd3cf564d907369.tar.gz
rust-5f304a5d7908d9dd55dda3baadd3cf564d907369.zip
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`.
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/config.rs10
-rw-r--r--src/librustdoc/doctest.rs3
-rw-r--r--src/librustdoc/lib.rs1
-rw-r--r--src/test/rustdoc-ui/no-run-flag-error.rs6
-rw-r--r--src/test/rustdoc-ui/no-run-flag-error.stderr2
-rw-r--r--src/test/rustdoc-ui/no-run-flag.rs38
-rw-r--r--src/test/rustdoc-ui/no-run-flag.stdout12
7 files changed, 71 insertions, 1 deletions
diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs
index 8f10ab2d3ac..48eb14ed291 100644
--- a/src/librustdoc/config.rs
+++ b/src/librustdoc/config.rs
@@ -120,6 +120,8 @@ crate struct Options {
     /// 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 @@ impl fmt::Debug for Options {
             .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 @@ impl Options {
             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 @@ impl Options {
             enable_per_target_ignores,
             test_builder,
             run_check,
+            no_run,
             render_options: RenderOptions {
                 output,
                 external_html,
diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs
index 466d1b65406..c0157121e19 100644
--- a/src/librustdoc/doctest.rs
+++ b/src/librustdoc/doctest.rs
@@ -940,13 +940,14 @@ impl Tester for Collector {
                 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,
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index 985aeedabb1..2a25b595625 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -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")),
     ]
 }
 
diff --git a/src/test/rustdoc-ui/no-run-flag-error.rs b/src/test/rustdoc-ui/no-run-flag-error.rs
new file mode 100644
index 00000000000..4ead621482b
--- /dev/null
+++ b/src/test/rustdoc-ui/no-run-flag-error.rs
@@ -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() {}
diff --git a/src/test/rustdoc-ui/no-run-flag-error.stderr b/src/test/rustdoc-ui/no-run-flag-error.stderr
new file mode 100644
index 00000000000..d032646c365
--- /dev/null
+++ b/src/test/rustdoc-ui/no-run-flag-error.stderr
@@ -0,0 +1,2 @@
+error: the `--test` flag must be passed to enable `--no-run`
+
diff --git a/src/test/rustdoc-ui/no-run-flag.rs b/src/test/rustdoc-ui/no-run-flag.rs
new file mode 100644
index 00000000000..da1672c4a6e
--- /dev/null
+++ b/src/test/rustdoc-ui/no-run-flag.rs
@@ -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() {}
diff --git a/src/test/rustdoc-ui/no-run-flag.stdout b/src/test/rustdoc-ui/no-run-flag.stdout
new file mode 100644
index 00000000000..d92f5da8335
--- /dev/null
+++ b/src/test/rustdoc-ui/no-run-flag.stdout
@@ -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
+