Skip to content

Commit 2f6dff6

Browse files
committed
nits and fix non-deterministic test output
1 parent f9bd6b0 commit 2f6dff6

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

cargo-miri/bin.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ enum MiriCommand {
3838
}
3939

4040
/// The information to run a crate with the given environment.
41-
#[derive(Serialize, Deserialize, Clone)]
41+
#[derive(Serialize, Deserialize)]
4242
struct CrateRunEnv {
4343
/// The command-line arguments.
4444
args: Vec<String>,
@@ -52,13 +52,13 @@ struct CrateRunEnv {
5252

5353
impl CrateRunEnv {
5454
/// Gather all the information we need.
55-
fn collect(args: env::Args) -> Self {
55+
fn collect(args: env::Args, capture_stdin: bool) -> Self {
5656
let args = args.collect();
5757
let env = env::vars_os().collect();
5858
let current_dir = env::current_dir().unwrap().into_os_string();
5959

6060
let mut stdin = Vec::new();
61-
if env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
61+
if capture_stdin {
6262
std::io::stdin().lock().read_to_end(&mut stdin).expect("cannot read stdin");
6363
}
6464

@@ -669,17 +669,18 @@ fn phase_cargo_rustc(mut args: env::Args) {
669669
let runnable_crate = !print && is_runnable_crate();
670670

671671
if runnable_crate && target_crate {
672+
let inside_rustdoc = env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some();
672673
// This is the binary or test crate that we want to interpret under Miri.
673674
// But we cannot run it here, as cargo invoked us as a compiler -- our stdin and stdout are not
674675
// like we want them.
675676
// Instead of compiling, we write JSON into the output file with all the relevant command-line flags
676677
// and environment variables; this is used when cargo calls us again in the CARGO_TARGET_RUNNER phase.
677-
let env = CrateRunEnv::collect(args);
678+
let env = CrateRunEnv::collect(args, inside_rustdoc);
678679

679680
// Rustdoc expects us to exit with an error code if the test is marked as `compile_fail`,
680681
// just creating the JSON file is not enough: we need to detect syntax errors,
681682
// so we need to run Miri with `MIRI_BE_RUSTC` for a check-only build.
682-
if std::env::var_os("MIRI_CALLED_FROM_RUSTDOC").is_some() {
683+
if inside_rustdoc {
683684
let mut cmd = miri();
684685

685686
// Ensure --emit argument for a check-only build is present.

test-cargo-miri/run-test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ def test_cargo_miri_test():
143143

144144
os.chdir(os.path.dirname(os.path.realpath(__file__)))
145145
os.environ["RUST_TEST_NOCAPTURE"] = "0" # this affects test output, so make sure it is not set
146+
os.environ["RUST_TEST_THREADS"] = "1" # avoid non-deterministic output due to concurrent test runs
146147

147148
target_str = " for target {}".format(os.environ['MIRI_TEST_TARGET']) if 'MIRI_TEST_TARGET' in os.environ else ""
148149
print(CGREEN + CBOLD + "## Running `cargo miri` tests{}".format(target_str) + CEND)

test-cargo-miri/test.default.stdout.ref

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ test result: ok. 6 passed; 0 failed; 1 ignored; 0 measured; 0 filtered out
1010

1111

1212
running 3 tests
13+
test src/lib.rs - make_true (line 2) ... ok
1314
test src/lib.rs - make_true (line 5) ... ok
1415
test src/lib.rs - make_true (line 8) ... ok
15-
test src/lib.rs - make_true (line 2) ... ok
1616

1717
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in $TIME
1818

0 commit comments

Comments
 (0)