Skip to content

Commit 91c98ec

Browse files
Apply changes to the test runner
1 parent 83e3b93 commit 91c98ec

1 file changed

Lines changed: 11 additions & 19 deletions

File tree

lib/compiler/test_runner.zig

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ fn mainServer() !void {
169169
},
170170
};
171171
if (!is_fuzz_test) @panic("missed call to std.testing.fuzz");
172-
if (log_err_count != 0) @panic("error logs detected");
173172
},
174173

175174
else => {
@@ -191,7 +190,11 @@ fn mainTerminal() void {
191190
.root_name = "Test",
192191
.estimated_total_items = test_fn_list.len,
193192
});
194-
const have_tty = std.fs.File.stderr().isTty();
193+
const doColors = std.fs.File.stderr().supportsAnsiEscapeCodes();
194+
const reset = if (doColors) "\x1b[0m" else "";
195+
const red = if (doColors) "\x1b[31m" else "";
196+
const yellow = if (doColors) "\x1b[33m" else "";
197+
const green = if (doColors) "\x1b[32m" else "";
195198

196199
var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
197200
// TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
@@ -209,33 +212,22 @@ fn mainTerminal() void {
209212
testing.log_level = .warn;
210213

211214
const test_node = root_node.start(test_fn.name, 0);
212-
if (!have_tty) {
213-
std.debug.print("{d}/{d} {s}...", .{ i + 1, test_fn_list.len, test_fn.name });
214-
}
215+
216+
std.debug.print("{d: >4}/{d: <4} {s:.<65}", .{ i + 1, test_fn_list.len, test_fn.name });
215217
is_fuzz_test = false;
216218
if (test_fn.func()) |_| {
217219
ok_count += 1;
218220
test_node.end();
219-
if (!have_tty) std.debug.print("OK\n", .{});
221+
std.debug.print("{s}OK{s}\n", .{ green, reset });
220222
} else |err| switch (err) {
221223
error.SkipZigTest => {
222224
skip_count += 1;
223-
if (have_tty) {
224-
std.debug.print("{d}/{d} {s}...SKIP\n", .{ i + 1, test_fn_list.len, test_fn.name });
225-
} else {
226-
std.debug.print("SKIP\n", .{});
227-
}
225+
std.debug.print("{s}SKIP{s}\n", .{ yellow, reset });
228226
test_node.end();
229227
},
230228
else => {
231229
fail_count += 1;
232-
if (have_tty) {
233-
std.debug.print("{d}/{d} {s}...FAIL ({s})\n", .{
234-
i + 1, test_fn_list.len, test_fn.name, @errorName(err),
235-
});
236-
} else {
237-
std.debug.print("FAIL ({s})\n", .{@errorName(err)});
238-
}
230+
std.debug.print("{s}FAIL{s}\n{s}:\n", .{ red, reset, @errorName(err) });
239231
if (@errorReturnTrace()) |trace| {
240232
std.debug.dumpStackTrace(trace.*);
241233
}
@@ -259,7 +251,7 @@ fn mainTerminal() void {
259251
if (fuzz_count != 0) {
260252
std.debug.print("{d} fuzz tests found.\n", .{fuzz_count});
261253
}
262-
if (leaks != 0 or log_err_count != 0 or fail_count != 0) {
254+
if (leaks != 0 or fail_count != 0) {
263255
std.process.exit(1);
264256
}
265257
}

0 commit comments

Comments
 (0)