Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't propagate __RUST_TEST_INVOKE to subprocess #68301

Merged
merged 1 commit into from
Jan 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/libtest/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ pub fn test_main_static_abort(tests: &[&TestDescAndFn]) {
// If we're being run in SpawnedSecondary mode, run the test here. run_test
// will then exit the process.
if let Ok(name) = env::var(SECONDARY_TEST_INVOKER_VAR) {
env::remove_var(SECONDARY_TEST_INVOKER_VAR);
let test = tests
.iter()
.filter(|test| test.desc.name.as_slice() == name)
.map(make_owned_test)
.next()
.expect("couldn't find a test with the provided name");
.expect(&format!("couldn't find a test with the provided name '{}'", name));
let TestDescAndFn { desc, testfn } = test;
let testfn = match testfn {
StaticTestFn(f) => f,
Expand Down
11 changes: 11 additions & 0 deletions src/test/ui/test-panic-abort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![cfg(test)]

use std::io::Write;
use std::env;

#[test]
fn it_works() {
Expand All @@ -35,3 +36,13 @@ fn it_fails() {
fn it_exits() {
std::process::exit(123);
}

#[test]
fn no_residual_environment() {
for (key, _) in env::vars() {
// Look for keys like __RUST_TEST_INVOKE.
if key.contains("TEST_INVOKE") {
panic!("shouldn't have '{}' in environment", key);
}
}
}
7 changes: 4 additions & 3 deletions src/test/ui/test-panic-abort.run.stdout
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

running 4 tests
running 5 tests
test it_exits ... FAILED
test it_fails ... FAILED
test it_panics ... ok
test it_works ... ok
test no_residual_environment ... ok

failures:

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


failures:
it_exits
it_fails

test result: FAILED. 2 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out
test result: FAILED. 3 passed; 2 failed; 0 ignored; 0 measured; 0 filtered out