I have created a simple example to illustrate the issue:
test.h
#ifndef TEST_H
#define TEST_H
class TestCoverage{
public:
/*
*
*
*
*/
int a = 5;
int b = 10;
void testfunc();
explicit TestCoverage();
};
#endif // TEST_H
test.cpp
#include "test.h"
#include <iostream>
TestCoverage::TestCoverage()
{
a=15;
b=20;
}
void TestCoverage::testfunc(){
/*
*
* */
std::cout<<"hey";
}
And added a simple test case (which checks nothing) using catch2:
test_test.cpp
#include "test.h"
#include <catch2/catch.hpp>
TEST_CASE("test", "[whatever]")
{
auto testCoverage = new TestCoverage();
testCoverage->testfunc();
}
Afterwards I generated a code coverage report using lcov and generated html file. Html file shows some strange results:
The question is: why lines 11 and 12 are displayed as covered? It looks like they are completely mirroring the class member initialization in the header file (a and b initialization). If I move initialization across the header file - the covered lines in the cpp file also move. Is this a bug in lcov or am I missing something?
UPD: If I build coverage with slightly updated header file, e.g.:
#ifndef TEST_H
#define TEST_H
class TestCoverage{
public:
/*
*
*
*
*/
int a = 5;
void testfunc();
int b = 10;
explicit TestCoverage();
};
#endif // TEST_H
I get report like this: lcov report upd
Note that I swapped lines 12 and 13 in the header file and it is reflected in the report file. In the report file line 12 appears as not covered and line 13 as covered