Skip to content

Commit 907de3a

Browse files
committed
show proper warning about not running doctests
1 parent 74db228 commit 907de3a

File tree

5 files changed

+24
-6
lines changed

5 files changed

+24
-6
lines changed

cargo-miri/bin.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,9 @@ fn phase_cargo_miri(mut args: env::Args) {
439439
let runner_env_name = format!("CARGO_TARGET_{}_RUNNER", target.to_uppercase().replace('-', "_"));
440440
cmd.env(runner_env_name, &miri_path);
441441

442+
// Set rustdoc to us as well, so we can make it do nothing (see issue #584).
443+
cmd.env("RUSTDOC", &miri_path);
444+
442445
// Run cargo.
443446
if verbose {
444447
cmd.env("MIRI_VERBOSE", ""); // This makes the other phases verbose.
@@ -568,7 +571,7 @@ fn phase_cargo_rustc(args: env::Args) {
568571
}
569572
}
570573

571-
fn phase_cargo_runner(binary: &str, binary_args: env::Args) {
574+
fn phase_cargo_runner(binary: &Path, binary_args: env::Args) {
572575
let verbose = std::env::var_os("MIRI_VERBOSE").is_some();
573576

574577
let file = File::open(&binary)
@@ -656,10 +659,25 @@ fn main() {
656659
// binary crates for later interpretation.
657660
// - When we are executed due to CARGO_TARGET_RUNNER, we start interpretation based on the
658661
// flags that were stored earlier.
662+
// On top of that, we are also called as RUSTDOC, but that is just a stub currently.
659663
match args.next().as_deref() {
660664
Some("miri") => phase_cargo_miri(args),
661665
Some("rustc") => phase_cargo_rustc(args),
662-
Some(binary) => phase_cargo_runner(binary, args),
666+
Some(arg) => {
667+
// We have to distinguish the "runner" and "rustfmt" cases.
668+
// As runner, the first argument is the binary (a file that should exist, with an absolute path);
669+
// as rustfmt, the first argument is a flag (`--something`).
670+
let binary = Path::new(arg);
671+
if binary.exists() {
672+
assert!(!arg.starts_with("--")); // not a flag
673+
phase_cargo_runner(binary, args);
674+
} else if arg.starts_with("--") {
675+
// We are rustdoc.
676+
eprintln!("Running doctests is not currently supported by Miri.")
677+
} else {
678+
show_error(format!("`cargo-miri` called with unexpected first argument `{}`; please only invoke this binary through `cargo miri`", arg));
679+
}
680+
}
663681
_ => show_error(format!("`cargo-miri` called without first argument; please only invoke this binary through `cargo miri`")),
664682
}
665683
}

test-cargo-miri/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,4 @@ rand = { version = "0.7", features = ["small_rng"] }
1212
num_cpus = "1.10.1"
1313

1414
[lib]
15-
test = false
16-
doctest = false # FIXME: doctests should be skipped automatically until we can run them...
15+
test = false # test that this is respected (will show in the output)

test-cargo-miri/run-test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ def test_cargo_miri_test():
7878
)
7979
test("cargo miri test (test target)",
8080
cargo_miri("test") + ["--test", "test", "--", "--format=pretty"],
81-
"test.stdout.ref4", "test.stderr.ref"
81+
"test.stdout.ref4", "test.stderr.ref2"
8282
)
8383
test("cargo miri test (bin target)",
8484
cargo_miri("test") + ["--bin", "cargo-miri-test", "--", "--format=pretty"],
85-
"test.stdout.ref5", "test.stderr.ref"
85+
"test.stdout.ref5", "test.stderr.ref2"
8686
)
8787

8888
os.chdir(os.path.dirname(os.path.realpath(__file__)))

test-cargo-miri/test.stderr.ref

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Running doctests is not currently supported by Miri.

test-cargo-miri/test.stderr.ref2

Whitespace-only changes.

0 commit comments

Comments
 (0)