File tree Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Expand file tree Collapse file tree 3 files changed +17
-4
lines changed Original file line number Diff line number Diff 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,
Original file line number Diff line number Diff line change 1111#![ cfg( test) ]
1212
1313use std:: io:: Write ;
14+ use std:: env;
1415
1516#[ test]
1617fn it_works ( ) {
@@ -35,3 +36,13 @@ fn it_fails() {
3536fn 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+ }
Original file line number Diff line number Diff line change 11
2- running 4 tests
2+ running 5 tests
33test it_exits ... FAILED
44test it_fails ... FAILED
55test it_panics ... ok
66test it_works ... ok
7+ test no_residual_environment ... ok
78
89failures:
910
@@ -17,13 +18,13 @@ testing123
1718testing321
1819thread '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
2122note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
2223
2324
2425failures:
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
You can’t perform that action at this time.
0 commit comments