views:

351

answers:

2

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.

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.

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.

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

-- edit --

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.

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.

+1  A: 

Your header file doesn't contain executed code. Since nothing is executed (there's no executed code in a class declaration), there's nothing to measure, and nothing to cover.

lacqui
+2  A: 

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

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.

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.

Bill B