in reply to How do you Test that the right output got printed?
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
|
|---|