LCOV_EXCL_START/STOP has no effect when using gcovr
Asked Answered
C

2

1

When I add LCOV_EXCL_START/STOP tags to my C++ code, it does not seem to have any effect on my gcovr report.

Does someone know why this occurs?

I have the following:

$ tree
.
├── build
├── include
│   └── a.h
└── tests
    └── test_a.cpp

and

$ cat include/a.h 
void f (bool x)
{
    // LCOV_EXCL_START
    if (x)
        throw 1;
    // LCOV_EXCL_STOP
}

and

$ cat tests/test_a.cpp 
#include "a.h"

int main ()
{
    f (false);
    return 0;
}

But line 5 throw 1; is included in the gcovr report, even though it is surrounded in exclude tags:

$ g++ -c -O0 -fprofile-arcs -ftest-coverage -fPIC --coverage -I include ./tests/test_a.cpp -o ./build/test_a.o
$ g++ ./build/test_a.o -o ./build/test_a -lgcov
$ ./build/test_a
$ gcovr -r .
------------------------------------------------------------------------------
                           GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File                                       Lines    Exec  Cover   Missing
------------------------------------------------------------------------------
include/a.h                                    4       3    75%   5
tests/test_a.cpp                               3       3   100%   
------------------------------------------------------------------------------
TOTAL                                          7       6    85%
------------------------------------------------------------------------------
Cracow answered 27/7, 2016 at 16:6 Comment(7)
As a start, try adding // GCOV_EXCL_LINE after throw 1; - i.e. all on the same line. Does that make any difference?Flatulent
@Flatulent I tried it, but it makes no difference.Cracow
Have you tried that and removing // LCOV_EXCL_START and // LCOV_EXCL_STOP? Clutching here..Flatulent
@Flatulent Yes, I've tried that. Thanks for the suggestion. Strange isn't it?Cracow
@Flatulent However, if make the directory structure flat, it works.Cracow
Did you resolve this?Flatulent
@Flatulent No, it was never resolved.Cracow
C
2

I upgraded to gcovr version 3.4, and it works now.

Cracow answered 23/9, 2016 at 18:24 Comment(0)
M
0

I tried to check these couple marks (//LCOV_EXCL_START , //LCOV_EXCL_STOP) with gcov version: 9.4.0. And It works well

Moussorgsky answered 14/6, 2023 at 8:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.