我想知道是否有可能告诉 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/