I am configuring and testing source code coverage by the various tests . And sonarqube
he shows me totally incomprehensible results.
For example, this piece of code:
auto node_number = adjacencyMatrix.n_cols;
std::vector<bool> visited( node_number, false );
std::vector<std::vector<uword> > islands;
decltype( islands.size( ) ) island_idx = 0;
std::vector<uword> stack( node_number );
for ( uword node = 0; node < node_number; ++node ) {
// Visited yet. Nothing.
if ( !visited[ node ] ) {
islands.emplace_back( );
It is placed right at the beginning of one of the functions to be tested , and that function has a single argument. The first 5 lines shown are simple statements with initial assignment.
However, sonarqube
he tells me that the coverage of the file is 38%, when I know that the test covers all the functions . In fact, he tells me that this line
std::vector<uword> stack( node_number );
is partially covered , when it is a simple declaration ! And even if we took into account all the possible calls to the constructor, it still wouldn't add up: the constructor ofstd::vector< >
has 9 possible ways to be invoked.
I understand that sonarqube
he does nothing more than make beautiful the data he collects from the input file. I am generating the latter like this:
gcovr -r . -k --xml-pretty -o report.xml
And the compilations of the different translation units are done, ultimately, like this:
g++ -g -Wall -Wpedantic -Wextra -Og -g3 -ggdb -fprofile-arcs -ftest-coverage -std=c++17
What would be the correct interpretation of this coverage test ?
Am I using the correct arguments when compiling and calling gcovr
?
Templates are compiled when the compiler finds a use for them. That is, the source code of the templates is always public .
On the other hand, the standard only requires (for simplicity) that the STL classes have a specific interface, that is, it does not interfere in the implementation of these classes, which is free.
What happens here is that the constructor
std::vector
ends up calling a conditional at some point and sonarqube detects that not all possible paths offered by the code are being verified. What conditional is it? Where is it? No idea. As I have told you, the implementation of the STL is free. It is quite likely that if you try it with another compiler the message will be different (or even none at all).The STL is something proven and robust. It should work without problems. Errors that refer to STL calls can be ignored (as a general rule).
It has nothing to do with it. It is a message due to the specific implementation of
std::vector