Skip to content

Commit 7b3cb05

Browse files
committed
libstd: Colorify test results when run in parallel
Closes rust-lang#782
1 parent 828d067 commit 7b3cb05

File tree

1 file changed

+15
-22
lines changed

1 file changed

+15
-22
lines changed

src/libstd/test.rs

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ enum test_result { tr_ok, tr_failed, tr_ignored, }
9191
type console_test_state =
9292
@{out: io::writer,
9393
log_out: option<io::writer>,
94-
use_color: bool,
9594
mut total: uint,
9695
mut passed: uint,
9796
mut failed: uint,
@@ -117,7 +116,6 @@ fn run_tests_console(opts: test_opts,
117116
let st =
118117
@{out: io::stdout(),
119118
log_out: log_out,
120-
use_color: use_color(),
121119
mut total: 0u,
122120
mut passed: 0u,
123121
mut failed: 0u,
@@ -150,18 +148,18 @@ fn run_tests_console(opts: test_opts,
150148
alt result {
151149
tr_ok {
152150
st.passed += 1u;
153-
write_ok(st.out, st.use_color);
151+
write_ok(st.out);
154152
st.out.write_line("");
155153
}
156154
tr_failed {
157155
st.failed += 1u;
158-
write_failed(st.out, st.use_color);
156+
write_failed(st.out);
159157
st.out.write_line("");
160158
st.failures += [test];
161159
}
162160
tr_ignored {
163161
st.ignored += 1u;
164-
write_ignored(st.out, st.use_color);
162+
write_ignored(st.out);
165163
st.out.write_line("");
166164
}
167165
}
@@ -180,11 +178,9 @@ fn run_tests_console(opts: test_opts,
180178
}
181179

182180
st.out.write_str(#fmt["\nresult: "]);
183-
if success {
184-
write_ok(st.out, true);
185-
} else { write_failed(st.out, true); }
186-
st.out.write_str(#fmt[". %u passed; %u failed; %u ignored\n\n", st.passed,
187-
st.failed, st.ignored]);
181+
if success { write_ok(st.out); } else { write_failed(st.out); }
182+
st.out.write_str(#fmt[". %u passed; %u failed; %u ignored\n\n",
183+
st.passed, st.failed, st.ignored]);
188184

189185
ret success;
190186

@@ -197,24 +193,24 @@ fn run_tests_console(opts: test_opts,
197193
}, test.name));
198194
}
199195

200-
fn write_ok(out: io::writer, use_color: bool) {
201-
write_pretty(out, "ok", term::color_green, use_color);
196+
fn write_ok(out: io::writer) {
197+
write_pretty(out, "ok", term::color_green);
202198
}
203199

204-
fn write_failed(out: io::writer, use_color: bool) {
205-
write_pretty(out, "FAILED", term::color_red, use_color);
200+
fn write_failed(out: io::writer) {
201+
write_pretty(out, "FAILED", term::color_red);
206202
}
207203

208-
fn write_ignored(out: io::writer, use_color: bool) {
209-
write_pretty(out, "ignored", term::color_yellow, use_color);
204+
fn write_ignored(out: io::writer) {
205+
write_pretty(out, "ignored", term::color_yellow);
210206
}
211207

212-
fn write_pretty(out: io::writer, word: str, color: u8, use_color: bool) {
213-
if use_color && term::color_supported() {
208+
fn write_pretty(out: io::writer, word: str, color: u8) {
209+
if term::color_supported() {
214210
term::fg(out, color);
215211
}
216212
out.write_str(word);
217-
if use_color && term::color_supported() {
213+
if term::color_supported() {
218214
term::reset(out);
219215
}
220216
}
@@ -251,7 +247,6 @@ fn should_sort_failures_before_printing_them() {
251247
let st =
252248
@{out: writer,
253249
log_out: option::none,
254-
use_color: false,
255250
mut total: 0u,
256251
mut passed: 0u,
257252
mut failed: 0u,
@@ -267,8 +262,6 @@ fn should_sort_failures_before_printing_them() {
267262
assert apos < bpos;
268263
}
269264

270-
fn use_color() -> bool { ret get_concurrency() == 1u; }
271-
272265
enum testevent {
273266
te_filtered([test_desc]),
274267
te_wait(test_desc),

0 commit comments

Comments
 (0)