I have the following logic:
sub test {
my ($x, $y) = @_;
die unless defined $x || defined $y;
# uncoverable condition false
return $x // $y;
}
test( 1, 2 );
test( 1, undef );
test( undef, 2 );
test( undef, undef );
The return
statement will never be covered for the condition where $x
and $y
are both undefined. So the coverage report points out that condition as uncovered:
% | coverage | condition
------------------------------
67 | A | B | dec | $x // $y
|-------------|
===> | 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | X | 1 |
Is there a way for me to mark that condition as uncoverable
? Adding uncoverable condition false
above the line fixes the coverage summary, but when I look at the details the condition coverage is still at 67%.
Does Devel::Cover handle the //
operator?
On another note, if I change the die
line to the equivalent:
die "died" if !defined $x && !defined $y;
that line also becomes 67% covered.
% | coverage | condition
------------------------------
67 | A | B | dec | defined $x or defined $y
|-------------|
| 0 | 0 | 0 |
===> | 0 | 1 | 1 |
| 1 | X | 1 |
Could that be a bug?
That makes no sense. //
only has two paths ($x
is defined, $x
is not defined). $y
is not relevant for the //
. So I ran a test
test( 1, 2 );
#test( 1, undef ); # Don't even need this one.
test( undef, 2 );
test( undef, undef );
Got:
----------------------------------- ------ ------ ------ ------ ------ ------
File stmt bran cond sub time total
----------------------------------- ------ ------ ------ ------ ------ ------
x.pl 100.0 100.0 100.0 100.0 100.0 100.0
Total 100.0 100.0 100.0 100.0 100.0 100.0
----------------------------------- ------ ------ ------ ------ ------ ------
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With