authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-18 23:44:31-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-18 23:45:32-07:00
log07c03f85a8e062923b07572a68acc0191c84f001
treed1cb78c94e593a47a28b47cf65cda0b53e8df1ef
parent9f9f215305389c08a21730859982b68bf2681932

zig test: fix test runner detection of tty

Before, `std.Progress` was printing unwanted stuff to stderr. Now, the test runner's logic to detect whether we should print each test as a separate line to stderr is properly activated.

1 files changed, 9 insertions(+), 6 deletions(-)

lib/std/special/test_runner.zig+9-6
......@@ -31,11 +31,14 @@ pub fn main() void {
3131 var ok_count: usize = 0;
3232 var skip_count: usize = 0;
3333 var fail_count: usize = 0;
34 var progress = std.Progress{};
34 var progress = std.Progress{
35 .dont_print_on_dumb = true,
36 };
3537 const root_node = progress.start("Test", test_fn_list.len) catch |err| switch (err) {
3638 // TODO still run tests in this case
3739 error.TimerUnsupported => @panic("timer unsupported"),
3840 };
41 const have_tty = progress.terminal != null and progress.supports_ansi_escape_codes;
3942
4043 var async_frame_buffer: []align(std.Target.stack_align) u8 = undefined;
4144 // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
......@@ -55,7 +58,7 @@ pub fn main() void {
5558 var test_node = root_node.start(test_fn.name, 0);
5659 test_node.activate();
5760 progress.refresh();
58 if (progress.terminal == null) {
61 if (!have_tty) {
5962 std.debug.print("{d}/{d} {s}... ", .{ i + 1, test_fn_list.len, test_fn.name });
6063 }
6164 const result = if (test_fn.async_frame_size) |size| switch (io_mode) {
......@@ -71,26 +74,26 @@ pub fn main() void {
7174 skip_count += 1;
7275 test_node.end();
7376 progress.log("{s}... SKIP (async test)\n", .{test_fn.name});
74 if (progress.terminal == null) std.debug.print("SKIP (async test)\n", .{});
77 if (!have_tty) std.debug.print("SKIP (async test)\n", .{});
7578 continue;
7679 },
7780 } else test_fn.func();
7881 if (result) |_| {
7982 ok_count += 1;
8083 test_node.end();
81 if (progress.terminal == null) std.debug.print("OK\n", .{});
84 if (!have_tty) std.debug.print("OK\n", .{});
8285 } else |err| switch (err) {
8386 error.SkipZigTest => {
8487 skip_count += 1;
8588 test_node.end();
8689 progress.log("{s}... SKIP\n", .{test_fn.name});
87 if (progress.terminal == null) std.debug.print("SKIP\n", .{});
90 if (!have_tty) std.debug.print("SKIP\n", .{});
8891 },
8992 else => {
9093 fail_count += 1;
9194 test_node.end();
9295 progress.log("{s}... FAIL ({s})\n", .{ test_fn.name, @errorName(err) });
93 if (progress.terminal == null) std.debug.print("FAIL ({s})\n", .{@errorName(err)});
96 if (!have_tty) std.debug.print("FAIL ({s})\n", .{@errorName(err)});
9497 if (@errorReturnTrace()) |trace| {
9598 std.debug.dumpStackTrace(trace.*);
9699 }