binhonglee / coco

Code coverage for Nim lang (CLI + library)
MIT License
46 stars 3 forks source link

option for branch coverage (instead of line coverage) #3

Closed timotheecour closed 5 years ago

timotheecour commented 5 years ago

see my previous forum post https://forum.dlang.org/thread/mailman.3083.1517859192.9493.digitalmars-d@puremagic.com (-cov LOC is inadequate for 1 liner branching; need a metric based on branching) which applies to Nim as well

EDIT some more motivation: branch coverage is much more useful than line coverage because line coverage tends to overcount, eg:

proc foo(bar: int)=
  if bar == 1:
    # suppose this has 100 lines of code
  else:
     echo "baz"
foo(1)

with LOC (line of code) coverage, coverage is 103/105 = almost 100% with branch coverage, coverage is 50% (need to check that number) in terms of making sure unittests/tests cover a codebase, it's irrelevant how large is each code block and branch coverage is the correct metric to track.

samuelroy commented 5 years ago

For myself:

Add --rc lcov_branch_coverage=1 to every lcov invocation and add the flag --branch-coverage to the command genhtml.

samuelroy commented 5 years ago

Use the flag -b to enable branch mode. See the latest readme.