authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-07-19 22:10:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-10-29 06:20:48-07:00
logd801a71d29938196f3e8f43b766f42450b27f235
treedbd347754f451d03e51804942427d5d0a05b9a9e
parent84d60404becbb66da3b025ab510e945b1bd8f5ff

add std.testing.io


2 files changed, 10 insertions(+), 9 deletions(-)

lib/compiler/test_runner.zig+7-9
......@@ -12,7 +12,7 @@ pub const std_options: std.Options = .{
1212};
1313
1414var log_err_count: usize = 0;
15var fba = std.heap.FixedBufferAllocator.init(&fba_buffer);
15var fba: std.heap.FixedBufferAllocator = .init(&fba_buffer);
1616var fba_buffer: [8192]u8 = undefined;
1717var stdin_buffer: [4096]u8 = undefined;
1818var stdout_buffer: [4096]u8 = undefined;
......@@ -131,6 +131,7 @@ fn mainServer() !void {
131131
132132 .run_test => {
133133 testing.allocator_instance = .{};
134 testing.io_instance = .init(fba.allocator());
134135 log_err_count = 0;
135136 const index = try server.receiveBody_u32();
136137 const test_fn = builtin.test_functions[index];
......@@ -152,6 +153,8 @@ fn mainServer() !void {
152153 break :s .fail;
153154 },
154155 };
156 testing.io_instance.deinit();
157 fba.reset();
155158 const leak_count = testing.allocator_instance.detectLeaks();
156159 testing.allocator_instance.deinitWithoutLeakChecks();
157160 try server.serveTestResults(.{
......@@ -228,18 +231,13 @@ fn mainTerminal() void {
228231 });
229232 const have_tty = std.fs.File.stderr().isTty();
230233
231 var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
232 // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
233 // ignores the alignment of the slice.
234 async_frame_buffer = &[_]u8{};
235
236234 var leaks: usize = 0;
237235 for (test_fn_list, 0..) |test_fn, i| {
238236 testing.allocator_instance = .{};
237 testing.io_instance = .init(fba.allocator());
239238 defer {
240 if (testing.allocator_instance.deinit() == .leak) {
241 leaks += 1;
242 }
239 if (testing.allocator_instance.deinit() == .leak) leaks += 1;
240 testing.io_instance.deinit();
243241 }
244242 testing.log_level = .warn;
245243
lib/std/testing.zig+3
......@@ -28,6 +28,9 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{
2828 break :b .init;
2929};
3030
31pub var io_instance: std.Io.ThreadPool = undefined;
32pub const io = io_instance.io();
33
3134/// TODO https://github.com/ziglang/zig/issues/5738
3235pub var log_level = std.log.Level.warn;
3336