Skip to content

Commit d930b2c

Browse files
committed
auto merge of #6730 : hjr3/rust/exit_code, r=z0w0
Scripts need to know if the tests pass or the program ran correctly.
2 parents 0628c92 + 264c84b commit d930b2c

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

src/librust/rust.rc

+14-10
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,17 @@ extern mod rustc;
3232
use core::prelude::*;
3333

3434
use core::run;
35+
use core::libc::exit;
3536

3637
enum ValidUsage {
37-
Valid, Invalid
38+
Valid(int), Invalid
3839
}
3940

4041
impl ValidUsage {
4142
fn is_valid(&self) -> bool {
4243
match *self {
43-
Valid => true,
44-
Invalid => false
44+
Valid(_) => true,
45+
Invalid => false
4546
}
4647
}
4748
}
@@ -144,7 +145,7 @@ fn cmd_help(args: &[~str]) -> ValidUsage {
144145
UsgStr(msg) => io::println(fmt!("%s\n", msg)),
145146
UsgCall(f) => f(),
146147
}
147-
Valid
148+
Valid(0)
148149
},
149150
None => Invalid
150151
}
@@ -162,8 +163,8 @@ fn cmd_test(args: &[~str]) -> ValidUsage {
162163
let test_exec = Path(filename).filestem().unwrap() + "test~";
163164
invoke("rustc", &[~"--test", filename.to_owned(),
164165
~"-o", test_exec.to_owned()], rustc::main);
165-
run::run_program(~"./" + test_exec, []);
166-
Valid
166+
let exit_code = run::run_program(~"./" + test_exec, []);
167+
Valid(exit_code)
167168
}
168169
_ => Invalid
169170
}
@@ -175,8 +176,8 @@ fn cmd_run(args: &[~str]) -> ValidUsage {
175176
let exec = Path(filename).filestem().unwrap() + "~";
176177
invoke("rustc", &[filename.to_owned(), ~"-o", exec.to_owned()],
177178
rustc::main);
178-
run::run_program(~"./"+exec, prog_args);
179-
Valid
179+
let exit_code = run::run_program(~"./"+exec, prog_args);
180+
Valid(exit_code)
180181
}
181182
_ => Invalid
182183
}
@@ -194,7 +195,7 @@ fn do_command(command: &Command, args: &[~str]) -> ValidUsage {
194195
Call(f) => f(args),
195196
CallMain(prog, f) => {
196197
invoke(prog, args, f);
197-
Valid
198+
Valid(0)
198199
}
199200
}
200201
}
@@ -233,7 +234,10 @@ pub fn main() {
233234
if !args.is_empty() {
234235
for find_cmd(*args.head()).each |command| {
235236
let result = do_command(command, args.tail());
236-
if result.is_valid() { return; }
237+
match result {
238+
Valid(exit_code) => unsafe { exit(exit_code.to_i32()) },
239+
_ => loop
240+
}
237241
}
238242
}
239243

0 commit comments

Comments
 (0)