c++ - 如何告诉 lcov 忽略源文件中的行

标签 c++ c code-coverage lcov

我想知道是否有可能告诉 lcov 忽略源文件中的某些行,即。不要将它们报告为未访问过。我正在寻找可以放入代码本身的解决方案,例如:

int some_method(char some_var, char some_other_var)
{
    if(some_var == 'A')
    {
         if(some_other_var == 'B')
         {
               /* do some real stuff here */
         }
         else
         {
                LCOV_DO_NOT_REPORT_NEXT_LINE // **<-- this?? **
                NOT_IMPLEMENTED("A*")
         }
    }
    else
    {
         NOT_IMPLEMENTED("*")
    }

以及必要的背景:

像上面这样的一大段代码正在一系列单元测试中进行测试,但由于这段代码仍在开发中,所以有很多 NOT_IMPLEMENTED("A*") 宏它只是在屏幕上显示一条消息,其中包含行号/文件名,然后退出应用程序。没有针对未实现的分支进行测试,显然它们将在实现功能时编写。

但是 lcov 报告了这些 NOT_IMPLEMENTED 行,它们在覆盖率报告中看起来非常丑陋(即:它们的红线比例很高)。

我的要求是可行的,还是我们应该忍受这个?

最佳答案

您可以在源代码中使用以下内容作为注释。

来自 http://ltp.sourceforge.net/coverage/lcov/geninfo.1.php

  • LCOV_EXCL_LINE
    • Lines containing this marker will be excluded.
  • LCOV_EXCL_START
    • Marks the beginning of an excluded section. The current line is part of this section.
  • LCOV_EXCL_STOP
    • Marks the end of an excluded section. The current line not part of this section.

关于c++ - 如何告诉 lcov 忽略源文件中的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23264049/

相关文章:

c++ - 如何创建具有任意数量(编译时确定)容器的内存池?

C++ : How does Virtual Function resolve "this" pointer scope issue?

testing - 是否仍然没有使用 cobertura-maven-plugin 忽略 setter/getter(其他琐碎的方法)的解决方案?

c# - 无法将下载的代码覆盖工具转换为 XML

c++ - 在 C++ 中访问程序外的变量

c++ - 二叉搜索树验证的空间复杂度

c - 在c中传递数组元素指针

c - C 中的多队列

c - 如何防止Socket服务器断开连接

python - Django 测试覆盖率与代码覆盖率