It does indeed require you (I'd say allow you) to specify the exact input that readLine() will read within your test cases. Isn't that typically what you want in a unit test? You run your code with a certain input and verify that the output is what you expect?
Do you really want to read from the terminal during a unit test run? What do you want to happen if no user's present whilst the tests are run?
If you do really want read from an actual terminal, you can open /dev/tty and dup2 it to STDIN_FILENO. Pseudo-code:
[...] // most of the code like before
let oldStdin = dup(STDIN_FILENO)
let ttyFD = open("/dev/tty", O_RDONLY)
if ttyFD == -1 {
throw SomeErrorHereWhichIndicatesThatYouCouldNotOpenTheTTY()
}
dup2(ttyFD, STDIN_FILENO)
defer {
// Restore the original stdin
dup2(oldStdin, STDIN_FILENO)
// Close our copy of the original stdin.
close(oldStdin)
}
// Run the code.
try body()
[...]