| author | |
| committer | |
| log | bf56cdd9edffd5b97d2084b46cda6e6a89a391c1 |
| tree | b27dffca9c3c26ef8cb33776dfbdf1941e7f6e55 |
| parent | 7bd0500589f02a6f2ba75525d803b2c1d7409ebe |
by default the test runner will only print logs with "warning" or
higher. this can be configured via the std.testing API.
See #5738 for future plans2 files changed, 15 insertions(+), 0 deletions(-)
lib/std/special/test_runner.zig+12| ... | ... | @@ -21,6 +21,7 @@ pub fn main() anyerror!void { |
| 21 | 21 | |
| 22 | 22 | for (test_fn_list) |test_fn, i| { |
| 23 | 23 | std.testing.base_allocator_instance.reset(); |
| 24 | std.testing.log_level = .warn; | |
| 24 | 25 | |
| 25 | 26 | var test_node = root_node.start(test_fn.name, null); |
| 26 | 27 | test_node.activate(); |
| ... | ... | @@ -73,3 +74,14 @@ pub fn main() anyerror!void { |
| 73 | 74 | std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count }); |
| 74 | 75 | } |
| 75 | 76 | } |
| 77 | ||
| 78 | pub fn log( | |
| 79 | comptime message_level: std.log.Level, | |
| 80 | comptime scope: @Type(.EnumLiteral), | |
| 81 | comptime format: []const u8, | |
| 82 | args: var, | |
| 83 | ) void { | |
| 84 | if (@enumToInt(message_level) <= @enumToInt(std.testing.log_level)) { | |
| 85 | std.debug.print("[{}] ({}): " ++ format, .{@tagName(scope), @tagName(message_level)} ++ args); | |
| 86 | } | |
| 87 | } |
lib/std/testing.zig+3| ... | ... | @@ -14,6 +14,9 @@ pub var failing_allocator_instance = FailingAllocator.init(&base_allocator_insta |
| 14 | 14 | pub var base_allocator_instance = std.mem.validationWrap(std.heap.ThreadSafeFixedBufferAllocator.init(allocator_mem[0..])); |
| 15 | 15 | var allocator_mem: [2 * 1024 * 1024]u8 = undefined; |
| 16 | 16 | |
| 17 | /// TODO https://github.com/ziglang/zig/issues/5738 | |
| 18 | pub var log_level = std.log.Level.warn; | |
| 19 | ||
| 17 | 20 | /// This function is intended to be used only in tests. It prints diagnostics to stderr |
| 18 | 21 | /// and then aborts when actual_error_union is not expected_error. |
| 19 | 22 | pub fn expectError(expected_error: anyerror, actual_error_union: var) void { |