我有以下逻辑:
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 );
Run Code Online (Sandbox Code Playgroud)
该return声明将永远不会被覆盖的情况,其中$x和$y都是不确定的.因此,覆盖率报告指出该条件未被发现:
% | coverage | condition
------------------------------
67 | A | B | dec | $x // $y
|-------------|
===> | 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | X | 1 |
Run Code Online (Sandbox Code Playgroud)
有没有办法让我把这个条件标记为uncoverable?uncoverable condition false在线上方添加可修复覆盖率摘要,但在查看详细信息时,条件覆盖率仍为67%.
Devel :: Cover是否处理//运算符?
另一方面,如果我改变了 die行为等效行:
die "died" if !defined $x && !defined $y;
Run Code Online (Sandbox Code Playgroud)
该线也变为67%.
% | coverage | condition
------------------------------
67 | A | B | dec | defined $x or defined $y
|-------------|
| 0 | 0 | 0 |
===> | 0 | 1 | 1 |
| 1 | X | 1 |
Run Code Online (Sandbox Code Playgroud)
这可能是一个错误吗?
这是没有意义的。//只有两个路径($x已定义、$x未定义)。$y与 无关//。所以我进行了测试
test( 1, 2 );
#test( 1, undef ); # Don't even need this one.
test( undef, 2 );
test( undef, undef );
Run Code Online (Sandbox Code Playgroud)
得到:
----------------------------------- ------ ------ ------ ------ ------ ------
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
----------------------------------- ------ ------ ------ ------ ------ ------
Run Code Online (Sandbox Code Playgroud)