Skip to content

Commit

Permalink
Revert "libstd: Handle test results in serial"
Browse files Browse the repository at this point in the history
This reverts commit 828d067.
  • Loading branch information
lht committed Apr 13, 2012
1 parent 2955ecd commit 39c5e06
Showing 1 changed file with 33 additions and 44 deletions.
77 changes: 33 additions & 44 deletions src/libstd/test.rs
Expand Up @@ -102,44 +102,13 @@ type console_test_state =
fn run_tests_console(opts: test_opts,
tests: [test_desc]) -> bool {

let log_out = alt opts.logfile {
some(path) {
alt io::file_writer(path, [io::create, io::truncate]) {
result::ok(w) { some(w) }
result::err(s) {
fail(#fmt("can't open output file: %s", s))
}
}
}
none { none }
};

let st =
@{out: io::stdout(),
log_out: log_out,
use_color: use_color(),
mut total: 0u,
mut passed: 0u,
mut failed: 0u,
mut ignored: 0u,
mut failures: []};

let p = comm::port::<testevent>();
let reporter = comm::chan(p);

task::spawn {||
run_tests(opts, tests, reporter);
};

while true {
alt comm::recv(p) {
fn callback(event: testevent, st: console_test_state) {
alt event {
te_filtered(filtered_tests) {
st.total = vec::len(filtered_tests);
st.out.write_line(#fmt["\nrunning %u tests", st.total]);
}
te_wait(test) {
st.out.write_str(#fmt["test %s ... ", test.name]);
}
te_wait(test) { st.out.write_str(#fmt["test %s ... ", test.name]); }
te_result(test, result) {
alt st.log_out {
some(f) {
Expand All @@ -166,12 +135,33 @@ fn run_tests_console(opts: test_opts,
}
}
}
te_done {
break;
}
}
}

let log_out = alt opts.logfile {
some(path) {
alt io::file_writer(path, [io::create, io::truncate]) {
result::ok(w) { some(w) }
result::err(s) {
fail(#fmt("can't open output file: %s", s))
}
}
}
none { none }
};

let st =
@{out: io::stdout(),
log_out: log_out,
use_color: use_color(),
mut total: 0u,
mut passed: 0u,
mut failed: 0u,
mut ignored: 0u,
mut failures: []};

run_tests(opts, tests, bind callback(_, st));

assert (st.passed + st.failed + st.ignored == st.total);
let success = st.failed == 0u;

Expand All @@ -181,6 +171,7 @@ fn run_tests_console(opts: test_opts,

st.out.write_str(#fmt["\nresult: "]);
if success {
// There's no parallelism at this point so it's safe to use color
write_ok(st.out, true);
} else { write_failed(st.out, true); }
st.out.write_str(#fmt[". %u passed; %u failed; %u ignored\n\n", st.passed,
Expand Down Expand Up @@ -273,16 +264,15 @@ enum testevent {
te_filtered([test_desc]),
te_wait(test_desc),
te_result(test_desc, test_result),
te_done,
}

type monitor_msg = (test_desc, test_result);

fn run_tests(opts: test_opts, tests: [test_desc],
reporter: comm::chan<testevent>) {
callback: fn@(testevent)) {

let mut filtered_tests = filter_tests(opts, tests);
comm::send(reporter, te_filtered(filtered_tests));
callback(te_filtered(filtered_tests));

// It's tempting to just spawn all the tests at once, but since we have
// many tests that run in other processes we would be making a big mess.
Expand All @@ -304,7 +294,7 @@ fn run_tests(opts: test_opts, tests: [test_desc],
// We are doing one test at a time so we can print the name
// of the test before we run it. Useful for debugging tests
// that hang forever.
comm::send(reporter, te_wait(test));
callback(te_wait(test));
}
run_test(test, ch);
wait_idx += 1u;
Expand All @@ -313,13 +303,12 @@ fn run_tests(opts: test_opts, tests: [test_desc],

let (test, result) = comm::recv(p);
if concurrency != 1u {
comm::send(reporter, te_wait(test));
callback(te_wait(test));
}
comm::send(reporter, te_result(test, result));
callback(te_result(test, result));
wait_idx -= 1u;
done_idx += 1u;
}
comm::send(reporter, te_done);
}

// Windows tends to dislike being overloaded with threads.
Expand Down

0 comments on commit 39c5e06

Please sign in to comment.