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 = .{...@@ -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;
...@@ -131,6 +131,7 @@ fn mainServer() !void {...@@ -131,6 +131,7 @@ fn mainServer() !void {
131131
132 .run_test => {132 .run_test => {
133 testing.allocator_instance = .{};133 testing.allocator_instance = .{};
134 testing.io_instance = .init(fba.allocator());
134 log_err_count = 0;135 log_err_count = 0;
135 const index = try server.receiveBody_u32();136 const index = try server.receiveBody_u32();
136 const test_fn = builtin.test_functions[index];137 const test_fn = builtin.test_functions[index];
...@@ -152,6 +153,8 @@ fn mainServer() !void {...@@ -152,6 +153,8 @@ fn mainServer() !void {
152 break :s .fail;153 break :s .fail;
153 },154 },
154 };155 };
156 testing.io_instance.deinit();
157 fba.reset();
155 const leak_count = testing.allocator_instance.detectLeaks();158 const leak_count = testing.allocator_instance.detectLeaks();
156 testing.allocator_instance.deinitWithoutLeakChecks();159 testing.allocator_instance.deinitWithoutLeakChecks();
157 try server.serveTestResults(.{160 try server.serveTestResults(.{
...@@ -228,18 +231,13 @@ fn mainTerminal() void {...@@ -228,18 +231,13 @@ fn mainTerminal() void {
228 });231 });
229 const have_tty = std.fs.File.stderr().isTty();232 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
236 var leaks: usize = 0;234 var leaks: usize = 0;
237 for (test_fn_list, 0..) |test_fn, i| {235 for (test_fn_list, 0..) |test_fn, i| {
238 testing.allocator_instance = .{};236 testing.allocator_instance = .{};
237 testing.io_instance = .init(fba.allocator());
239 defer {238 defer {
240 if (testing.allocator_instance.deinit() == .leak) {239 if (testing.allocator_instance.deinit() == .leak) leaks += 1;
241 leaks += 1;240 testing.io_instance.deinit();
242 }
243 }241 }
244 testing.log_level = .warn;242 testing.log_level = .warn;
245243
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