mirror of
https://github.com/denoland/deno.git
synced 2025-03-03 09:31:22 -05:00
fix(coverage): ensure single line functions don't yield false positives (#9717)
This commit is contained in:
parent
33eea0400d
commit
3ec9a9bfe4
4 changed files with 22 additions and 22 deletions
|
@ -66,3 +66,6 @@ export function ƒ(): number {
|
|||
0
|
||||
);
|
||||
}
|
||||
|
||||
// This arrow function should also show up as uncovered.
|
||||
console.log("%s", () => 1);
|
||||
|
|
|
@ -47,6 +47,7 @@ DA:65,0
|
|||
DA:66,0
|
||||
DA:67,0
|
||||
DA:68,1
|
||||
DA:71,0
|
||||
LH:22
|
||||
LF:36
|
||||
LF:37
|
||||
end_of_record
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
cover [WILDCARD]/coverage/complex.ts ... 61.111% (22/36)
|
||||
cover [WILDCARD]/coverage/complex.ts ... 59.459% (22/37)
|
||||
46 | export function unused(
|
||||
47 | foo: string,
|
||||
48 | bar: string,
|
||||
|
@ -15,3 +15,5 @@ cover [WILDCARD]/coverage/complex.ts ... 61.111% (22/36)
|
|||
65 | return (
|
||||
66 | 0
|
||||
67 | );
|
||||
-----|-----
|
||||
71 | console.log("%s", () => 1);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue