使用gcovr时,LCOV_EXCL_START / STOP无效

时间:2016-07-27 16:06:17

标签: gcov lcov gcovr

当我将LCOV_EXCL_START / STOP标记添加到我的C ++代码中时,它似乎对我的gcovr报告没有任何影响。

有人知道为什么会这样吗?

我有以下内容:

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

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

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

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

但第5行throw 1;包含在gcovr报告中,即使它被排除标记包围:

$ 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%
------------------------------------------------------------------------------

1 个答案:

答案 0 :(得分:2)

我已升级到gcovr版本3.4,现在可以使用。