diff --git a/lib/compiler/test_runner.zig b/lib/compiler/test_runner.zig index 673ea2cb2d..40f52fbd39 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; @@ -131,6 +131,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]; @@ -152,6 +153,8 @@ fn mainServer() !void { break :s .fail; }, }; + testing.io_instance.deinit(); + fba.reset(); const leak_count = testing.allocator_instance.detectLeaks(); testing.allocator_instance.deinitWithoutLeakChecks(); try server.serveTestResults(.{ @@ -228,18 +231,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 e1e78c3bec..5baaa0f77b 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;