fix(coverage): ensure single line functions don't yield false positives (#9717)

This commit is contained in:
Casper Beyer 2021-03-08 18:51:01 +08:00 committed by GitHub
parent 33eea0400d
commit 3ec9a9bfe4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 22 deletions

View file

@ -295,22 +295,19 @@ impl CoverageReporter for LcovCoverageReporter {
}
}
// Reset the count if any block intersects with the current line has a count of
// zero.
//
// We check for intersection instead of inclusion here because a block may be anywhere
// inside a line.
// We reset the count if any block with a zero count overlaps with the line range.
for function in &script_coverage.functions {
for range in &function.ranges {
if range.count > 0 {
continue;
}
if (range.start_offset < *line_start_offset
&& range.end_offset > *line_start_offset)
|| (range.start_offset < *line_end_offset
&& range.end_offset > *line_end_offset)
{
let overlaps = std::cmp::max(line_end_offset, &range.end_offset)
- std::cmp::min(line_start_offset, &range.start_offset)
< (line_end_offset - line_start_offset)
+ (range.end_offset - range.start_offset);
if overlaps {
count = 0;
}
}
@ -435,22 +432,19 @@ impl CoverageReporter for PrettyCoverageReporter {
}
}
// Reset the count if any block intersects with the current line has a count of
// zero.
//
// We check for intersection instead of inclusion here because a block may be anywhere
// inside a line.
// We reset the count if any block with a zero count overlaps with the line range.
for function in &script_coverage.functions {
for range in &function.ranges {
if range.count > 0 {
continue;
}
if (range.start_offset < *line_start_offset
&& range.end_offset > *line_start_offset)
|| (range.start_offset < *line_end_offset
&& range.end_offset > *line_end_offset)
{
let overlaps = std::cmp::max(line_end_offset, &range.end_offset)
- std::cmp::min(line_start_offset, &range.start_offset)
< (line_end_offset - line_start_offset)
+ (range.end_offset - range.start_offset);
if overlaps {
count = 0;
}
}