ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.65k stars 2.53k forks source link

missing newline after `Test [1/1] ...` #15999

Open baronleonardo opened 1 year ago

baronleonardo commented 1 year ago

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
nektro commented 1 year ago

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

nektro commented 1 year ago

test blocks are meant to be whats commonly referred to as "unit tests" and should generally not have observable side effects

haze commented 1 year ago

@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)

baronleonardo commented 1 year ago
squeek502 commented 1 year ago

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:

test "testing" {
    std.debug.print("\n", .{});
    std.log.warn("test", .{});
}

if you have a print function how do you test it ?

Either:

baronleonardo commented 1 year ago

thanks @squeek502 for your ideas but they are workarounds to me not solutions we could solve all of that by just printing out normally

squeek502 commented 1 year ago

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.
nektro commented 1 year ago

while developing you can also put it in a pub fn main() !void {} and move to test {} once it is ready

baronleonardo commented 1 year ago

can we add for example std.testing.print function ?