On Monday, February 9, 2004, at 02:14 am, David Wheeler wrote: [snip]
Perhaps:

stdout_is(print STDOUT "hello", "hello", 'print "hello" to STDOUT');
[snip]

I did something similar with Test::Output

http://www.quietstars.com/perl/Test-Output-0.01.tar.gz

which allows 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");

(rather than using a tied filehandle I just temporarily redirected it to a temporary file)

I like the look of Adriano's solution more because it allows you to test things that mix output on different filehandles - which I can see being a handy feature.

Adrian



Reply via email to