Skip to content

Commit a026e8a

Browse files
authored
Rollup merge of rust-lang#47986 - Gilnaa:libtest_relaxed, r=Mark-Simulacrum
libtest: Replace panics with error messages This replaces explicit panics on failures in libtest with prints to stderr. Where "failures" == CLI argument parsing and such Before: ``` $ ./foo-stable --not-an-option thread 'main' panicked at '"Unrecognized option: \'not-an-option\'"', libtest/lib.rs:251:27 note: Run with `RUST_BACKTRACE=1` for a backtrace. ``` After: ``` $ ./foo-nightly --not-an-option error: Unrecognized option: 'not-an-option' ```
2 parents 0a3e07d + 61ff3ba commit a026e8a

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/libtest/lib.rs

+13-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ use std::sync::{Arc, Mutex};
7272
use std::thread;
7373
use std::time::{Instant, Duration};
7474
use std::borrow::Cow;
75+
use std::process;
7576

7677
const TEST_WARN_TIMEOUT_S: u64 = 60;
7778
const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode
@@ -266,19 +267,27 @@ impl Options {
266267
pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Options) {
267268
let mut opts = match parse_opts(args) {
268269
Some(Ok(o)) => o,
269-
Some(Err(msg)) => panic!("{:?}", msg),
270+
Some(Err(msg)) => {
271+
eprintln!("error: {}", msg);
272+
process::exit(101);
273+
},
270274
None => return,
271275
};
276+
272277
opts.options = options;
273278
if opts.list {
274279
if let Err(e) = list_tests_console(&opts, tests) {
275-
panic!("io error when listing tests: {:?}", e);
280+
eprintln!("error: io error when listing tests: {:?}", e);
281+
process::exit(101);
276282
}
277283
} else {
278284
match run_tests_console(&opts, tests) {
279285
Ok(true) => {}
280-
Ok(false) => std::process::exit(101),
281-
Err(e) => panic!("io error when running tests: {:?}", e),
286+
Ok(false) => process::exit(101),
287+
Err(e) => {
288+
eprintln!("error: io error when listing tests: {:?}", e);
289+
process::exit(101);
290+
},
282291
}
283292
}
284293
}

0 commit comments

Comments
 (0)