show proper warning about not running doctests

This commit is contained in:
Ralf Jung 2020-09-11 15:05:05 +02:00
parent ba3b354af9
commit 2205ed5bbb
5 changed files with 24 additions and 6 deletions

View File

@ -442,6 +442,9 @@ fn phase_cargo_miri(mut args: env::Args) {
let runner_env_name = format!("CARGO_TARGET_{}_RUNNER", target.to_uppercase().replace('-', "_"));
cmd.env(runner_env_name, &miri_path);
// Set rustdoc to us as well, so we can make it do nothing (see issue #584).
cmd.env("RUSTDOC", &miri_path);
// Run cargo.
if verbose {
cmd.env("MIRI_VERBOSE", ""); // This makes the other phases verbose.
@ -571,7 +574,7 @@ fn phase_cargo_rustc(args: env::Args) {
}
}
fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
let verbose = std::env::var_os("MIRI_VERBOSE").is_some();
let file = File::open(&binary)
@ -659,10 +662,25 @@ fn main() {
// binary crates for later interpretation.
// - When we are executed due to CARGO_TARGET_RUNNER, we start interpretation based on the
// flags that were stored earlier.
// On top of that, we are also called as RUSTDOC, but that is just a stub currently.
match args.next().as_deref() {
Some("miri") => phase_cargo_miri(args),
Some("rustc") => phase_cargo_rustc(args),
Some(binary) => phase_cargo_runner(binary, args),
Some(arg) => {
// We have to distinguish the "runner" and "rustfmt" cases.
// As runner, the first argument is the binary (a file that should exist, with an absolute path);
// as rustfmt, the first argument is a flag (`--something`).
let binary = Path::new(arg);
if binary.exists() {
assert!(!arg.starts_with("--")); // not a flag
phase_cargo_runner(binary, args);
} else if arg.starts_with("--") {
// We are rustdoc.
eprintln!("Running doctests is not currently supported by Miri.")
} else {
show_error(format!("`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`", arg));
}
}
_ => show_error(format!("`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`")),
}
}

View File

@ -12,5 +12,4 @@ rand = { version = "0.7", features = ["small_rng"] }
num_cpus = "1.10.1"
[lib]
test = false
doctest = false # FIXME: doctests should be skipped automatically until we can run them...
test = false # test that this is respected (will show in the output)

View File

@ -78,11 +78,11 @@ def test_cargo_miri_test():
)
test("cargo miri test (test target)",
cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
"test.stdout.ref4", "test.stderr.ref"
"test.stdout.ref4", "test.stderr.ref2"
)
test("cargo miri test (bin target)",
cargo_miri("test") + ["--bin", "cargo-miri-test", "--", "--format=pretty"],
"test.stdout.ref5", "test.stderr.ref"
"test.stdout.ref5", "test.stderr.ref2"
)
os.chdir(os.path.dirname(os.path.realpath(__file__)))

View File

@ -0,0 +1 @@
Running doctests is not currently supported by Miri.

View File