diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-03-08 18:51:01 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-08 11:51:01 +0100 |
commit | 3ec9a9bfe4137f57df648ec5664725f96c9ef8d4 (patch) | |
tree | b5a5c889dabba89be68a1311e8447893bff6920a /cli/tools/coverage.rs | |
parent | 33eea0400d6b72d84c8fe80d1fbf9f02723187fb (diff) |
fix(coverage): ensure single line functions don't yield false positives (#9717)
Diffstat (limited to 'cli/tools/coverage.rs')
-rw-r--r-- | cli/tools/coverage.rs | 34 |
1 files changed, 14 insertions, 20 deletions
diff --git a/cli/tools/coverage.rs b/cli/tools/coverage.rs index eb7c5e932..9e97688a3 100644 --- a/cli/tools/coverage.rs +++ b/cli/tools/coverage.rs @@ -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; } } |