问题描述
我使用gcov来测量我的C ++代码的覆盖率。我想得到100%的覆盖,但是阻碍了这样的事实,有一些代码在理论上是不可击的(需要实现的方法,但是从来不调用,默认分支 switch
语句等)。每个分支都包含一个 assert(false);
语句,但gcov仍然将它们标记为未命中。
I'm using gcov to measure coverage in my C++ code. I'd like to get to 100% coverage, but am hampered by the fact that there are some lines of code that are theoretically un-hittable (methods that are required to be implemented but which are never called, default branches of switch
statements, etc.). Each of these branches contains an assert( false );
statement, but gcov still marks them as un-hit.
我想能够告诉gcov忽略这些分支。有没有办法给gcov的信息 - 通过注释源代码或任何其他机制?
I'd like to be able to tell gcov to ignore these branches. Is there any way to give gcov that information -- by annotating the source code, or by any other mechanism?
推荐答案
lcov。它隐藏gcov的复杂性,产生不错的输出,允许每次测试的详细输出,特征容易的文件过滤和已经审查的行的ta-taa线标记:
Please use lcov. It hides gcov's complexity, produces nice output, allows detailed output per test, features easy file filtering and - ta-taa - line markers for already reviewed lines:
从geninfo 1):
From geninfo(1):
- LCOV_EXCL_LINE
- 排除包含此标记的行。
- 标记排除部分的开头。当前行是此部分的一部分。
- 标记结束的排除部分。当前行不是此部分的一部分。
这篇关于如何告诉gcov忽略未命中的C ++代码行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!