Revert "libstd: Colorify test results when run in parallel"

This reverts commit 7b3cb05311.
This commit is contained in:
Haitao Li
2012-04-13 18:34:41 +08:00
parent 1adc26d5e7
commit 2955ecd13c

View File

@@ -91,6 +91,7 @@ enum test_result { tr_ok, tr_failed, tr_ignored, }
type console_test_state = type console_test_state =
@{out: io::writer, @{out: io::writer,
log_out: option<io::writer>, log_out: option<io::writer>,
use_color: bool,
mut total: uint, mut total: uint,
mut passed: uint, mut passed: uint,
mut failed: uint, mut failed: uint,
@@ -116,6 +117,7 @@ fn run_tests_console(opts: test_opts,
let st = let st =
@{out: io::stdout(), @{out: io::stdout(),
log_out: log_out, log_out: log_out,
use_color: use_color(),
mut total: 0u, mut total: 0u,
mut passed: 0u, mut passed: 0u,
mut failed: 0u, mut failed: 0u,
@@ -148,18 +150,18 @@ fn run_tests_console(opts: test_opts,
alt result { alt result {
tr_ok { tr_ok {
st.passed += 1u; st.passed += 1u;
write_ok(st.out); write_ok(st.out, st.use_color);
st.out.write_line(""); st.out.write_line("");
} }
tr_failed { tr_failed {
st.failed += 1u; st.failed += 1u;
write_failed(st.out); write_failed(st.out, st.use_color);
st.out.write_line(""); st.out.write_line("");
st.failures += [test]; st.failures += [test];
} }
tr_ignored { tr_ignored {
st.ignored += 1u; st.ignored += 1u;
write_ignored(st.out); write_ignored(st.out, st.use_color);
st.out.write_line(""); st.out.write_line("");
} }
} }
@@ -178,9 +180,11 @@ fn run_tests_console(opts: test_opts,
} }
st.out.write_str(#fmt["\nresult: "]); st.out.write_str(#fmt["\nresult: "]);
if success { write_ok(st.out); } else { write_failed(st.out); } if success {
st.out.write_str(#fmt[". %u passed; %u failed; %u ignored\n\n", write_ok(st.out, true);
st.passed, st.failed, st.ignored]); } else { write_failed(st.out, true); }
st.out.write_str(#fmt[". %u passed; %u failed; %u ignored\n\n", st.passed,
st.failed, st.ignored]);
ret success; ret success;
@@ -193,24 +197,24 @@ fn run_tests_console(opts: test_opts,
}, test.name)); }, test.name));
} }
fn write_ok(out: io::writer) { fn write_ok(out: io::writer, use_color: bool) {
write_pretty(out, "ok", term::color_green); write_pretty(out, "ok", term::color_green, use_color);
} }
fn write_failed(out: io::writer) { fn write_failed(out: io::writer, use_color: bool) {
write_pretty(out, "FAILED", term::color_red); write_pretty(out, "FAILED", term::color_red, use_color);
} }
fn write_ignored(out: io::writer) { fn write_ignored(out: io::writer, use_color: bool) {
write_pretty(out, "ignored", term::color_yellow); write_pretty(out, "ignored", term::color_yellow, use_color);
} }
fn write_pretty(out: io::writer, word: str, color: u8) { fn write_pretty(out: io::writer, word: str, color: u8, use_color: bool) {
if term::color_supported() { if use_color && term::color_supported() {
term::fg(out, color); term::fg(out, color);
} }
out.write_str(word); out.write_str(word);
if term::color_supported() { if use_color && term::color_supported() {
term::reset(out); term::reset(out);
} }
} }
@@ -247,6 +251,7 @@ fn should_sort_failures_before_printing_them() {
let st = let st =
@{out: writer, @{out: writer,
log_out: option::none, log_out: option::none,
use_color: false,
mut total: 0u, mut total: 0u,
mut passed: 0u, mut passed: 0u,
mut failed: 0u, mut failed: 0u,
@@ -262,6 +267,8 @@ fn should_sort_failures_before_printing_them() {
assert apos < bpos; assert apos < bpos;
} }
fn use_color() -> bool { ret get_concurrency() == 1u; }
enum testevent { enum testevent {
te_filtered([test_desc]), te_filtered([test_desc]),
te_wait(test_desc), te_wait(test_desc),