diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 480dd63859..39f8dcf17e 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -882,26 +882,34 @@ fn phase_cargo_rustdoc(fst_arg: &str, mut args: env::Args) { // Because of the way the main function is structured, we have to take the first argument spearately // from the rest; to simplify the following argument patching loop, we'll just skip that one. - // This is fine for now, because cargo will never pass the relevant arguments in the first position, + // This is fine for now, because cargo will never pass --extern arguments in the first position, // but we should defensively assert that this will work. let extern_flag = "--extern"; - let runtool_flag = "--runtool"; assert!(fst_arg != extern_flag); - assert!(fst_arg != runtool_flag); cmd.arg(fst_arg); - + + let runtool_flag = "--runtool"; + let mut crossmode = fst_arg == runtool_flag; while let Some(arg) = args.next() { if arg == extern_flag { // Patch --extern arguments to use *.rmeta files, since phase_cargo_rustc only creates stub *.rlib files. forward_patched_extern_arg(&mut args, &mut cmd); } else if arg == runtool_flag { - // Do not forward an existing --runtool argument, since we will set this ourselves - let _ = args.next().expect("`--runtool` should be followed by an executable name"); + // An existing --runtool flag indicates cargo is running in cross-target mode, which we don't support. + // Note that this is only passed when cargo is run with the unstable -Zdoctest-xcompile flag; + // otherwise, we won't be called as rustdoc at all. + crossmode = true; + break; } else { cmd.arg(arg); } } + if crossmode { + eprintln!("Cross-interpreting doc-tests 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 d32afa6a8a..df0b736028 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -16,13 +16,13 @@ def fail(msg): sys.exit(1) def cargo_miri(cmd): - args = ["cargo", "+nightly", "miri", cmd, "-q"] + args = ["cargo", "miri", cmd, "-q"] if 'MIRI_TEST_TARGET' in os.environ: - args += ["-Zdoctest-xcompile"] args += ["--target", os.environ['MIRI_TEST_TARGET']] return args def normalize_stdout(str): + str = str.replace("src\\", "src/") # normalize paths across platforms return re.sub("finished in \d+\.\d\ds", "finished in $TIME", str) def test(name, cmd, stdout_ref, stderr_ref, stdin=b'', env={}): @@ -73,24 +73,29 @@ def test_cargo_miri_run(): ) def test_cargo_miri_test(): + # rustdoc is not run on foreign targets + is_foreign = 'MIRI_TEST_TARGET' in os.environ + default_ref = "test.cross-target.stdout.ref" if is_foreign else "test.default.stdout.ref" + filter_ref = "test.filter.cross-target.stdout.ref" if is_foreign else "test.filter.stdout.ref" + test("`cargo miri test`", cargo_miri("test"), - "test.default.stdout.ref", "test.stderr-empty.ref", + default_ref, "test.stderr-empty.ref", env={'MIRIFLAGS': "-Zmiri-seed=feed"}, ) test("`cargo miri test` (no isolation)", cargo_miri("test"), - "test.default.stdout.ref", "test.stderr-empty.ref", + default_ref, "test.stderr-empty.ref", env={'MIRIFLAGS': "-Zmiri-disable-isolation"}, ) test("`cargo miri test` (raw-ptr tracking)", cargo_miri("test"), - "test.default.stdout.ref", "test.stderr-empty.ref", + default_ref, "test.stderr-empty.ref", env={'MIRIFLAGS': "-Zmiri-track-raw-pointers"}, ) test("`cargo miri test` (with filter)", cargo_miri("test") + ["--", "--format=pretty", "le1"], - "test.filter.stdout.ref", "test.stderr-empty.ref", + filter_ref, "test.stderr-empty.ref", ) test("`cargo miri test` (test target)", cargo_miri("test") + ["--test", "test", "--", "--format=pretty"], diff --git a/test-cargo-miri/test.cross-target.stdout.ref b/test-cargo-miri/test.cross-target.stdout.ref new file mode 100644 index 0000000000..7079798e42 --- /dev/null +++ b/test-cargo-miri/test.cross-target.stdout.ref @@ -0,0 +1,10 @@ + +running 1 test +. +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out + + +running 7 tests +..i.... +test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out + diff --git a/test-cargo-miri/test.filter.cross-target.stdout.ref b/test-cargo-miri/test.filter.cross-target.stdout.ref new file mode 100644 index 0000000000..37efb8c3ee --- /dev/null +++ b/test-cargo-miri/test.filter.cross-target.stdout.ref @@ -0,0 +1,11 @@ + +running 0 tests + +test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 1 filtered out + + +running 1 test +test simple1 ... ok + +test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 6 filtered out +