cpancover.com 的 Perl 模块覆盖率报告
Coverage report for Perl modules by cpancover.com
cpancover.com 生成有关 Perl 模块代码覆盖率的报告。
我知道它只是一个使用 Devel::Cover 的网络服务器,但我想简单地理解报告的含义,例如:
http://cpancover.com/latest/JSON-PP-4.02/blib-lib-JSON-PP-pm--condition.html
其中 table 的列如下:
- !l
- l&&!r
- l&&r
能否请您link一份相关文件来理解这一点,或者为我提供一些关于这些报告的初步指导?
这是文档的一部分,提供了有关报告格式的信息。
在覆盖测试中,如Devel::Cover
tells us,代码中可能有无法检查的地方:它们是"uncoverable"
Sometimes you have code which is uncoverable for some reason. Perhaps it is an else clause that cannot be reached, or a check for an error condition that should never happen. You can tell Devel::Cover that certain criteria are uncoverable and then they are not counted as errors when they are not exercised. In fact, they are counted as errors if they are exercised. [...]
处理这个可以考虑语句、分支、条件和子程序。您提供的示例报告处理条件,并且文档说
Because of the way in which Perl short-circuits boolean operations, there are three ways in which such conditionals can be uncoverable. In the case of $x && $y
for example, the left operator may never be true, the right operator may never be true, and the whole operation may never be false. These conditions may be modelled thus:
# uncoverable branch true
# uncoverable condition left
# uncoverable condition false
if ($x && !$y) {
$x++; # uncoverable statement
}
# uncoverable branch true
# uncoverable condition right
# uncoverable condition false
if (!$x && $y) {
}
通过这次讨论,linked 报告更有意义。
例如,这是我对您 link 中第一行的看法。这是一种 A && B
种情况,它涵盖了以下可能的情况:
left side false --- 覆盖在测试中(两个)
左真右假 --- 未涵盖
both left and right true --- covered (二)
然后我们点击 "line 214"(这是一个 link)并查看总体百分位数覆盖率(66 -- 三分之二)。颜色很明显,代码可以在 this page
上看到
文档还说有多种报告格式,因此您可能想进一步了解。但是,我不太容易看到哪里可以看,我觉得有点不安。
l
和r
指表达式的right-hand边和left-hand边,数字代表关联表达式为真的次数。
例如下面的表达式有0
for l && !r
的覆盖率:
exists $self->{'true'} and exists $self->{'false'}
这意味着 0
测试涵盖了以下情况:
(exists $self->{'true'}) && !(exists $self->{'false'})
Logical-and 和 logical-or 有两个输入,可以分别取两个值。
+-----------------+-----------------+
| Left-hand side | Right-hand side |
+-----------------+-----------------+
| False | False |
| False | True |
| True | False |
| True | True |
+-----------------+-----------------+
然而,由于 short-circuiting,Perl 并不总是计算 right-hand 端。真实案例如下:
+-----------------------------------+
| Logical AND |
+-----------------+-----------------+
| Left-hand side | Right-hand side |
+-----------------+-----------------+
| False | - |
| True | False |
| True | True |
+-----------------+-----------------+
+-----------------------------------+
| Logical OR |
+-----------------+-----------------+
| Left-hand side | Right-hand side |
+-----------------+-----------------+
| False | False |
| False | True |
| True | - |
+-----------------+-----------------+
Devel::Cover 正在报告这些输入组中的哪些已经过测试。
+--------------------------------------------------------+
| Logical AND |
+--------------------+-----------------+-----------------+
| Devel::Cover label | Left-hand side | Right-hand side |
+--------------------+-----------------+-----------------+
| !l | False | - |
| l && !r | True | False |
| l && r | True | True |
+--------------------+-----------------+-----------------+
+--------------------------------------------------------+
| Logical OR |
+--------------------+-----------------+-----------------+
| Devel::Cover label | Left-hand side | Right-hand side |
+--------------------+-----------------+-----------------+
| l | True | - |
| !l && r | False | True |
| !l && !r | False | False |
+--------------------+-----------------+-----------------+
如果我们查看链接页面的第一行,我们会看到
!l 2
l && !r 0
l && r 2
为
exists $self->{'true'} and exists $self->{'false'}
也就是说
!l meaning !(exists $self->{'true'}) was true 2 times.
l && !r meaning (exists $self->{'true'}) && !(exists $self->{'false'}) was true 0 times.
l && r meaning (exists $self->{'true'}) && (exists $self->{'false'}) was true 2 times.
这意味着从未测试过 (exists $self->{'true'}) && !(exists $self->{'false'})
为真。
cpancover.com 生成有关 Perl 模块代码覆盖率的报告。
我知道它只是一个使用 Devel::Cover 的网络服务器,但我想简单地理解报告的含义,例如: http://cpancover.com/latest/JSON-PP-4.02/blib-lib-JSON-PP-pm--condition.html
其中 table 的列如下:
- !l
- l&&!r
- l&&r
能否请您link一份相关文件来理解这一点,或者为我提供一些关于这些报告的初步指导?
这是文档的一部分,提供了有关报告格式的信息。
在覆盖测试中,如Devel::Cover
tells us,代码中可能有无法检查的地方:它们是"uncoverable"
Sometimes you have code which is uncoverable for some reason. Perhaps it is an else clause that cannot be reached, or a check for an error condition that should never happen. You can tell Devel::Cover that certain criteria are uncoverable and then they are not counted as errors when they are not exercised. In fact, they are counted as errors if they are exercised. [...]
处理这个可以考虑语句、分支、条件和子程序。您提供的示例报告处理条件,并且文档说
Because of the way in which Perl short-circuits boolean operations, there are three ways in which such conditionals can be uncoverable. In the case of
$x && $y
for example, the left operator may never be true, the right operator may never be true, and the whole operation may never be false. These conditions may be modelled thus:# uncoverable branch true # uncoverable condition left # uncoverable condition false if ($x && !$y) { $x++; # uncoverable statement } # uncoverable branch true # uncoverable condition right # uncoverable condition false if (!$x && $y) { }
通过这次讨论,linked 报告更有意义。
例如,这是我对您 link 中第一行的看法。这是一种 A && B
种情况,它涵盖了以下可能的情况:
left side false --- 覆盖在测试中(两个)
左真右假 --- 未涵盖
both left and right true --- covered (二)
然后我们点击 "line 214"(这是一个 link)并查看总体百分位数覆盖率(66 -- 三分之二)。颜色很明显,代码可以在 this page
上看到文档还说有多种报告格式,因此您可能想进一步了解。但是,我不太容易看到哪里可以看,我觉得有点不安。
l
和r
指表达式的right-hand边和left-hand边,数字代表关联表达式为真的次数。
例如下面的表达式有0
for l && !r
的覆盖率:
exists $self->{'true'} and exists $self->{'false'}
这意味着 0
测试涵盖了以下情况:
(exists $self->{'true'}) && !(exists $self->{'false'})
Logical-and 和 logical-or 有两个输入,可以分别取两个值。
+-----------------+-----------------+
| Left-hand side | Right-hand side |
+-----------------+-----------------+
| False | False |
| False | True |
| True | False |
| True | True |
+-----------------+-----------------+
然而,由于 short-circuiting,Perl 并不总是计算 right-hand 端。真实案例如下:
+-----------------------------------+
| Logical AND |
+-----------------+-----------------+
| Left-hand side | Right-hand side |
+-----------------+-----------------+
| False | - |
| True | False |
| True | True |
+-----------------+-----------------+
+-----------------------------------+
| Logical OR |
+-----------------+-----------------+
| Left-hand side | Right-hand side |
+-----------------+-----------------+
| False | False |
| False | True |
| True | - |
+-----------------+-----------------+
Devel::Cover 正在报告这些输入组中的哪些已经过测试。
+--------------------------------------------------------+
| Logical AND |
+--------------------+-----------------+-----------------+
| Devel::Cover label | Left-hand side | Right-hand side |
+--------------------+-----------------+-----------------+
| !l | False | - |
| l && !r | True | False |
| l && r | True | True |
+--------------------+-----------------+-----------------+
+--------------------------------------------------------+
| Logical OR |
+--------------------+-----------------+-----------------+
| Devel::Cover label | Left-hand side | Right-hand side |
+--------------------+-----------------+-----------------+
| l | True | - |
| !l && r | False | True |
| !l && !r | False | False |
+--------------------+-----------------+-----------------+
如果我们查看链接页面的第一行,我们会看到
!l 2
l && !r 0
l && r 2
为
exists $self->{'true'} and exists $self->{'false'}
也就是说
!l meaning !(exists $self->{'true'}) was true 2 times.
l && !r meaning (exists $self->{'true'}) && !(exists $self->{'false'}) was true 0 times.
l && r meaning (exists $self->{'true'}) && (exists $self->{'false'}) was true 2 times.
这意味着从未测试过 (exists $self->{'true'}) && !(exists $self->{'false'})
为真。