Skip to content

Commit 985c287

Browse files
committed
fix(ci): require complete LCOV line summaries
1 parent c641475 commit 985c287

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

‎src/scripts/verify-lcov.mjs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,28 @@ import { fileURLToPath } from "node:url"
55
export 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
}

‎src/scripts/verify-lcov.spec.mjs‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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"],

0 commit comments

Comments
 (0)