Skip to content

Commit

Permalink
fix(coverage): Do not emit error on BRDA:0 entries
Browse files Browse the repository at this point in the history
Coverage report generators in Coverage.py would generate BRDA:0 for
exit branches.

Ref: https://github.com/nedbat/coveragepy/blob/5467e1f/coverage/lcovreport.py#L108-L112

Also small string fixes for error messages in BRDA.

Improves #362.
  • Loading branch information
cwahbong committed Oct 16, 2024
1 parent b4a8b0c commit 663d870
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/test-explorer/lcov_parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,23 +330,27 @@ export async function parseLcov(
if (!match) {
throw new Error(`Invalid FNDA entry`);
}
const lineNumber = Number.parseInt(match[1], 10) - 1;
if (lineNumber < 0) {
throw new Error("Negative line number in DA entry");
const lineNumber1 = Number.parseInt(match[1], 10);
if (lineNumber1 < 0) {
throw new Error("Negative line number in BRDA entry");
}
// There might be BRDA:0 for exiting branch in report generated by
// Coverage.py. Simply drop these entries.
if (lineNumber1 === 0) break;
const lineNumber = lineNumber1 - 1;
const isException = match[2] === "e";
const blockId = Number.parseInt(match[3], 10);
const rest = match[4];
const commaOffset = rest.lastIndexOf(",");
if (commaOffset === undefined) {
throw new Error(`Invalid FNDA entry`);
throw new Error(`Invalid BRDA entry`);
}
const label = rest.substring(0, commaOffset);
const hitCountStr = rest.substring(commaOffset + 1);
const hitCount =
hitCountStr === "-" ? 0 : Number.parseInt(hitCountStr, 10);
if (hitCount < 0) {
throw new Error("Negative hit count in DA entry");
throw new Error("Negative hit count in BRDA entry");
}

if (info === undefined) {
Expand Down
4 changes: 4 additions & 0 deletions test/lcov_parser.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ describe("The lcov parser", () => {
assert.equal(coveredFiles[0].declarationCoverage.total, 1);
});

it("ignores invalid line numbers", async () => {
assert.deepEqual(await parseTestLcov("BRDA:0,0,0,b"), []);
});

describe("parses Java coverage data:", () => {
let fileCov: BazelFileCoverage;
before(async () => {
Expand Down

0 comments on commit 663d870

Please sign in to comment.