Subject: | "return" in a branch messes up branch coverage sometimes |
I am using Devel-Cover 0.26. A program that demonstrates the issue follows:
[sjs@cobra foo]$ cat foo.pl
#!/usr/bin/perl
use strict;
use warnings;
is_3digits1(1234);
is_3digits1(123);
is_3digits2(1234);
is_3digits2(123);
is_3digits3(1234);
is_3digits3(123);
exit;
sub is_3digits1 {
my $val = shift;
if ($val =~ /^\d{3}$/) {
return 1;
}
else {
return;
}
}
sub is_3digits2 {
my $val = shift;
my $retval = undef;
$retval=1 if $val =~ /^\d{3}$/;
return $retval;
}
sub is_3digits3 {
my $val = shift;
return 1 if $val =~ /^\d{3}$/;
return;
}
[sjs@cobra foo]$
Run the program under Devel::Cover with "perl -MDevel::Cover foo.pl".
The relevant results from the coverage report are:
Branches
--------
line err % true false branch
----- --- ------ ------ ------ ------
19 100 1 1 if ($val =~ /^\d{3}$/) { }
30 100 1 1 if $val =~ /^\d{3}$/
36 *** 50 1 0 if $val =~ /^\d{3}$/
I expected 100% coverage in all three subroutines.