How to show True/False Condition on Branch Coverage on Gcovr

I've been trying to get which condition on a branch my executed test case took. For example, this is a snip of the coverage information I got from Gcov's gcov -b (I also use -i option for readability):

lcount:10,1
branch:10,nottaken 
branch:10,taken    

After examining some samples, it seems that the true condition always written first on every branch information. Which means I can determine whether the executed test case take the true part or false part of the branch. And in this case, the test case took the false part of the branch on line 10.

Now, here is a snip from a generated xml by Gcovr's --branches and --xml of the same program and test case:

<line branch="true" condition-coverage="50% (1/2)" hits="1" number="10">
   <conditions>
      <condition coverage="50%" number="0" type="jump"/>
   </conditions>
</line>

Here, I can't figure out which part of the branch was taken.

Is there any options on Gcovr that I can use?


The gcovr XML output uses the Cobertura XML format that is understood by a variety of other tools. This means gcovr is limited to that XML schema, and cannot include extra information.

Gcovr's HTML reports ( --html-details ) display branch coverage. To see which branches are uncovered, it is often easiest to see which statements in the conditional branches are uncovered. However, the branch coverage column also displays small icons that indicate which branches were taken. There is one indicator per branch / two per condition. A green ✔ indicates a covered branch, a red ✘ an uncovered branch.

In the above example, the first branch is uncovered. Whether the first branch corresponds to a true or false condition is not defined. If in doubt, rewrite your code to only use statement-level conditionals (no … ? … : … , && , || operators) so that all branches are separate statements. Note that in C++, exception handling can introduce additional branches that may be difficult/impossible to cover.

Tip: the --branch option is unnecessary to get branch coverage. It only controls whether the gcovr text report shows branch or line coverage.

链接地址: http://www.djcxy.com/p/51016.html

上一篇: 为什么类不能用相同签名的方法扩展特征?

下一篇: 如何在Gcovr上显示分支覆盖的真/假条件