New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why are branches that are never executed ignored? #28

Merged
merged 1 commit into from Jul 3, 2014

Conversation

Projects
None yet
3 participants
@nschum
Contributor

nschum commented May 7, 2014

I've noticed the Cobertura Jenkins plugin reporting high conditional coverage for a poorly tested project. Further investigation revealed that all untested files reported no (and I don't mean 0%) conditional coverage, so the aggregated result only included already-tested files, which inflated the average.

The reason is that gcovr simply doesn't report these branches:

try:
    count = int(fields[3])
    branches.setdefault(lineno, {})[int(fields[1])] = count
except:
    # We ignore branches that were "never executed"
    pass

If I replace that with:

fields = line.split()
try:
    count = int(fields[3])
except:
    count = 0
branches.setdefault(lineno, {})[int(fields[1])] = count

I got the 0% coverage number for these files and the shamefully low aggregated result I was expecting.

Why are never executed branches currently skipped?

@nschum

This comment has been minimized.

Contributor

nschum commented May 7, 2014

I noticed that the HTML also reports unexecuted files as "100% (0/0)" covered. With my change it becomes e.g. "0% (0/38)", which is what I expect.

If really nobody can explain the reason, maybe I should just turn this into a pull request?

@mr-c

This comment has been minimized.

mr-c commented May 7, 2014

As a fellow user I'd appreciate a pull request so I could locally incorporate this change.

nschum added a commit to nschum/gcovr that referenced this pull request May 7, 2014

@nschum

This comment has been minimized.

Contributor

nschum commented May 7, 2014

Alright, this is now a pull request.

@mr-c

This comment has been minimized.

mr-c commented May 13, 2014

Thanks, this gives me results that better match my expectations.

whart222 added a commit that referenced this pull request Jul 3, 2014

Merge pull request #28 from nschum/never-executed-branches
Why are branches that are never executed ignored?

@whart222 whart222 merged commit 117b98b into gcovr:master Jul 3, 2014

whart222 added a commit that referenced this pull request Jul 3, 2014

Updating test example to demonstrate fix in #28
Pull request #28 did not contain an example that demonstrated
this fix.  I modified the files in the 'nested' test example (which
is also used by the 'linked' test example).  This illustrates
correct statistics for branches that are not executed.

JamesReynolds pushed a commit to JamesReynolds/gcovr that referenced this pull request Mar 8, 2018

JamesReynolds pushed a commit to JamesReynolds/gcovr that referenced this pull request Mar 8, 2018

Merge pull request gcovr#28 from nschum/never-executed-branches
Why are branches that are never executed ignored?

JamesReynolds pushed a commit to JamesReynolds/gcovr that referenced this pull request Mar 8, 2018

Updating test example to demonstrate fix in gcovr#28
Pull request gcovr#28 did not contain an example that demonstrated
this fix.  I modified the files in the 'nested' test example (which
is also used by the 'linked' test example).  This illustrates
correct statistics for branches that are not executed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment