7

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?

stevenl
  • 6,736
  • 26
  • 33

1 Answers1

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
----------------------------------- ------ ------ ------ ------ ------ ------
ikegami
  • 367,544
  • 15
  • 269
  • 518
  • 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? – stevenl Oct 19 '13 at 00:13
  • @stevenl, ah, no. ...except I get the same result after removing it. Devel::Cover 1.08, Perl 5.16.3 – ikegami Oct 19 '13 at 01:37