How to mark `//` conditions uncoverable with Devel::Cover?
Asked Answered
A

1

8

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?

Amabil answered 18/10, 2013 at 4:5 Comment(2)
What version of Devel::Cover are you running?Cognizance
The version I'm using is 1.08 (Strawberry Perl 5.18, if that makes any difference)Amabil
T
1

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
----------------------------------- ------ ------ ------ ------ ------ ------
Tub answered 18/10, 2013 at 11:59 Comment(2)
Your answer makes sense to me, and that's what I originally thought. But that's not what my report said. Did you run that with the uncoverable spec removed?Amabil
@stevenl, ah, no. ...except I get the same result after removing it. Devel::Cover 1.08, Perl 5.16.3Tub

© 2022 - 2024 — McMap. All rights reserved.