about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2013-09-24 16:34:23 -0700
committerBrian Anderson <banderson@mozilla.com>2013-09-24 16:34:23 -0700
commit6d03897376f8737e28a93693f90bd651e9d08e92 (patch)
treedbf0199323e50ab9c39d0349f9eeed74b0616593 /src/libextra
parent753547963340cb973210ad2df5590c29bf46ddf1 (diff)
Don't use libc::exit. #9473
This can cause unexpected errors in the runtime when done while
scheduler threads are still initializing. Required some restructuring
of the main_args functions in our libraries.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/test.rs23
1 files changed, 11 insertions, 12 deletions
diff --git a/src/libextra/test.rs b/src/libextra/test.rs
index 7400973c28a..4721a6b4122 100644
--- a/src/libextra/test.rs
+++ b/src/libextra/test.rs
@@ -30,7 +30,6 @@ use treemap::TreeMap;
 
 use std::clone::Clone;
 use std::comm::{stream, SharedChan, GenericPort, GenericChan};
-use std::libc;
 use std::io;
 use std::result;
 use std::task;
@@ -125,8 +124,9 @@ pub type MetricDiff = TreeMap<~str,MetricChange>;
 pub fn test_main(args: &[~str], tests: ~[TestDescAndFn]) {
     let opts =
         match parse_opts(args) {
-            Ok(o) => o,
-            Err(msg) => fail!(msg)
+            Some(Ok(o)) => o,
+            Some(Err(msg)) => fail!(msg),
+            None => return
         };
     if !run_tests_console(&opts, tests) { fail!("Some tests failed"); }
 }
@@ -189,7 +189,7 @@ fn optgroups() -> ~[getopts::groups::OptGroup] {
                      "A.B")]
 }
 
-fn usage(binary: &str, helpstr: &str) -> ! {
+fn usage(binary: &str, helpstr: &str) {
     #[fixed_stack_segment]; #[inline(never)];
 
     let message = fmt!("Usage: %s [OPTIONS] [FILTER]", binary);
@@ -217,20 +217,19 @@ Test Attributes:
                      tests. This may also be written as #[ignore(cfg(...))] to
                      ignore the test on certain configurations.");
     }
-    unsafe { libc::exit(0) }
 }
 
 // Parses command line arguments into test options
-pub fn parse_opts(args: &[~str]) -> OptRes {
+pub fn parse_opts(args: &[~str]) -> Option<OptRes> {
     let args_ = args.tail();
     let matches =
         match groups::getopts(args_, optgroups()) {
           Ok(m) => m,
-          Err(f) => return Err(f.to_err_msg())
+          Err(f) => return Some(Err(f.to_err_msg()))
         };
 
-    if matches.opt_present("h") { usage(args[0], "h"); }
-    if matches.opt_present("help") { usage(args[0], "help"); }
+    if matches.opt_present("h") { usage(args[0], "h"); return None; }
+    if matches.opt_present("help") { usage(args[0], "help"); return None; }
 
     let filter =
         if matches.free.len() > 0 {
@@ -272,7 +271,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
         logfile: logfile
     };
 
-    Ok(test_opts)
+    Some(Ok(test_opts))
 }
 
 pub fn opt_shard(maybestr: Option<~str>) -> Option<(uint,uint)> {
@@ -1228,7 +1227,7 @@ mod tests {
     fn first_free_arg_should_be_a_filter() {
         let args = ~[~"progname", ~"filter"];
         let opts = match parse_opts(args) {
-            Ok(o) => o,
+            Some(Ok(o)) => o,
             _ => fail!("Malformed arg in first_free_arg_should_be_a_filter")
         };
         assert!("filter" == opts.filter.clone().unwrap());
@@ -1238,7 +1237,7 @@ mod tests {
     fn parse_ignored_flag() {
         let args = ~[~"progname", ~"filter", ~"--ignored"];
         let opts = match parse_opts(args) {
-            Ok(o) => o,
+            Some(Ok(o)) => o,
             _ => fail!("Malformed arg in parse_ignored_flag")
         };
         assert!((opts.run_ignored));