diff options
| author | Herman J. Radtke III <hermanradtke@gmail.com> | 2013-05-24 13:37:39 -0700 |
|---|---|---|
| committer | Herman J. Radtke III <hermanradtke@gmail.com> | 2013-05-24 13:41:53 -0700 |
| commit | 264c84b892f531f968b1ab9c9b8e15f2c66cf524 (patch) | |
| tree | d06f7d55ecb668a2e7aad54833d723bf095f1af8 | |
| parent | b5ab1012f1f5786f550e511ba1302a22c85fcd71 (diff) | |
| download | rust-264c84b892f531f968b1ab9c9b8e15f2c66cf524.tar.gz rust-264c84b892f531f968b1ab9c9b8e15f2c66cf524.zip | |
Make rust {test, run} exit with appropriate code.
Scripts need to know if the tests pass or the program ran correctly.
| -rw-r--r-- | src/librust/rust.rc | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/librust/rust.rc b/src/librust/rust.rc index f1d92f1d957..6449958e09c 100644 --- a/src/librust/rust.rc +++ b/src/librust/rust.rc @@ -32,16 +32,17 @@ extern mod rustc; use core::prelude::*; use core::run; +use core::libc::exit; enum ValidUsage { - Valid, Invalid + Valid(int), Invalid } impl ValidUsage { fn is_valid(&self) -> bool { match *self { - Valid => true, - Invalid => false + Valid(_) => true, + Invalid => false } } } @@ -144,7 +145,7 @@ fn cmd_help(args: &[~str]) -> ValidUsage { UsgStr(msg) => io::println(fmt!("%s\n", msg)), UsgCall(f) => f(), } - Valid + Valid(0) }, None => Invalid } @@ -162,8 +163,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage { let test_exec = Path(filename).filestem().unwrap() + "test~"; invoke("rustc", &[~"--test", filename.to_owned(), ~"-o", test_exec.to_owned()], rustc::main); - run::run_program(~"./" + test_exec, []); - Valid + let exit_code = run::run_program(~"./" + test_exec, []); + Valid(exit_code) } _ => Invalid } @@ -175,8 +176,8 @@ fn cmd_run(args: &[~str]) -> ValidUsage { let exec = Path(filename).filestem().unwrap() + "~"; invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()], rustc::main); - run::run_program(~"./"+exec, prog_args); - Valid + let exit_code = run::run_program(~"./"+exec, prog_args); + Valid(exit_code) } _ => Invalid } @@ -194,7 +195,7 @@ fn do_command(command: &Command, args: &[~str]) -> ValidUsage { Call(f) => f(args), CallMain(prog, f) => { invoke(prog, args, f); - Valid + Valid(0) } } } @@ -233,7 +234,10 @@ pub fn main() { if !args.is_empty() { for find_cmd(*args.head()).each |command| { let result = do_command(command, args.tail()); - if result.is_valid() { return; } + match result { + Valid(exit_code) => unsafe { exit(exit_code.to_i32()) }, + _ => loop + } } } |
