File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,18 +5,28 @@ import { fileURLToPath } from "node:url"
55export function verifyLcov ( content ) {
66 let inRecord = false
77 let anyCovered = false
8+ let hasLinesFound = false
9+ let hasLinesHit = false
810
911 for ( const line of content . split ( / \r ? \n / ) ) {
1012 if ( line . startsWith ( "SF:" ) ) {
1113 if ( inRecord ) throw new Error ( "LCOV source record is not terminated" )
1214 inRecord = true
15+ hasLinesFound = false
16+ hasLinesHit = false
17+ } else if ( line . startsWith ( "LF:" ) ) {
18+ if ( ! inRecord ) throw new Error ( "LCOV line count is outside a source record" )
19+ if ( ! / ^ \d + $ / . test ( line . slice ( 3 ) ) ) throw new Error ( "LCOV line count is not a decimal integer" )
20+ hasLinesFound = true
1321 } else if ( line . startsWith ( "LH:" ) ) {
1422 if ( ! inRecord ) throw new Error ( "LCOV hit count is outside a source record" )
1523 const hits = line . slice ( 3 )
1624 if ( ! / ^ \d + $ / . test ( hits ) ) throw new Error ( "LCOV hit count is not a decimal integer" )
1725 if ( BigInt ( hits ) > 0n ) anyCovered = true
26+ hasLinesHit = true
1827 } else if ( line === "end_of_record" ) {
1928 if ( ! inRecord ) throw new Error ( "LCOV terminator is outside a source record" )
29+ if ( ! hasLinesFound || ! hasLinesHit ) throw new Error ( "LCOV source record has incomplete line summaries" )
2030 inRecord = false
2131 }
2232 }
Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ describe("verifyLcov", () => {
1212 [ "a zero-hit report" , "SF:file.ts\nLF:1\nLH:0\nend_of_record\n" ] ,
1313 [ "a hit count outside a record" , "LH:1\n" ] ,
1414 [ "a terminator outside a record" , "end_of_record\n" ] ,
15+ [ "a record without lines found" , "SF:file.ts\nLH:1\nend_of_record\n" ] ,
1516 [ "an infinite hit count" , "SF:file.ts\nLH:Infinity\nend_of_record\n" ] ,
1617 [ "a fractional hit count" , "SF:file.ts\nLH:1.5\nend_of_record\n" ] ,
1718 [ "an exponential hit count" , "SF:file.ts\nLH:1e3\nend_of_record\n" ] ,
You can’t perform that action at this time.
0 commit comments