missing newline after `Test [1/1] ...`
Zig Version
0.10.1
Steps to Reproduce and Observed Behavior
test "testing"
{
std.log.warn("test", .{});
}
output:
Test [1/1] test.testing... [default] (warn): test
Expected Behavior
output:
Test [1/1] test.testing...
[default] (warn): test
behavior changed in master, tests are not currently expected to output https://github.com/ziglang/zig/issues/15091
also related https://github.com/ziglang/zig/issues/5738
edit there was another related issue but i cant find it atm
test blocks are meant to be whats commonly referred to as "unit tests" and should generally not have observable side effects
@nektro the warn and error log levels should make tests fail though, so I could see why this would be desired (also, it’s helpful when debugging tests)
- during first stage of developing a module I need to test it by just printing out to see (I failed to debug unit tests in zig so I;m using the old school way
printing) - if you have a print function how do you test it ?
during first stage of developing a module I need to test it by just printing out to see (I failed to debug unit tests in zig so I;m using the old school way printing)
What I do:
- If I know my test will be printing something, I sometimes emit a newline at the start of the test to get the first line to be on a separate line from the
Test [1/1] test.testing.... For the example in the OP that could be:
test "testing" {
std.debug.print("\n", .{});
std.log.warn("test", .{});
}
- Otherwise, I just keep in mind that the first line of output will go on the same line as the
Test [1/1] test.testing...
if you have a print function how do you test it ?
Either:
- Write the function so that it can output to more than just stderr/stdout (like a
std.io.Writerinstead) and then in the tests you can use e.g. an ArrayList as a buffer to write into instead of outputting to stderr/stdout - Use a child process to spawn the thing that prints, collect the stdout/stderr, and check it. This is the strategy used by the compare output Zig tests.
thanks @squeek502 for your ideas but they are workarounds to me not solutions we could solve all of that by just printing out normally
It's not as simple as 'printing out normally' since the Test [1/1] test.testing... is technically part of a progress bar. If you have multiple tests the Test [1/5] test.testing... would get overwritten with Test [2/5] test.test2... and so on. If none of the tests print to stderr, then the final result of zig test ends up looking like this:
> zig test multiple-tests.zig
All 7 tests passed.
while developing you can also put it in a pub fn main() !void {} and move to test {} once it is ready
can we add for example std.testing.print function ?