Should standalone test simple/cat/main.zig actually work or just be buildable?

Hi, I am learning zig and couldn’t find any information about why test/standalone/simple/cat/main.zig panics on run in version 0.15.1, but in 0.14.1 it works properly.

/.../zig/std/debug.zig:559:14: 0x102e0fe07 in assert (...)
    if (!ok) unreachable; // assertion failure
             ^
/.../zig/0.15.1/lib/zig/std/Io/Writer.zig:939:11: 0x102ea2bb7 in sendFileAll (...)
    assert(w.buffer.len > 0);
          ^
/.../src/main.zig:35:39: 0x102ea28df in main (..)
            _ = try stdout.sendFileAll(&file_reader, .unlimited);
                                      ^

Steps to reproduce

$ zig init
# replace contents of src/main.zig with test/standalone/simple/cat/main.zig
$ zig build
$ echo "test" > t.txt
$ ./zig-out/bin/cat t.txt

Is my assumption correct that the goal was to have a buildable example for testing, not an actually working one or is this is degradation after 0.15 release and it should be fixed?

Hi @imomaliev
Welcome to ziggit :slight_smile:

It complains about the missing buffer of stdout.
A fix is:

    var buf: [4096]u8 = undefined;
    var stdout_writer = std.fs.File.stdout().writerStreaming(&buf);
1 Like

I am not sure if this test is disabled because it does not work (the intention might be to use sendFile without a buffer) or it is an oversight.

Hi @dimdin, thanks! Yes, have spotted the fix by reading examples in zig’s src/main.zig :slightly_smiling_face: Also, since there is now a buffer in stdout_writer we should call stdout.flush() after each sendFileAll call. The main question was: should I send a fix to upstream, or is this intended? The more I look at the 0.14.1 version the more I believe this is an oversight.

P.S. Sorry if my message sounds crude, I am not a native speaker and mean everything written in the best way possible)

I believe the test is not disabled, but looks like standalone test suit is just builds the file and doesn’t have any verification if the program itself works

@dimdin Thanks again for warm welcome and tips) I decided to push fix to upstream Fix standalone test simple/cat/main.zig after Writergate update by imomaliev · Pull Request #25188 · ziglang/zig · GitHub, will see what the maintainers will say

1 Like