Skip to content

Commit 6246f7e

Browse files
committed
Don't propagate __RUST_TEST_INVOKE to subprocess
When -Z panic_abort_tests is enabled, we use an environment variable to tell the subprocess which test to invoke. If that subprocess then invokes another Rust test binary, chaos ensues.
1 parent ecbc222 commit 6246f7e

File tree

3 files changed

+17
-4
lines changed

3 files changed

+17
-4
lines changed

Diff for: src/libtest/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -153,12 +153,13 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
153153
// If we're being run in SpawnedSecondary mode, run the test here. run_test
154154
// will then exit the process.
155155
if let Ok(name) = env::var(SECONDARY_TEST_INVOKER_VAR) {
156+
env::remove_var(SECONDARY_TEST_INVOKER_VAR);
156157
let test = tests
157158
.iter()
158159
.filter(|test| test.desc.name.as_slice() == name)
159160
.map(make_owned_test)
160161
.next()
161-
.expect("couldn't find a test with the provided name");
162+
.expect(&format!("couldn't find a test with the provided name '{}'", name));
162163
let TestDescAndFn { desc, testfn } = test;
163164
let testfn = match testfn {
164165
StaticTestFn(f) => f,

Diff for: src/test/ui/test-panic-abort.rs

+11
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#![cfg(test)]
1212

1313
use std::io::Write;
14+
use std::env;
1415

1516
#[test]
1617
fn it_works() {
@@ -35,3 +36,13 @@ fn it_fails() {
3536
fn it_exits() {
3637
std::process::exit(123);
3738
}
39+
40+
#[test]
41+
fn no_residual_environment() {
42+
for (key, _) in env::vars() {
43+
// Look for keys like __RUST_TEST_INVOKE.
44+
if key.contains("TEST_INVOKE") {
45+
panic!("shouldn't have '{}' in environment", key);
46+
}
47+
}
48+
}

Diff for: src/test/ui/test-panic-abort.run.stdout

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

2-
running 4 tests
2+
running 5 tests
33
test it_exits ... FAILED
44
test it_fails ... FAILED
55
test it_panics ... ok
66
test it_works ... ok
7+
test no_residual_environment ... ok
78

89
failures:
910

@@ -17,13 +18,13 @@ testing123
1718
testing321
1819
thread 'main' panicked at 'assertion failed: `(left == right)`
1920
left: `2`,
20-
right: `5`', $DIR/test-panic-abort.rs:31:5
21+
right: `5`', $DIR/test-panic-abort.rs:32:5
2122
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2223

2324

2425
failures:
2526
it_exits
2627
it_fails
2728

28-
test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
29+
test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
2930

0 commit comments

Comments
 (0)