mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
add std.testing.io
This commit is contained in:
parent
84d60404be
commit
d801a71d29
2 changed files with 10 additions and 9 deletions
|
|
@ -12,7 +12,7 @@ pub const std_options: std.Options = .{
|
||||||
};
|
};
|
||||||
|
|
||||||
var log_err_count: usize = 0;
|
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 fba_buffer: [8192]u8 = undefined;
|
||||||
var stdin_buffer: [4096]u8 = undefined;
|
var stdin_buffer: [4096]u8 = undefined;
|
||||||
var stdout_buffer: [4096]u8 = undefined;
|
var stdout_buffer: [4096]u8 = undefined;
|
||||||
|
|
@ -131,6 +131,7 @@ fn mainServer() !void {
|
||||||
|
|
||||||
.run_test => {
|
.run_test => {
|
||||||
testing.allocator_instance = .{};
|
testing.allocator_instance = .{};
|
||||||
|
testing.io_instance = .init(fba.allocator());
|
||||||
log_err_count = 0;
|
log_err_count = 0;
|
||||||
const index = try server.receiveBody_u32();
|
const index = try server.receiveBody_u32();
|
||||||
const test_fn = builtin.test_functions[index];
|
const test_fn = builtin.test_functions[index];
|
||||||
|
|
@ -152,6 +153,8 @@ fn mainServer() !void {
|
||||||
break :s .fail;
|
break :s .fail;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
testing.io_instance.deinit();
|
||||||
|
fba.reset();
|
||||||
const leak_count = testing.allocator_instance.detectLeaks();
|
const leak_count = testing.allocator_instance.detectLeaks();
|
||||||
testing.allocator_instance.deinitWithoutLeakChecks();
|
testing.allocator_instance.deinitWithoutLeakChecks();
|
||||||
try server.serveTestResults(.{
|
try server.serveTestResults(.{
|
||||||
|
|
@ -228,18 +231,13 @@ fn mainTerminal() void {
|
||||||
});
|
});
|
||||||
const have_tty = std.fs.File.stderr().isTty();
|
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;
|
var leaks: usize = 0;
|
||||||
for (test_fn_list, 0..) |test_fn, i| {
|
for (test_fn_list, 0..) |test_fn, i| {
|
||||||
testing.allocator_instance = .{};
|
testing.allocator_instance = .{};
|
||||||
|
testing.io_instance = .init(fba.allocator());
|
||||||
defer {
|
defer {
|
||||||
if (testing.allocator_instance.deinit() == .leak) {
|
if (testing.allocator_instance.deinit() == .leak) leaks += 1;
|
||||||
leaks += 1;
|
testing.io_instance.deinit();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
testing.log_level = .warn;
|
testing.log_level = .warn;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,6 +28,9 @@ pub var allocator_instance: std.heap.GeneralPurposeAllocator(.{
|
||||||
break :b .init;
|
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
|
/// TODO https://github.com/ziglang/zig/issues/5738
|
||||||
pub var log_level = std.log.Level.warn;
|
pub var log_level = std.log.Level.warn;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue