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-02 16:30:59-07:00
logf680c095bd96b2d739c7a1257fb3bff9abbac14a
treeb0e9a6aa97f7e0589b7c04457e422fc44797554c
parent2746239fd3f9ead09569a1a073d7a3c8819d5e11

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;
......@@ -129,6 +129,7 @@ fn mainServer() !void {
129129
130130 .run_test => {
131131 testing.allocator_instance = .{};
132 testing.io_instance = .init(fba.allocator());
132133 log_err_count = 0;
133134 const index = try server.receiveBody_u32();
134135 const test_fn = builtin.test_functions[index];
......@@ -144,6 +145,8 @@ fn mainServer() !void {
144145 }
145146 },
146147 };
148 testing.io_instance.deinit();
149 fba.reset();
147150 const leak = testing.allocator_instance.deinit() == .leak;
148151 try server.serveTestResults(.{
149152 .index = index,
......@@ -217,18 +220,13 @@ fn mainTerminal() void {
217220 });
218221 const have_tty = std.fs.File.stderr().isTty();
219222
220 var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined;
221 // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly
222 // ignores the alignment of the slice.
223 async_frame_buffer = &[_]u8{};
224
225223 var leaks: usize = 0;
226224 for (test_fn_list, 0..) |test_fn, i| {
227225 testing.allocator_instance = .{};
226 testing.io_instance = .init(fba.allocator());
228227 defer {
229 if (testing.allocator_instance.deinit() == .leak) {
230 leaks += 1;
231 }
228 if (testing.allocator_instance.deinit() == .leak) leaks += 1;
229 testing.io_instance.deinit();
232230 }
233231 testing.log_level = .warn;
234232
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