in reply to How do you Test that the right output got printed?

In terms of good design, the previous replies are right on the money. But if you are unable to restructure your code as they suggest, it is still possible to test what you are asking.

You can localize STDERR and STDOUT to filehandles which write to scalars. Then call the method and check that the scalars contain what they should:

use Test::More 'no_plan'; my $status = Status->new; my ($stderr, $stdout); { local(*STDERR, *STDOUT); open STDERR, ">", \($stderr = ""); open STDOUT, ">", \($stdout = ""); $status->status("good"); } ok( ($stderr eq "") and ($stdout =~ /good status/) ); ### { local(*STDERR, *STDOUT); open STDERR, ">", \($stderr = ""); open STDOUT, ">", \($stdout = ""); $status->status("bad"); } ok( ($stderr =~ /bad status/) and ($stdout eq "") );

blokhead