Skip to content

Commit 667c94c

Browse files
committed
Address review comments; still need to add more test
1 parent 8beed50 commit 667c94c

File tree

8 files changed

+33
-92
lines changed

8 files changed

+33
-92
lines changed

assembly/diytest.ts

-24
This file was deleted.

src/generator/html-generator/genCode.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { CodeCoverage, FileCoverageResult, OrganizationName, Repository } from "../../interface.js";
1+
import { CodeCoverage, FileCoverageResult, UncoveredLines, OrganizationName, Repository } from "../../interface.js";
22
import { escape } from "../../utils/escape.js";
33

44
function generateLineCount(totalLines: number): string {
@@ -23,10 +23,10 @@ function generateLineCoverage(codes: CodeCoverage[]): string {
2323
return str.join("\n");
2424
}
2525

26-
function generateSource(codes: CodeCoverage[], result: FileCoverageResult): string {
26+
function generateSource(codes: CodeCoverage[], uncoveredlines: UncoveredLines): string {
2727
const str: string[] = [];
2828
for (const [index, code] of codes.entries()) {
29-
if (result.linesToHighlight.has(index + 1)) {
29+
if (uncoveredlines.has(index + 1)) {
3030
// IMPORTANT! to add "nocode" here to preventing prettify from adding unwanted pln class
3131
str.push('<span class="missing-if-branch nocode" title="Branch not taken">!</span>' + escape(code.source));
3232
}
@@ -42,7 +42,7 @@ export function generateCodeHtml(relativePathofRoot: string, result: FileCoverag
4242

4343
const lineCoutHtml = generateLineCount(codes.length);
4444
const lineCov = generateLineCoverage(codes);
45-
const lineSource = generateSource(codes, result);
45+
const lineSource = generateSource(codes, result.uncoveredlines);
4646

4747
return `
4848
<!DOCTYPE html>

src/interface.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ export type FunctionIndex = number;
1616
export type LineIndex = number;
1717
export type ColumnIndex = number;
1818
export type FileIndex = number;
19+
export type UncoveredBasicBlocks = Set<CodeSnippetIndex>;
20+
export type UncoveredLines = Set<LineIndex>;
1921

2022
// input cov
2123
export type BranchInfo = [CodeSnippetIndex, CodeSnippetIndex];
@@ -87,13 +89,13 @@ export class FileCoverageResult {
8789
functionCoverageRate: Rate = new Rate();
8890
lineCoverageRate: Rate = new Rate();
8991
sourceUsedCount: CodeCoverage[] = [];
90-
linesToHighlight: Set<number> = new Set();
92+
uncoveredlines: Set<number> = new Set();
9193
}
9294

9395
export class FunctionCoverageResult {
9496
constructor(public functionName: string) {}
9597
branchCoverageRate: Rate = new Rate();
96-
linesToHighlight: Set<number> = new Set();
98+
uncoveredlines: UncoveredLines = new Set();
9799
lineRange: [number, number] = [Number.MAX_SAFE_INTEGER, Number.MIN_SAFE_INTEGER];
98100
/**
99101
* first means lineIndex;
@@ -113,7 +115,7 @@ export class FunctionCoverageResult {
113115
];
114116
result.branchCoverageRate = Rate.summarize(infos.map((info) => info.branchCoverageRate));
115117
for (const info of infos) {
116-
info.linesToHighlight.forEach(line => result.linesToHighlight.add(line));
118+
info.uncoveredlines.forEach(line => result.uncoveredlines.add(line));
117119
for (const [lineIndex, count] of info.sourceUsedCount.entries()) {
118120
const srcLineUsedCount = result.sourceUsedCount.get(lineIndex);
119121
result.sourceUsedCount.set(lineIndex, srcLineUsedCount === undefined ? count : srcLineUsedCount + count);

src/parser/singleFileAnalysis.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export class SingleFileCoverageAnalysis {
3030
// SingleFileCoverageAnalysis contains FileCoverageResult
3131
if (results.length === 0) return;
3232
for (const functionCovResult of results) {
33-
functionCovResult.linesToHighlight.forEach(line => this.result.linesToHighlight.add(line));
33+
functionCovResult.uncoveredlines.forEach(line => this.result.uncoveredlines.add(line));
3434
for (const [lineIndex, count] of functionCovResult.sourceUsedCount.entries()) {
3535
const srcLineUsedCount = this.result.sourceUsedCount[lineIndex - 1];
3636
if (srcLineUsedCount === undefined) {

src/parser/singleFunctionAnalysis.ts

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import assert from "node:assert";
2-
import { CodeSnippetIndex, CovInfo, FunctionCoverageResult } from "../interface.js";
2+
import { CodeSnippetIndex, CovInfo, FunctionCoverageResult, UncoveredBasicBlocks } from "../interface.js";
33

44
type BranchGraph = Map<number, Map<number, boolean>>;
55

66
export class SingleFunctionCoverageAnalysis {
77
result: FunctionCoverageResult;
88
branchGraph: BranchGraph = new Map();
9-
notFullyCoveredBasicBlock: Set<number> = new Set();
9+
notFullyCoveredBasicBlock: UncoveredBasicBlocks = new Set();
1010
constructor(
1111
public covInfo: CovInfo,
1212
name: string
@@ -73,28 +73,22 @@ export class SingleFunctionCoverageAnalysis {
7373
toNodes.set(second, true);
7474
}
7575
}
76-
for (const toNodes of this.branchGraph) {
77-
let [currentBasicBlock, branchesForThatBasicBlock] = toNodes;
76+
for (const [currentBasicBlock, branchesForThatBasicBlock] of this.branchGraph) {
77+
let used = 0;
7878
for (const isCovered of branchesForThatBasicBlock.values()) {
7979
if (!isCovered) {
8080
this.notFullyCoveredBasicBlock.add(currentBasicBlock);
81+
} else {
82+
used++;
8183
}
8284
}
83-
}
84-
for (const toNodes of this.branchGraph.values()) {
85-
let used = 0;
86-
for (const toNode of toNodes.values()) {
87-
if (toNode) used++;
88-
}
8985
this.result.branchCoverageRate.used += used;
9086
}
91-
// console.log(this.notFullyCoveredBasicBlock);
9287
for (const block of this.notFullyCoveredBasicBlock) {
9388
const lineInfo = this.covInfo.lineInfo.get(block);
9489
if (lineInfo !== undefined && lineInfo.size > 0) {
95-
this.result.linesToHighlight.add(Math.max(...lineInfo));
90+
this.result.uncoveredlines.add(Math.max(...lineInfo));
9691
}
9792
}
98-
// console.log(this.result.functionName, this.result.lineRange, this.result.linesToHighlight);
9993
}
10094
}

tests-as/diytest.test.ts

-31
This file was deleted.

tests-ts/test/parser/__snapshots__/parser.test.ts.snap

+13-13
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ exports[`Parser generateFileCoverage 1`] = `
1616
"total": 18,
1717
"used": 9,
1818
},
19-
"linesToHighlight": Set {},
2019
"sourceUsedCount": [
2120
CodeCoverage {
2221
"source": "",
@@ -227,6 +226,7 @@ exports[`Parser generateFileCoverage 1`] = `
227226
"total": 18,
228227
"used": 9,
229228
},
229+
"uncoveredlines": Set {},
230230
},
231231
FileCoverageResult {
232232
"branchCoverageRate": Rate {
@@ -242,7 +242,6 @@ exports[`Parser generateFileCoverage 1`] = `
242242
"total": 1,
243243
"used": 1,
244244
},
245-
"linesToHighlight": Set {},
246245
"sourceUsedCount": [
247246
CodeCoverage {
248247
"source": "",
@@ -453,6 +452,7 @@ exports[`Parser generateFileCoverage 1`] = `
453452
"total": 1,
454453
"used": 1,
455454
},
455+
"uncoveredlines": Set {},
456456
},
457457
FileCoverageResult {
458458
"branchCoverageRate": Rate {
@@ -468,9 +468,6 @@ exports[`Parser generateFileCoverage 1`] = `
468468
"total": 13,
469469
"used": 9,
470470
},
471-
"linesToHighlight": Set {
472-
25,
473-
},
474471
"sourceUsedCount": [
475472
CodeCoverage {
476473
"source": "",
@@ -681,6 +678,9 @@ exports[`Parser generateFileCoverage 1`] = `
681678
"total": 13,
682679
"used": 9,
683680
},
681+
"uncoveredlines": Set {
682+
25,
683+
},
684684
},
685685
FileCoverageResult {
686686
"branchCoverageRate": Rate {
@@ -696,7 +696,6 @@ exports[`Parser generateFileCoverage 1`] = `
696696
"total": 2,
697697
"used": 2,
698698
},
699-
"linesToHighlight": Set {},
700699
"sourceUsedCount": [
701700
CodeCoverage {
702701
"source": "",
@@ -907,6 +906,7 @@ exports[`Parser generateFileCoverage 1`] = `
907906
"total": 2,
908907
"used": 2,
909908
},
909+
"uncoveredlines": Set {},
910910
},
911911
]
912912
`;
@@ -923,10 +923,10 @@ exports[`Parser generateFunctionCoverage 1`] = `
923923
39,
924924
39,
925925
],
926-
"linesToHighlight": Set {},
927926
"sourceUsedCount": Map {
928927
39 => 3,
929928
},
929+
"uncoveredlines": Set {},
930930
},
931931
FunctionCoverageResult {
932932
"branchCoverageRate": Rate {
@@ -938,7 +938,6 @@ exports[`Parser generateFunctionCoverage 1`] = `
938938
16,
939939
24,
940940
],
941-
"linesToHighlight": Set {},
942941
"sourceUsedCount": Map {
943942
16 => 3,
944943
17 => 3,
@@ -949,6 +948,7 @@ exports[`Parser generateFunctionCoverage 1`] = `
949948
22 => 1,
950949
24 => 2,
951950
},
951+
"uncoveredlines": Set {},
952952
},
953953
FunctionCoverageResult {
954954
"branchCoverageRate": Rate {
@@ -960,10 +960,10 @@ exports[`Parser generateFunctionCoverage 1`] = `
960960
45,
961961
45,
962962
],
963-
"linesToHighlight": Set {},
964963
"sourceUsedCount": Map {
965964
45 => 4,
966965
},
966+
"uncoveredlines": Set {},
967967
},
968968
FunctionCoverageResult {
969969
"branchCoverageRate": Rate {
@@ -975,9 +975,6 @@ exports[`Parser generateFunctionCoverage 1`] = `
975975
10,
976976
29,
977977
],
978-
"linesToHighlight": Set {
979-
25,
980-
},
981978
"sourceUsedCount": Map {
982979
10 => 2,
983980
11 => 2,
@@ -990,6 +987,9 @@ exports[`Parser generateFunctionCoverage 1`] = `
990987
26 => 1,
991988
29 => 0,
992989
},
990+
"uncoveredlines": Set {
991+
25,
992+
},
993993
},
994994
FunctionCoverageResult {
995995
"branchCoverageRate": Rate {
@@ -1001,11 +1001,11 @@ exports[`Parser generateFunctionCoverage 1`] = `
10011001
10,
10021002
11,
10031003
],
1004-
"linesToHighlight": Set {},
10051004
"sourceUsedCount": Map {
10061005
10 => 2,
10071006
11 => 2,
10081007
},
1008+
"uncoveredlines": Set {},
10091009
},
10101010
]
10111011
`;

tests-ts/test/parser/singleFileAnalysis.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ describe("singleFileAnalysis", () => {
3636
functionName: "A",
3737
lineRange: [6, 9],
3838
branchCoverageRate: rate_A,
39-
linesToHighlight: new Set<number>([]),
39+
uncoveredlines: new Set<number>([]),
4040
sourceUsedCount: new Map([
4141
[6, 3],
4242
[7, 0],
@@ -50,7 +50,7 @@ describe("singleFileAnalysis", () => {
5050
functionName: "B",
5151
lineRange: [10, 14],
5252
branchCoverageRate: rate_B,
53-
linesToHighlight: new Set<number>([]),
53+
uncoveredlines: new Set<number>([]),
5454
sourceUsedCount: new Map([
5555
[10, 2],
5656
[11, 0],
@@ -90,7 +90,7 @@ describe("singleFileAnalysis", () => {
9090
functionName: "A",
9191
lineRange: [6, 30],
9292
branchCoverageRate: rate,
93-
linesToHighlight: new Set<number>([]),
93+
uncoveredlines: new Set<number>([]),
9494
sourceUsedCount: new Map([
9595
[6, 3],
9696
[7, 0],

0 commit comments

Comments
 (0)