diff --git a/cargo-miri/bin.rs b/cargo-miri/bin.rs index b9c46ff41cb5..b70d95c60402 100644 --- a/cargo-miri/bin.rs +++ b/cargo-miri/bin.rs @@ -38,7 +38,7 @@ enum MiriCommand { } /// The information to run a crate with the given environment. -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Deserialize)] struct CrateRunEnv { /// The command-line arguments. args: Vec, @@ -52,13 +52,13 @@ struct CrateRunEnv { impl CrateRunEnv { /// Gather all the information we need. - fn collect(args: env::Args) -> Self { + fn collect(args: env::Args, capture_stdin: bool) -> Self { let args = args.collect(); let env = env::vars_os().collect(); let current_dir = env::current_dir().unwrap().into_os_string(); let mut stdin = Vec::new(); - if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() { + if capture_stdin { std::io::stdin().lock().read_to_end(&mut stdin).expect("cannot read stdin"); } @@ -669,17 +669,18 @@ fn phase_cargo_rustc(mut args: env::Args) { let runnable_crate = !print && is_runnable_crate(); if runnable_crate && target_crate { + let inside_rustdoc = env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some(); // This is the binary or test crate that we want to interpret under Miri. // But we cannot run it here, as cargo invoked us as a compiler -- our stdin and stdout are not // like we want them. // Instead of compiling, we write JSON into the output file with all the relevant command-line flags // and environment variables; this is used when cargo calls us again in the CARGO_TARGET_RUNNER phase. - let env = CrateRunEnv::collect(args); + let env = CrateRunEnv::collect(args, inside_rustdoc); // Rustdoc expects us to exit with an error code if the test is marked as `compile_fail`, // just creating the JSON file is not enough: we need to detect syntax errors, // so we need to run Miri with `MIRI_BE_RUSTC` for a check-only build. - if std::env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() { + if inside_rustdoc { let mut cmd = miri(); // Ensure --emit argument for a check-only build is present. diff --git a/test-cargo-miri/run-test.py b/test-cargo-miri/run-test.py index 84c4a129ad3e..9185c2507b6f 100755 --- a/test-cargo-miri/run-test.py +++ b/test-cargo-miri/run-test.py @@ -143,6 +143,7 @@ def test_cargo_miri_test(): 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 +os.environ["RUST_TEST_THREADS"] = "1" # avoid non-deterministic output due to concurrent test runs target_str = " for target {}".format(os.environ['MIRI_TEST_TARGET']) if 'MIRI_TEST_TARGET' in os.environ else "" print(CGREEN + CBOLD + "## Running `cargo miri` tests{}".format(target_str) + CEND) diff --git a/test-cargo-miri/test.default.stdout.ref b/test-cargo-miri/test.default.stdout.ref index 72ae7e94a146..6e35c374e192 100644 --- a/test-cargo-miri/test.default.stdout.ref +++ b/test-cargo-miri/test.default.stdout.ref @@ -10,9 +10,9 @@ test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out running 3 tests +test src/lib.rs - make_true (line 2) ... ok test src/lib.rs - make_true (line 5) ... ok test src/lib.rs - make_true (line 8) ... ok -test src/lib.rs - make_true (line 2) ... ok test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME