Reputation: 19037
I'm writing a Perl test script with Test::More
for a process that is very verbose. I'm trying to figure out a good practice for highlighting the test results out of the verbose process I'm testing.
use Test::More;
ok( verbose_process(), 'Test A of a verbose process' );
ok( verbose_process(), 'Test B of a verbose process' );
ok( verbose_process(), 'Test C of a verbose process' );
sub verbose_process{
print "$_\n" for (0..100);
return 1;
}
I'm imagining a way of asking Test::More
for a test summary at the bottom of my script. Is such a thing possible? Or should I be suppressing the output of my verbose_pocess?
Upvotes: 2
Views: 230
Reputation: 13664
Use Capture::Tiny to capture STDOUT and STDERR from the process. You can then either test STDOUT/STDERR to make sure they contain expected data, or discard them if you consider that output to be unimportant.
use strict;
use warnings;
use Test::More;
use Capture::Tiny qw(capture);
my (undef, undef, $result_a) = capture { scalar verbose_process() };
ok($result_a, 'Test A of a verbose process');
my (undef, undef, $result_b) = capture { scalar verbose_process() };
ok($result_b, 'Test B of a verbose process');
my ($stdout_c, undef, $result_c) = capture { scalar verbose_process() };
ok($result_c, 'Test C of a verbose process');
like($stdout_c, qr/100\n\z/, '... and count to STDOUT ended correctly');
sub verbose_process {
print "$_\n" for (0..100);
return 1;
}
done_testing;
Upvotes: 2