From 2205ed5bbb2fb8fb6c3b6a619815513f9d4c8038 Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Fri, 11 Sep 2020 15:05:05 +0200 Subject: [PATCH] show proper warning about not running doctests --- cargo-miri/bin.rs | 22 ++++++++++++++++++++-- test-cargo-miri/Cargo.toml | 3 +-- test-cargo-miri/run-test.py | 4 ++-- test-cargo-miri/test.stderr.ref | 1 + test-cargo-miri/test.stderr.ref2 | 0 5 files changed, 24 insertions(+), 6 deletions(-) create mode 100644 test-cargo-miri/test.stderr.ref2 diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index 70f8888676f..6dbaa9791df 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -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`")), } } diff --git a/test-cargo-miri/Cargo.toml b/test-cargo-miri/Cargo.toml index 68970d7d166..6bc11ef0cc5 100644 --- a/test-cargo-miri/Cargo.toml +++ b/test-cargo-miri/Cargo.toml @@ -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) diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 877a2a57061..82b3b88a633 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -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__))) diff --git a/test-cargo-miri/test.stderr.ref b/test-cargo-miri/test.stderr.ref index e69de29bb2d..a310169e305 100644 --- a/test-cargo-miri/test.stderr.ref +++ b/test-cargo-miri/test.stderr.ref @@ -0,0 +1 @@ +Running doctests is not currently supported by Miri. diff --git a/test-cargo-miri/test.stderr.ref2 b/test-cargo-miri/test.stderr.ref2 new file mode 100644 index 00000000000..e69de29bb2d