Skip to content

Commit 76f5855

Browse files
committed
Auto merge of #1817 - hyd-dev:doctest, r=RalfJung
Skip doctests of `proc-macro` crates Fixes #1813. Verified that the newly added tests failed without the `cargo-miri` change and pass with normal `cargo test`.
2 parents 0f03a70 + d1de084 commit 76f5855

File tree

5 files changed

+17
-2
lines changed

5 files changed

+17
-2
lines changed

cargo-miri/bin.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -900,10 +900,17 @@ fn phase_rustdoc(fst_arg: &str, mut args: env::Args) {
900900
}
901901

902902
if crossmode {
903-
show_error(format!("cross-interpreting doc-tests is not currently supported by Miri."));
903+
show_error(format!("cross-interpreting doctests is not currently supported by Miri."));
904904
}
905905

906-
// For each doc-test, rustdoc starts two child processes: first the test is compiled,
906+
// Doctests of `proc-macro` crates (and their dependencies) are always built for the host,
907+
// so we are not able to run them in Miri.
908+
if ArgFlagValueIter::new("--crate-type").any(|crate_type| crate_type == "proc-macro") {
909+
eprintln!("Running doctests of `proc-macro` crates is not currently supported by Miri.");
910+
return;
911+
}
912+
913+
// For each doctest, rustdoc starts two child processes: first the test is compiled,
907914
// then the produced executable is invoked. We want to reroute both of these to cargo-miri,
908915
// such that the first time we'll enter phase_cargo_rustc, and phase_cargo_runner second.
909916
//

test-cargo-miri/run-test.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ def test_cargo_miri_test():
140140
"test.subcrate.stdout.ref", "test.stderr-proc-macro.ref",
141141
env={'MIRIFLAGS': "-Zmiri-disable-isolation"},
142142
)
143+
test("`cargo miri test` (subcrate, doctests)",
144+
cargo_miri("test") + ["-p", "subcrate", "--doc"],
145+
"test.stdout-empty.ref", "test.stderr-proc-macro-doctest.ref",
146+
)
143147

144148
os.chdir(os.path.dirname(os.path.realpath(__file__)))
145149
os.environ["RUST_TEST_NOCAPTURE"] = "0" # this affects test output, so make sure it is not set

test-cargo-miri/subcrate/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1+
#[cfg(doctest)]
2+
compile_error!("rustdoc should not touch me");
3+
14
#[cfg(test)]
25
compile_error!("Miri should not touch me");
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Running doctests of `proc-macro` crates is not currently supported by Miri.

test-cargo-miri/test.stdout-empty.ref

Whitespace-only changes.

0 commit comments

Comments
 (0)