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 = .{...@@ -12,7 +12,7 @@ pub const std_options: std.Options = .{
12};12};
1313
14var log_err_count: usize = 0;14var log_err_count: usize = 0;
15var fba = std.heap.FixedBufferAllocator.init(&fba_buffer);15var fba: std.heap.FixedBufferAllocator = .init(&fba_buffer);
16var fba_buffer: [8192]u8 = undefined;16var fba_buffer: [8192]u8 = undefined;
17var stdin_buffer: [4096]u8 = undefined;17var stdin_buffer: [4096]u8 = undefined;
18var stdout_buffer: [4096]u8 = undefined;18var stdout_buffer: [4096]u8 = undefined;
...@@ -129,6 +129,7 @@ fn mainServer() !void {...@@ -129,6 +129,7 @@ fn mainServer() !void {
129129
130 .run_test => {130 .run_test => {
131 testing.allocator_instance = .{};131 testing.allocator_instance = .{};
132 testing.io_instance = .init(fba.allocator());
132 log_err_count = 0;133 log_err_count = 0;
133 const index = try server.receiveBody_u32();134 const index = try server.receiveBody_u32();
134 const test_fn = builtin.test_functions[index];135 const test_fn = builtin.test_functions[index];
...@@ -144,6 +145,8 @@ fn mainServer() !void {...@@ -144,6 +145,8 @@ fn mainServer() !void {
144 }145 }
145 },146 },
146 };147 };
148 testing.io_instance.deinit();
149 fba.reset();
147 const leak = testing.allocator_instance.deinit() == .leak;150 const leak = testing.allocator_instance.deinit() == .leak;
148 try server.serveTestResults(.{151 try server.serveTestResults(.{
149 .index = index,152 .index = index,
...@@ -217,18 +220,13 @@ fn mainTerminal() void {...@@ -217,18 +220,13 @@ fn mainTerminal() void {
217 });220 });
218 const have_tty = std.fs.File.stderr().isTty();221 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
225 var leaks: usize = 0;223 var leaks: usize = 0;
226 for (test_fn_list, 0..) |test_fn, i| {224 for (test_fn_list, 0..) |test_fn, i| {
227 testing.allocator_instance = .{};225 testing.allocator_instance = .{};
226 testing.io_instance = .init(fba.allocator());
228 defer {227 defer {
229 if (testing.allocator_instance.deinit() == .leak) {228 if (testing.allocator_instance.deinit() == .leak) leaks += 1;
230 leaks += 1;229 testing.io_instance.deinit();
231 }
232 }230 }
233 testing.log_level = .warn;231 testing.log_level = .warn;
234232
lib/std/testing.zig+3
...@@ -28,6 +28,9 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{...@@ -28,6 +28,9 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{
28 break :b .init;28 break :b .init;
29};29};
3030
31pub var io_instance: std.Io.ThreadPool = undefined;
32pub const io = io_instance.io();
33
31/// TODO https://github.com/ziglang/zig/issues/573834/// TODO https://github.com/ziglang/zig/issues/5738
32pub var log_level = std.log.Level.warn;35pub var log_level = std.log.Level.warn;
3336