in reply to Tee STDOUT
Testing stuff written to stdout has been discussed a few times on the perl-qa mailing list. As far as possible, I use Ovid's trick of something like:
sub Foo::_print { print shift }
Then in my test, something like this:
my $_print; *Foo::_print = sub { $_print = shift }; is($_print, $expected, "Foo::_print output the correct data");
Apart from sparing you worrying about Test::Harness choking, it makes the module a little more flexible in that you can (a little hackily) override the _print function if you need to alter the module behaviour.
If you can't use a _print() function for some reason, there are many other approaches as discussed here and here and here and here. For an example of using tie, see the file TieOut.pm in the ExtUtils-MakeMaker CPAN distribution.
|
|---|