package Foo;
use warnings;
use strict;
require Exporter;
our @ISA = qw(Exporter);
our @EXPORT_OK = qw(bar);
sub bar {
my $x = shift;
if ($x > 10) {
return 'big';
}
else {
print 'small';
}
}
1;
Here is a single test, in a file named test.pl:
use warnings;
use strict;
use Foo qw(bar);
use Test::More tests => 2;
is(bar(77), 'big', 'check 77');
is(bar(22), 'big', 'check 22');
Both of these files are in the same directory. Run the test with coverage as follows:
perl -MDevel::Cover test.pl
I get this report as output:
It is a little verbose, but if you focus on the Foo.pm line, you'll see that only 50% of its branches were covered. This corresponds to the if branch inside the bar sub. |