From f680c095bd96b2d739c7a1257fb3bff9abbac14a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 19 Jul 2025 22:10:27 -0700 Subject: [PATCH] add std.testing.io --- lib/compiler/test_runner.zig | 16 +++++++--------- lib/std/testing.zig | 3 +++ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/compiler/test_runner.zig b/lib/compiler/test_runner.zig index 42c708cbfc..c8525b8659 100644 --- a/lib/compiler/test_runner.zig +++ b/lib/compiler/test_runner.zig @@ -12,7 +12,7 @@ pub const std_options: std.Options = .{ }; var log_err_count: usize = 0; -var fba = std.heap.FixedBufferAllocator.init(&fba_buffer); +var fba: std.heap.FixedBufferAllocator = .init(&fba_buffer); var fba_buffer: [8192]u8 = undefined; var stdin_buffer: [4096]u8 = undefined; var stdout_buffer: [4096]u8 = undefined; @@ -129,6 +129,7 @@ fn mainServer() !void { .run_test => { testing.allocator_instance = .{}; + testing.io_instance = .init(fba.allocator()); log_err_count = 0; const index = try server.receiveBody_u32(); const test_fn = builtin.test_functions[index]; @@ -144,6 +145,8 @@ fn mainServer() !void { } }, }; + testing.io_instance.deinit(); + fba.reset(); const leak = testing.allocator_instance.deinit() == .leak; try server.serveTestResults(.{ .index = index, @@ -217,18 +220,13 @@ fn mainTerminal() void { }); const have_tty = std.fs.File.stderr().isTty(); - var async_frame_buffer: []align(builtin.target.stackAlignment()) u8 = undefined; - // TODO this is on the next line (using `undefined` above) because otherwise zig incorrectly - // ignores the alignment of the slice. - async_frame_buffer = &[_]u8{}; - var leaks: usize = 0; for (test_fn_list, 0..) |test_fn, i| { testing.allocator_instance = .{}; + testing.io_instance = .init(fba.allocator()); defer { - if (testing.allocator_instance.deinit() == .leak) { - leaks += 1; - } + if (testing.allocator_instance.deinit() == .leak) leaks += 1; + testing.io_instance.deinit(); } testing.log_level = .warn; diff --git a/lib/std/testing.zig b/lib/std/testing.zig index 1c6c639796..e805c5a849 100644 --- a/lib/std/testing.zig +++ b/lib/std/testing.zig @@ -28,6 +28,9 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{ break :b .init; }; +pub var io_instance: std.Io.ThreadPool = undefined; +pub const io = io_instance.io(); + /// TODO https://github.com/ziglang/zig/issues/5738 pub var log_level = std.log.Level.warn;