perl - cpancover.com 的 Perl 模块覆盖率报告

标签 perl code-coverage cpan

cpancover.com 生成有关 Perl 模块代码覆盖率的报告。

我知道这只是一个使用 Devel::Cover 的网络服务器,但我想简单地了解以下报告的含义: http://cpancover.com/latest/JSON-PP-4.02/blib-lib-JSON-PP-pm--condition.html

其中表格包含如下列:

  • !l
  • l&&!r
  • l&&r

您能否链接相关文档以了解这一点或为我提供一些有关这些报告的初步指导?

最佳答案

这是文档的一部分,提供有关报告格式的信息。

在覆盖率测试中,如Devel::Cover tells us ,代码中可能存在无法检查的地方:它们是“不可覆盖的”

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) {
}

通过这次讨论,链接的报告更有意义。

例如,以下是我对链接中第一行的看法。这是一种 A && B 类型的条件,它涵盖了以下可能的情况:

  • 左侧 false --- 包含在测试中(二)

  • 左为真,右为假 --- 覆盖

  • 左右皆真---覆盖(二)

然后我们单击“第 214 行”(这是一个链接)并查看总体百分位覆盖率(66 - 三分之二)。颜色很能说明问题,代码可以在 this page 上看到。

文档还说有多种报告格式,因此您可能需要进一步挖掘。然而,我不太清楚该去哪里寻找,我觉得有些令人不安。

关于perl - cpancover.com 的 Perl 模块覆盖率报告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56026357/

相关文章:

arrays - 迭代数据数组/哈希

perl - < UNIX 中的运算符,传递给 Perl 脚本

Perl 构建、单元测试、代码覆盖率 : A complete working example

perl - 使用 Dist::Zilla dist.ini 如何获得仅用于测试的文件?

perl - 如何使用 LWP 显式设置 cookie

regex - Perl - 正则表达式、条件语句并根据不一致的字符串匹配多个对象

perl - cpan对.local目录的使用可以重定向吗?

windows - 为 CPAN(和 CorporatePAN)打包 perl 脚本的推荐方法是什么?

c++ - 从断言调用时缺少 llvm-cov 覆盖

Meteor-coverage 似乎将执行的语句显示为未覆盖