Skip to content

Commit

Permalink
show proper warning about not running doctests
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Sep 11, 2020
1 parent 74db228 commit 8e6575a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
22 changes: 20 additions & 2 deletions cargo-miri/bin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,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.
Expand Down Expand Up @@ -568,7 +571,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)
Expand Down Expand Up @@ -656,10 +659,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.is_absolute() && 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`")),
}
}
3 changes: 1 addition & 2 deletions test-cargo-miri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 8e6575a

Please sign in to comment.