#How the `zig` unit test prints information

1 messages · Page 1 of 1 (latest)

elfin dome
#
const std = @import("std");

pub fn main() !void {
    std.debug.print("Hello World!\n", .{});
}


test "expect this to fail" {
    std.log.debug("\ndebug Hello World!\n", .{});
    std.debug.print("\nHello World!\n", .{});
}
root@ser300462488588:~/test# zig test src/main.zig 
Test [1/1] test.expect this to fail... 
Hello World!
All 1 tests passed.

In general, how to print information in unit tests. Can you tell us about it? Thanks for the help!

remote ibex
#

As you can see, std.debug.print works. If you want to see the output of std.log you need to set std.testing.log_level low enough (it is .warn by default) for the type of log messages you want to see in the test. Note that this has to be done in each test, as the standard test runner sets it to .warn before executing each test.

royal moth
#

what if i want to log that certain tests are completed? say if i have two files and i want the test runner to log when the first one is complete, how could i go about that?