Here is simple test:
const std = @import("std");
test "a test" {
try std.testing.expect(1 == 1);
}
Let’s run it:
$ zig test t1.zig
All 1 tests passed.
Everything seems Ok, but actually it’s not.
Here is another test, which actually tests nothing, just prints something:
const std = @import("std");
test "dummy test" {
std.debug.print("{s}", .{"a"});
}
Running this test gives us this:
$ zig test t2.zig
TAll 1 tests passed.
^ // what is it?!?!?
Ok, let’s add one letter:
$ cat t2.zig
const std = @import("std");
test "dummy test" {
std.debug.print("{s}", .{"ab"});
}
And
$ zig test t2.zig
TeAll 1 tests passed.
^^ // What the ... is going on?!?
Ok, one more letter, “abc”, result:
$ zig test t2.zig
TesAll 1 tests passed.
Aha! “Tes” is probably the beginning of the word “Test”. Okaay, let’s output long string in the test, “abcdddddddddddddddddddddddddddddddddddd”:
$ zig test t2.zig
Test [1/1] test.dummy test... abcddddddAll 1 tests passed.
Now take a look at tests examples in the documentation:
$ zig test test_comptime_variables.zig
1/1 test_comptime_variables.test.comptime vars... OK
All 1 tests passed.
It looks like there was "OK\n"
after each test in a file, but then it has disappeared
and the final phrase is being output on the same line (probably after writing some backspaces or so). Was that intended? It’s very confusing actually.