为什么gcov在一个使用良好的类的头文件上报告0%的覆盖率? [英] Why does gcov report 0% coverage on a header file for a well used class?

查看:806
本文介绍了为什么gcov在一个使用良好的类的头文件上报告0%的覆盖率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用 gcov 首次测试测试覆盖率。现在,我已经超过了初始的学习曲线,事情似乎进展顺利,除了一个小陷阱。我期望它归结为我对我的缺乏理解,所以我希望有人熟悉gcov可以解释发生了什么。

I'm attempting to measure test coverage for the first time using gcov. Now that I'm past the initial learning curve, things seem to be going well, except for one little snag. I expect that it boils down to a lack of understanding on my part, so I'm hoping someone familiar with gcov can explain what's going on.

问题是,我有一个特定的头文件显示0%的覆盖率。然而,该头部中的只有事物是一个良好使用的类的类声明。

The issue is that I have one particular header file showing 0% coverage. However the only thing in that header is a class declaration for a well-used class.

此外,该类的实现文件显示了100%的覆盖率,我可以指向5个不同的测试,我知道该类正在成功实例化。

In addition, The implementation file for the class shows 100% coverage, and I can point to 5 different tests where I know for a fact that the class is being successfully instantiated.

那么为什么gcov会在类上报告0%的覆盖,我该如何解决呢?

So why would gcov report 0% coverage on the class, and how can I fix it?

- edit -

-- edit --

正如lacqui在下面指出的,如果标题没有可执行代码,它不应该包括在coverage计算中。事实上,在我的所有类中,特定的头文件是gcov尝试生成覆盖信息的唯一一个。

As lacqui pointed out below, if the header has no executable code, it shouldn't be included in coverage calculations. And in fact, out of all of my classes, that particular header file is the only one that gcov is trying to generate coverage information for.

我已经与其他头文件进行了逐行比较,我发现最大的区别是,这个特定的头没有显式的构造函数或析构函数,而其他人。为了尽量减少文件之间的差异,我向问题类添加了一个显式的ctor和dtor。然而,这没有什么区别。

I've done a line-by-line comparison with the other headers, and the biggest difference I found was that this particular header does not have an explicit constructor or destructor, while the others do. In an attempt to minimize the differences between the files, I added an explicit ctor and dtor to the problem class. However, this did not make any difference.

推荐答案

看起来我已经整理出问题。正如我所料,这是一个缺乏经验的问题,比任何事情。

It looks like I've sorted out the problem. As I expected, it's more of a lack-of-experience issue, than anything.

事实证明,gcov只找到一个可用的tracefiles的子集,因此只报告了总结果的一部分。查找和添加其余的tracefiles解决了问题。

As it turns out, gcov was only finding a subset of the available tracefiles, and was therefore reporting only part of the total results. Finding and adding the rest of the tracefiles resolved the issue.

对于任何好奇的,有问题的头文件仍然显示在输出中。实际上,所有其他头文件也做,即使它们不包含可执行代码。但是,它们都显示90 +%的覆盖率。

For any that are curious, the problematic header file still shows up in the output. In fact, all of the other header files do too, even though they contain no executable code. However, they all show 90+% coverage.

这篇关于为什么gcov在一个使用良好的类的头文件上报告0%的覆盖率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆