Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 547
stevenl Avatar asked Oct 18 '13 04:10

stevenl


1 Answers

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
----------------------------------- ------ ------ ------ ------ ------ ------
like image 195
ikegami Avatar answered Sep 19 '22 17:09

ikegami