$ zig test src/main.zig
Press enter 123
_ <- cursor position
It hangs at cursor position, it’s like stdin.writeStreamingAll is writing but not to the “right” stdin, or perhaps something from the test runner is interfering?
stdin is used from reading only; you cannot write to stdin.
Also stdout and stderr are used for writing only.
Finally these are used by the builder and are not available when running the tester under zig build.
Your code should just be taking reader/writers, instead of relying on using a file at all, not to mention specific hard coded files.
That would allow you to use different reader/writers in your tests:
test "press_enter" {
var input = std.Io.Reader.fixed("123\n");
try press_enter(&input);
}
Also, spawning a thread just wait for enter is absurdly inefficient.
When reading stdin, the terminal will, by default, block until the user presses enter. That is to say, you get the behaviour you want for free. might be different when using a cmd prompt on windows(?), but there are terminals and wsl for windows which have the behaviour I described.