0
當我將LCOV_EXCL_START/STOP標記添加到我的C++代碼中時,它似乎對我的gcovr報告沒有任何影響。使用gcovr時,LCOV_EXCL_START/STOP沒有任何作用
有人知道爲什麼會發生這種情況嗎?
我有以下幾點:
$ 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%
------------------------------------------------------------------------------
作爲一個開始,嘗試在throw 1之後添加'// GCOV_EXCL_LINE'; - 即全部在同一行上。這有什麼區別嗎? – ksl
@ksl我試過了,但沒有區別。 – jsp
您是否嘗試過*並*刪除了// LCOV_EXCL_START和LCOV_EXCL_STOP?抓住這裏.. – ksl