Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
baronleonardo opened this issue Jun 10, 2023 · 9 comments
Open

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

baronleonardo opened this issue Jun 10, 2023 · 9 comments
Labels
bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@baronleonardo
Copy link

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
@baronleonardo baronleonardo added the bug Observed behavior contradicts documented or intended behavior label Jun 10, 2023
@baronleonardo baronleonardo changed the title missing newline after Test [1/2] ... missing newline after Test [1/1] ... Jun 10, 2023
@nektro
Copy link
Contributor

nektro commented Jun 11, 2023

behavior changed in master, tests are not currently expected to output #15091

also related #5738

edit there was another related issue but i cant find it atm

@nektro
Copy link
Contributor

nektro commented Jun 11, 2023

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

@haze
Copy link
Contributor

haze commented Jun 11, 2023

@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
Copy link
Author

  • 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 ?

@squeek502
Copy link
Collaborator

squeek502 commented Jun 11, 2023

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.Writer instead) 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.

@baronleonardo
Copy link
Author

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
Copy link
Collaborator

squeek502 commented Jun 11, 2023

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
Copy link
Contributor

nektro commented Jun 11, 2023

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

@baronleonardo
Copy link
Author

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

@andrewrk andrewrk added this to the 0.12.0 milestone Jul 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

5 participants