]> git.lizzy.rs Git - rust.git/commitdiff
libtest: Replace panics with error messages
authorGilad Naaman <gilad.naaman@gmail.com>
Sat, 27 Jan 2018 20:34:05 +0000 (22:34 +0200)
committerGilad Naaman <gilad.naaman@gmail.com>
Sun, 4 Feb 2018 04:10:54 +0000 (06:10 +0200)
src/libtest/lib.rs

index ffa27688cf1a70d4ac71face0478209e5736bb82..9ea5f39b71feecca2ae04b27164c8c1bc2cbb6b3 100644 (file)
@@ -72,6 +72,7 @@
 use std::thread;
 use std::time::{Instant, Duration};
 use std::borrow::Cow;
+use std::process;
 
 const TEST_WARN_TIMEOUT_S: u64 = 60;
 const QUIET_MODE_MAX_COLUMN: usize = 100; // insert a '\n' after 100 tests in quiet mode
@@ -266,19 +267,27 @@ pub fn display_output(mut self, display_output: bool) -> Options {
 pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Options) {
     let mut opts = match parse_opts(args) {
         Some(Ok(o)) => o,
-        Some(Err(msg)) => panic!("{:?}", msg),
+        Some(Err(msg)) => {
+            eprintln!("error: {}", msg);
+            process::exit(101);
+        },
         None => return,
     };
+
     opts.options = options;
     if opts.list {
         if let Err(e) = list_tests_console(&opts, tests) {
-            panic!("io error when listing tests: {:?}", e);
+            eprintln!("error: io error when listing tests: {:?}", e);
+            process::exit(101);
         }
     } else {
         match run_tests_console(&opts, tests) {
             Ok(true) => {}
-            Ok(false) => std::process::exit(101),
-            Err(e) => panic!("io error when running tests: {:?}", e),
+            Ok(false) => process::exit(101),
+            Err(e) => {
+                eprintln!("error: io error when listing tests: {:?}", e);
+                process::exit(101);
+            },
         }
     }
 }