Testing without stdin/stdout is generally the better way to go, but just for completeness, this thread contains a few possible approaches for testing the program in the OP unmodified:
For the build system approach, you’d want to do something like:
test_foo.setStdIn(.{ .bytes = "foo\n" });
test_foo.expectStdOutEqual("Enter a word: \n");
test_foo.expectStdErrEqual("f o o ");