From db6a916804ff7402ba70ca635e5071ac3b1a8f13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Sun, 4 Apr 2021 16:53:59 +0200 Subject: [PATCH 01/10] added --no-run option --- src/librustdoc/config.rs | 5 +++++ src/librustdoc/doctest.rs | 4 ++-- src/librustdoc/lib.rs | 1 + 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 246e0ebbb2ba0..b70baff551102 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -121,6 +121,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, + /// Compile test but do not run them. + 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`. @@ -196,6 +198,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() } } @@ -622,6 +625,7 @@ impl Options { let document_hidden = matches.opt_present("document-hidden-items"); let run_check = matches.opt_present("check"); let generate_redirect_map = matches.opt_present("generate-redirect-map"); + let no_run = matches.opt_present("no-run"); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); @@ -658,6 +662,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 3d0ef02890224..eded40916b522 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -291,7 +291,7 @@ fn run_test( for debugging_option_str in &options.debugging_opts_strs { compiler.arg("-Z").arg(&debugging_option_str); } - if no_run && !compile_fail { + if (no_run || options.no_run) && !compile_fail { compiler.arg("--emit=metadata"); } compiler.arg("--target").arg(match target { @@ -361,7 +361,7 @@ fn run_test( } } - if no_run { + if no_run || options.no_run { return Ok(()); } diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index c6262f5873e3e..3a9651011239b 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -536,6 +536,7 @@ fn opts() -> Vec { "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]", ) }), + unstable("no-run", |o| o.optflag("", "no-run", "Compile, but don't run doc tests")), ] } From 0f3efe25b9c02c6b70cf68798ff0626023246c80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= <77335613+ABouttefeux@users.noreply.github.com> Date: Mon, 5 Apr 2021 17:53:45 +0200 Subject: [PATCH 02/10] Update src/librustdoc/lib.rs from suggestion Co-authored-by: Ivan Tham --- src/librustdoc/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 3a9651011239b..0b46399cf4ef9 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -536,7 +536,7 @@ fn opts() -> Vec { "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]", ) }), - unstable("no-run", |o| o.optflag("", "no-run", "Compile, but don't run doc tests")), + unstable("no-run", |o| o.optflag("", "no-run", "Compile doc tests without running it")), ] } From a6bf81bbf71de4af70a97ad6d4fdc974e1d0e0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Mon, 5 Apr 2021 17:59:57 +0200 Subject: [PATCH 03/10] suggestion from review move no run option in run_test call --- src/librustdoc/doctest.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index eded40916b522..6c776be58eb17 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -291,7 +291,7 @@ fn run_test( for debugging_option_str in &options.debugging_opts_strs { compiler.arg("-Z").arg(&debugging_option_str); } - if (no_run || options.no_run) && !compile_fail { + if no_run && !compile_fail { compiler.arg("--emit=metadata"); } compiler.arg("--target").arg(match target { @@ -361,7 +361,7 @@ fn run_test( } } - if no_run || options.no_run { + if no_run { return Ok(()); } @@ -852,7 +852,7 @@ impl Tester for Collector { line, options, config.should_panic, - config.no_run, + config.no_run || options.no_run, config.test_harness, runtool, runtool_args, From 72f534aae1c6cca58b97957d6c225885fcdb4d1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Mon, 5 Apr 2021 21:11:21 +0200 Subject: [PATCH 04/10] fix failing build --- src/librustdoc/doctest.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 6c776be58eb17..442e833d72031 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -846,13 +846,14 @@ impl Tester for Collector { test_type: testing::TestType::DocTest, }, testfn: testing::DynTestFn(box move || { + let option_no_run = options.no_run; let res = run_test( &test, &cratename, line, options, config.should_panic, - config.no_run || options.no_run, + config.no_run || option_no_run, config.test_harness, runtool, runtool_args, From 08c7f975263424cc1a56401c852689e84b239dfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Tue, 6 Apr 2021 17:51:25 +0200 Subject: [PATCH 05/10] correction based on review --- src/librustdoc/doctest.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/doctest.rs b/src/librustdoc/doctest.rs index 3443eae065601..9dde5471a2d31 100644 --- a/src/librustdoc/doctest.rs +++ b/src/librustdoc/doctest.rs @@ -940,14 +940,14 @@ impl Tester for Collector { let report_unused_externs = |uext| { unused_externs.lock().unwrap().push(uext); }; - let option_no_run = options.no_run; + let no_run = config.no_run || options.no_run; let res = run_test( &test, &cratename, line, options, config.should_panic, - config.no_run || option_no_run, + no_run, config.test_harness, runtool, runtool_args, From 3ad3597bd42c32f2b41f680ea331b06f10f5cecf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Wed, 7 Apr 2021 15:45:40 +0200 Subject: [PATCH 06/10] change based on reviews --- src/librustdoc/config.rs | 2 +- src/librustdoc/lib.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 339eb50ff13a0..60b42cbb3a01e 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -121,7 +121,7 @@ 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, - /// Compile test but do not run them. + /// 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 diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 0b46399cf4ef9..ac171dc12a853 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -536,7 +536,7 @@ fn opts() -> Vec { "[unversioned-shared-resources,toolchain-shared-resources,invocation-specific]", ) }), - unstable("no-run", |o| o.optflag("", "no-run", "Compile doc tests without running it")), + unstable("no-run", |o| o.optflag("", "no-run", "Compile doctests without running them")), ] } From 4770446e89627adbe98e380aa7377768bceb5366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Wed, 7 Apr 2021 17:19:11 +0200 Subject: [PATCH 07/10] add test --- src/test/rustdoc-ui/no-run-flag.rs | 38 ++++++++++++++++++++++++++ src/test/rustdoc-ui/no-run-flag.stdout | 12 ++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/test/rustdoc-ui/no-run-flag.rs create mode 100644 src/test/rustdoc-ui/no-run-flag.stdout 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 0000000000000..e5658a6645bc0 --- /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 +/// 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 0000000000000..d92f5da833567 --- /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 + From 202659a43d2bf9444e3d14f5917bf9cc90f72b16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Wed, 7 Apr 2021 20:48:12 +0200 Subject: [PATCH 08/10] fix failing tidy check --- src/test/rustdoc-ui/no-run-flag.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/rustdoc-ui/no-run-flag.rs b/src/test/rustdoc-ui/no-run-flag.rs index e5658a6645bc0..da1672c4a6e78 100644 --- a/src/test/rustdoc-ui/no-run-flag.rs +++ b/src/test/rustdoc-ui/no-run-flag.rs @@ -11,7 +11,7 @@ /// ```should_panic /// panic!() /// ``` -/// ```ignore +/// ```ignore (incomplete-code) /// fn foo() { /// ``` /// ```no_run From 3273d2f7199ed8e678c249ddbdbac78244968901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= Date: Fri, 30 Apr 2021 12:36:22 +0200 Subject: [PATCH 09/10] error when --no-run is present without --test --- src/librustdoc/config.rs | 7 ++++++- src/test/rustdoc-ui/no-run-flag-error.rs | 5 +++++ src/test/rustdoc-ui/no-run-flag-error.stderr | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 src/test/rustdoc-ui/no-run-flag-error.rs create mode 100644 src/test/rustdoc-ui/no-run-flag-error.stderr diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 60b42cbb3a01e..76aa785636d2e 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -459,6 +459,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.struct_err("option --no-run should be used with --test").emit(); + return Err(1); + } let output = matches.opt_str("o").map(|s| PathBuf::from(&s)).unwrap_or_else(|| PathBuf::from("doc")); @@ -629,7 +635,6 @@ impl Options { let document_hidden = matches.opt_present("document-hidden-items"); let run_check = matches.opt_present("check"); let generate_redirect_map = matches.opt_present("generate-redirect-map"); - let no_run = matches.opt_present("no-run"); let (lint_opts, describe_lints, lint_cap) = get_cmd_lint_options(matches, error_format); 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 0000000000000..a42b5a9d684bb --- /dev/null +++ b/src/test/rustdoc-ui/no-run-flag-error.rs @@ -0,0 +1,5 @@ +// test the behavior of the --no-run flag without the --test flag + +// compile-flags:-Z unstable-options --no-run --test-args=--test-threads=1 + +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 0000000000000..3d34be8a4205a --- /dev/null +++ b/src/test/rustdoc-ui/no-run-flag-error.stderr @@ -0,0 +1,2 @@ +error: option --no-run should be used with --test + From 03c710bf8923057ae2050f4300527ff922a2f081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=C3=A9nore=20Bouttefeux?= <77335613+ABouttefeux@users.noreply.github.com> Date: Sat, 1 May 2021 11:46:00 +0200 Subject: [PATCH 10/10] Apply suggestions from code review Co-authored-by: Joshua Nelson --- src/librustdoc/config.rs | 2 +- src/test/rustdoc-ui/no-run-flag-error.rs | 1 + src/test/rustdoc-ui/no-run-flag-error.stderr | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 76aa785636d2e..053529393d51e 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -462,7 +462,7 @@ impl Options { let no_run = matches.opt_present("no-run"); if !should_test && no_run { - diag.struct_err("option --no-run should be used with --test").emit(); + diag.err("the `--test` flag must be passed to enable `--no-run`"); return Err(1); } diff --git a/src/test/rustdoc-ui/no-run-flag-error.rs b/src/test/rustdoc-ui/no-run-flag-error.rs index a42b5a9d684bb..4ead621482bfd 100644 --- a/src/test/rustdoc-ui/no-run-flag-error.rs +++ b/src/test/rustdoc-ui/no-run-flag-error.rs @@ -1,5 +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 index 3d34be8a4205a..d032646c365c7 100644 --- a/src/test/rustdoc-ui/no-run-flag-error.stderr +++ b/src/test/rustdoc-ui/no-run-flag-error.stderr @@ -1,2 +1,2 @@ -error: option --no-run should be used with --test +error: the `--test` flag must be passed to enable `--no-run`