1
我開發了一個簡單的例子來測試gcovr和gcov的:Gcovr分支覆蓋了簡單的情況下
#include <iostream>
int main (int argc, const char * argv[])
{
std::cout << argc << std::endl;
if(argc == 1)
{
int y = 1;
std::cout << "Argc > 1" << std::endl;
}
if(argc == 2) std::cout << "Argc > 2" << std::endl;
if(argc == 3)
{
std::cout << "Argc > 3" << std::endl;
}
int i = 34;
i = i * i;
return 0;
}
而對於覆蓋報告生成的腳本:
#! /bin/bash
rm -rf build-run
mkdir build-run
cd build-run
g++ -O6 -DDEBUG=0 --coverage -ftest-coverage -fprofile-arcs -c -o main.o ../main.cpp
g++ -O6 -DDEBUG=0 --coverage -fprofile-arcs -ftest-coverage -lgcov -o coverage ./main.o
./coverage > out
./coverage --help > out
./coverage --help --out > out
gcovr -v -kpbu -r .. -o ../branch-report.txt
gcovr -v -kpu -r .. -o ../report.txt
我使用-b得到覆蓋率達80%選項,它指向我在主要塊的最後一行。在我看來,這種情況應該是100%呢?