Skip to content

Commit

Permalink
Auto merge of #1817 - hyd-dev:doctest, r=RalfJung
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
bors committed May 27, 2021
2 parents 0f03a70 + d1de084 commit 76f5855
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,17 @@ fn phase_rustdoc(fst_arg: &str, mut args: env::Args) {
}

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

// For each doc-test, rustdoc starts two child processes: first the test is compiled,
// Doctests 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 doctests of `proc-macro` crates is not currently supported by Miri.");
return;
}

// For each doctest, 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.
//
Expand Down
4 changes: 4 additions & 0 deletions test-cargo-miri/run-test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions test-cargo-miri/subcrate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#[cfg(doctest)]
compile_error!("rustdoc should not touch me");

#[cfg(test)]
compile_error!("Miri should not touch me");
1 change: 1 addition & 0 deletions test-cargo-miri/test.stderr-proc-macro-doctest.ref
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Running doctests of `proc-macro` crates is not currently supported by Miri.
Empty file.

0 comments on commit 76f5855

Please sign in to comment.