aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-07-08 21:01:13 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-07-08 21:01:13 -0700
commitbf56cdd9edffd5b97d2084b46cda6e6a89a391c1 (patch)
treeb27dffca9c3c26ef8cb33776dfbdf1941e7f6e55 /lib
parent7bd0500589f02a6f2ba75525d803b2c1d7409ebe (diff)
downloadzig-bf56cdd9edffd5b97d2084b46cda6e6a89a391c1.tar.gz
zig-bf56cdd9edffd5b97d2084b46cda6e6a89a391c1.zip
start to make test runner aware of logging
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 plans
Diffstat (limited to 'lib')
-rw-r--r--lib/std/special/test_runner.zig12
-rw-r--r--lib/std/testing.zig3
2 files changed, 15 insertions, 0 deletions
diff --git a/lib/std/special/test_runner.zig b/lib/std/special/test_runner.zig
index 828d3165db..fd8c068f05 100644
--- a/lib/std/special/test_runner.zig
+++ b/lib/std/special/test_runner.zig
@@ -21,6 +21,7 @@ pub fn main() anyerror!void {
for (test_fn_list) |test_fn, i| {
std.testing.base_allocator_instance.reset();
+ std.testing.log_level = .warn;
var test_node = root_node.start(test_fn.name, null);
test_node.activate();
@@ -73,3 +74,14 @@ pub fn main() anyerror!void {
std.debug.warn("{} passed; {} skipped.\n", .{ ok_count, skip_count });
}
}
+
+pub fn log(
+ comptime message_level: std.log.Level,
+ comptime scope: @Type(.EnumLiteral),
+ comptime format: []const u8,
+ args: var,
+) void {
+ if (@enumToInt(message_level) <= @enumToInt(std.testing.log_level)) {
+ std.debug.print("[{}] ({}): " ++ format, .{@tagName(scope), @tagName(message_level)} ++ args);
+ }
+}
diff --git a/lib/std/testing.zig b/lib/std/testing.zig
index 670d8fd5d6..bdaf759d62 100644
--- a/lib/std/testing.zig
+++ b/lib/std/testing.zig
@@ -14,6 +14,9 @@ pub var failing_allocator_instance = FailingAllocator.init(&base_allocator_insta
pub var base_allocator_instance = std.mem.validationWrap(std.heap.ThreadSafeFixedBufferAllocator.init(allocator_mem[0..]));
var allocator_mem: [2 * 1024 * 1024]u8 = undefined;
+/// TODO https://github.com/ziglang/zig/issues/5738
+pub var log_level = std.log.Level.warn;
+
/// This function is intended to be used only in tests. It prints diagnostics to stderr
/// and then aborts when actual_error_union is not expected_error.
pub fn expectError(expected_error: anyerror, actual_error_union: var) void {