Skip to content

Commit 47052ce

Browse files
committed
Refactor std::test
1 parent 4a34776 commit 47052ce

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/lib/test.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -140,30 +140,22 @@ fn run_tests(&test_opts opts, &test_desc[] tests) -> bool {
140140
ret true;
141141

142142
fn write_ok(&io::writer out) {
143-
if (term::color_supported()) {
144-
term::fg(out.get_buf_writer(), term::color_green);
145-
}
146-
out.write_str("ok");
147-
if (term::color_supported()) {
148-
term::reset(out.get_buf_writer());
149-
}
143+
write_pretty(out, "ok", term::color_green);
150144
}
151145

152146
fn write_failed(&io::writer out) {
153-
if (term::color_supported()) {
154-
term::fg(out.get_buf_writer(), term::color_red);
155-
}
156-
out.write_str("FAILED");
157-
if (term::color_supported()) {
158-
term::reset(out.get_buf_writer());
159-
}
147+
write_pretty(out, "FAILED", term::color_red);
160148
}
161149

162150
fn write_ignored(&io::writer out) {
151+
write_pretty(out, "ignored", term::color_yellow);
152+
}
153+
154+
fn write_pretty(&io::writer out, &str word, u8 color) {
163155
if (term::color_supported()) {
164-
term::fg(out.get_buf_writer(), term::color_yellow);
156+
term::fg(out.get_buf_writer(), color);
165157
}
166-
out.write_str("ignored");
158+
out.write_str(word);
167159
if (term::color_supported()) {
168160
term::reset(out.get_buf_writer());
169161
}

0 commit comments

Comments
 (0)