From 39c5e06526b5af23ce471df8a99b9b6ad3db815d Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Fri, 13 Apr 2012 18:34:45 +0800 Subject: [PATCH] Revert "libstd: Handle test results in serial" This reverts commit 828d0677c4d6d9cc955f9b90e8b28039f69ff8b8. --- src/libstd/test.rs | 77 ++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 44 deletions(-) diff --git a/src/libstd/test.rs b/src/libstd/test.rs index d0814c01f37..ad3ab9fef79 100644 --- a/src/libstd/test.rs +++ b/src/libstd/test.rs @@ -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::(); - 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) { @@ -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; @@ -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, @@ -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) { + 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. @@ -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; @@ -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.