From f42a6d1026fc2350766be9a755d124ab49e28138 Mon Sep 17 00:00:00 2001 From: hyd-dev Date: Thu, 27 May 2021 06:40:47 +0800 Subject: [PATCH] Skip doctests of `proc-macro` crates --- cargo-miri/bin.rs | 7 +++++++ test-cargo-miri/run-test.py | 4 ++++ test-cargo-miri/subcrate/src/lib.rs | 3 +++ test-cargo-miri/test.stderr-proc-macro-doctest.ref | 1 + test-cargo-miri/test.stdout-empty.ref | 0 5 files changed, 15 insertions(+) create mode 100644 test-cargo-miri/test.stderr-proc-macro-doctest.ref create mode 100644 test-cargo-miri/test.stdout-empty.ref diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 295acd6638a..19d235cf67d 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -903,6 +903,13 @@ fn phase_rustdoc(fst_arg: &str, mut args: env::Args) { show_error(format!("cross-interpreting doc-tests is not currently supported by Miri.")); } + // Doc-tests of `proc-macro` crates (and their dependencies) are always built for the host, + // so we are not able to run them in Miri. + if ArgFlagValueIter::new("--crate-type").any(|crate_type| crate_type == "proc-macro") { + eprintln!("Running doc-tests of `proc-macro` crates is not currently supported by Miri."); + return; + } + // For each doc-test, rustdoc starts two child processes: first the test is compiled, // then the produced executable is invoked. We want to reroute both of these to cargo-miri, // such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second. diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 9185c2507b6..c850e7d1459 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -140,6 +140,10 @@ def test_cargo_miri_test(): "test.subcrate.stdout.ref", "test.stderr-proc-macro.ref", env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, ) + test("`cargo miri test` (subcrate, doctests)", + cargo_miri("test") + ["-p", "subcrate", "--doc"], + "test.stdout-empty.ref", "test.stderr-proc-macro-doctest.ref", + ) os.chdir(os.path.dirname(os.path.realpath(__file__))) os.environ["RUST_TEST_NOCAPTURE"] = "0" # this affects test output, so make sure it is not set diff --git a/test-cargo-miri/subcrate/src/lib.rs b/test-cargo-miri/subcrate/src/lib.rs index 706e368017c..07ed1acb7a0 100644 --- a/test-cargo-miri/subcrate/src/lib.rs +++ b/test-cargo-miri/subcrate/src/lib.rs @@ -1,2 +1,5 @@ +#[cfg(doctest)] +use num_cpus as _; + #[cfg(test)] compile_error!("Miri should not touch me"); diff --git a/test-cargo-miri/test.stderr-proc-macro-doctest.ref b/test-cargo-miri/test.stderr-proc-macro-doctest.ref new file mode 100644 index 00000000000..55d0f7cf54a --- /dev/null +++ b/test-cargo-miri/test.stderr-proc-macro-doctest.ref @@ -0,0 +1 @@ +Running doc-tests of `proc-macro` crates is not currently supported by Miri. diff --git a/test-cargo-miri/test.stdout-empty.ref b/test-cargo-miri/test.stdout-empty.ref new file mode 100644 index 00000000000..e69de29bb2d