Refactor getLinesToBeIgnored() so it can work with branch/path data #757
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
For #380
Hello @sebastianbergmann
Take the example code below from the test suite
That is easy to understand when dealing with line based coverage (ignore lines 4-9), and also with branch/path coverage (ignore all functions in the class).
However, it is possible to specify that individual lines should be ignored, not just whole functions e.g.
Branch/path coverage in this situation is much less obvious. There are 2 possible solutions (1) disallow ignoring branch/path coverage for only part of a function (2) treat the annotation as referring to the branch it's found in, and ignore that.
Option 2 sounds much better to me and is what I'm implementing. However, in testing I've found that
getLinesToBeIgnored()
performs 2 different types of "ignore". The first is the type above, where the code being tested explicitly asks for it. The second is code that ignores any source lines that aren't executable, which AFAICT exists solely for the purpose of dealing with the output ofaddUncoveredFilesFromWhitelist()
even though it's called on every iteration.This has consequences when trying to implement option 2 because blank/empty lines are considered non-executable under line based coverage. Ignoring every branch that includes a blank line means that most become accidentally ignored.
For paths, a similar undesirable effect happens with the function declaration - under line based coverage this is considered non-executable, however under path coverage the entry into the function is considered to be the line with the declaration on it. Since every possible path starts at function entry the current version of
getLinesToBeIgnored()
has the side effect of removing literally every single one!To handle this, I've split the
getLinesToBeIgnored()
logic that exists to handleaddUncoveredFilesFromWhitelist()
into a seperate function. This logic exists to operate on line based coverage only and can be segregated. The remaining logic handles code annotations only and can therefore be used on both line and branch/path coverage.There is one minor change to coverage as a result of this split, and that is handling of the keyword "function". Previously any line featuring this was always ignored, now it is only ignored when adding uncovered files. This means that in covered files, lines declaring anonymous functions are now included in the line coverage data rather than excluded. This seems correct to me anyway.