`zig test` -> OK printing is missing on MacOS Terminal

environment:
Zig: 0.11.0
MacOS: sonoma 14.2.1
Processor: 2.6GHz 6-Core Intel i7
compiler:
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: x86_64-apple-darwin23.2.0

test codes:

const std = @import("std");
const expect = std.testing.expect;

test "print test result" {
    const v = 3;
    try expect(v == 3);
    std.time.sleep(3000 * std.time.ns_per_ms);
}
$ zig test test.zig
Test [1/1] test.print test result...

OK is missing and is stuck. The following shows up 3 seconds later.

$ zig test test.zig
All 1 tests passed.

OK print code

179 test_node.end();
180 if (!have_tty) std.debug.print(“OK\n”, .{}); → stuck.

I presume printing after node ends causes stuck and it should be set before test_node.end().

This issue happenned on 0.9.1 two years ago. reddit post

Please tell me how to resolve this issue.

Thanks,

Welcome @MickeyOh,

You are getting this result because you are using a tty.

zig test test.zig
All 1 tests passed.

If you capture both stdout and stderr it displays:

zig test test.zig 2>&1 | head
1/1 test.print test result... OK
All 1 tests passed.

A way to overcome this is to build your own test_runner and use the --test-runner option. The default test_runner is bundled at lib/test_runner.zig

See also this thread:

2 Likes