Skip to content

Commit 7a890fe

Browse files
Apply changes to the test runner
1 parent 1b12e0f commit 7a890fe

File tree

1 file changed

+11
-19
lines changed

1 file changed

+11
-19
lines changed

lib/compiler/test_runner.zig

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ fn mainServer() !void {
202202
},
203203
};
204204
if (!is_fuzz_test) @panic("missed call to std.testing.fuzz");
205-
if (log_err_count != 0) @panic("error logs detected");
206205
assert(mode != .forever);
207206
std.process.exit(0);
208207
},
@@ -228,7 +227,11 @@ fn mainTerminal() void {
228227
.root_name = "Test",
229228
.estimated_total_items = test_fn_list.len,
230229
});
231-
const have_tty = std.fs.File.stderr().isTty();
230+
const doColors = std.fs.File.stderr().supportsAnsiEscapeCodes();
231+
const reset = if (doColors) "\x1b[0m" else "";
232+
const red = if (doColors) "\x1b[31m" else "";
233+
const yellow = if (doColors) "\x1b[33m" else "";
234+
const green = if (doColors) "\x1b[32m" else "";
232235

233236
var leaks: usize = 0;
234237
for (test_fn_list, 0..) |test_fn, i| {
@@ -241,33 +244,22 @@ fn mainTerminal() void {
241244
testing.log_level = .warn;
242245

243246
const test_node = root_node.start(test_fn.name, 0);
244-
if (!have_tty) {
245-
std.debug.print("{d}/{d} {s}...", .{ i + 1, test_fn_list.len, test_fn.name });
246-
}
247+
248+
std.debug.print("{d: >4}/{d: <4} {s:.<65}", .{ i + 1, test_fn_list.len, test_fn.name });
247249
is_fuzz_test = false;
248250
if (test_fn.func()) |_| {
249251
ok_count += 1;
250252
test_node.end();
251-
if (!have_tty) std.debug.print("OK\n", .{});
253+
std.debug.print("{s}OK{s}\n", .{ green, reset });
252254
} else |err| switch (err) {
253255
error.SkipZigTest => {
254256
skip_count += 1;
255-
if (have_tty) {
256-
std.debug.print("{d}/{d} {s}...SKIP\n", .{ i + 1, test_fn_list.len, test_fn.name });
257-
} else {
258-
std.debug.print("SKIP\n", .{});
259-
}
257+
std.debug.print("{s}SKIP{s}\n", .{ yellow, reset });
260258
test_node.end();
261259
},
262260
else => {
263261
fail_count += 1;
264-
if (have_tty) {
265-
std.debug.print("{d}/{d} {s}...FAIL ({t})\n", .{
266-
i + 1, test_fn_list.len, test_fn.name, err,
267-
});
268-
} else {
269-
std.debug.print("FAIL ({t})\n", .{err});
270-
}
262+
std.debug.print("{s}FAIL{s}\n{s}:\n", .{ red, reset, @errorName(err) });
271263
if (@errorReturnTrace()) |trace| {
272264
std.debug.dumpStackTrace(trace);
273265
}
@@ -291,7 +283,7 @@ fn mainTerminal() void {
291283
if (fuzz_count != 0) {
292284
std.debug.print("{d} fuzz tests found.\n", .{fuzz_count});
293285
}
294-
if (leaks != 0 or log_err_count != 0 or fail_count != 0) {
286+
if (leaks != 0 or fail_count != 0) {
295287
std.process.exit(1);
296288
}
297289
}

0 commit comments

Comments
 (0)