In the spirit of TMTOWTDI you could also use IO::File to create a temporary file, redirect STDIN to the temporary file, do your stuff, seek back to the start and slurp up the output into a scalar for testing as normal.
The skip2.t test in Test::Class uses this method.
One of the advantages is that IO::File is core so you don't have to muck around with other modules.
I did write a Test::Output module (download Test-Output-0.01.tar.gz) that allowed you to do things like:
output_is { hello() } "hello world\n", STDOUT, "hello world"; output_isnt { hello() } "goodbye", STDOUT, "not goodbye"; output_unlike { hello() } qr/bye/, STDOUT, "didn't print bye +"; output_like { hello() } qr/hello/, STDOUT, "printed hello"; like(Test::Output->last, qr/world/, "... and world");
... but I'm not entirely happy with the API so have not distributed it yet... feedback welcome :-)
In reply to Re^2: Testing Input and Output
by adrianh
in thread Testing Input and Output
by jaldhar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |