Skip to content

Commit

Permalink
Unit test for coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
TSonono committed Nov 4, 2024
1 parent 9c109e4 commit 2d53bdb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
42 changes: 42 additions & 0 deletions test/unit-tests/coverage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { handleCoverageInfoFiles } from "@cmt/coverage";
import * as vscode from "vscode";
import { expect, getTestResourceFilePath } from "@test/util";

suite('Coverage Handling', () => {

test('Coverage Info (LCOV)', async () => {
const filesCoverages: vscode.FileCoverage[] = [];
const testRun: vscode.TestRun = {
name: '',
token: {} as vscode.CancellationToken,
isPersisted: false,
enqueued: (_test: vscode.TestItem) => {},
started: (_test: vscode.TestItem) => {},
passed: (_test: vscode.TestItem, _duration: number) => {},
failed: (_test: vscode.TestItem, _message: vscode.TestMessage | vscode.TestMessage[], _duration: number) => {},
skipped: (_test: vscode.TestItem) => {},
errored: (_test: vscode.TestItem, _message: vscode.TestMessage | vscode.TestMessage[], _duration: number) => {},
appendOutput: (_output: string, _location?: vscode.Location, _test?: vscode.TestItem) => {},
addCoverage: (fileCoverage: vscode.FileCoverage) => {
filesCoverages.push(fileCoverage);
},
end: () => {},
onDidDispose: (_listener: () => void): vscode.Disposable => new vscode.Disposable(() => {})
};

const coverageData = new WeakMap<vscode.FileCoverage, vscode.FileCoverageDetail[]>();
await handleCoverageInfoFiles(testRun, [getTestResourceFilePath('lcov.info')], coverageData);
expect(filesCoverages.length).to.eq(1);
expect(filesCoverages[0].uri.fsPath).to.eq('/tmp/lcov/main.cpp');
const coverageDetail = coverageData.get(filesCoverages[0]);
expect(coverageDetail).to.not.be.undefined;

expect(coverageDetail![0].executed).to.eq(1);
expect((coverageDetail![0].location as vscode.Position).line).to.eq(2);

expect(coverageDetail![1].executed).to.eq(1);
expect((coverageDetail![1].location as vscode.Position).line).to.eq(3);

console.log(JSON.stringify(coverageDetail, null, 4));
});
});
16 changes: 16 additions & 0 deletions test/unit-tests/lcov.info
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
TN:
SF:/tmp/lcov/main.cpp
FN:3,4,main
FN:5,5,_GLOBAL__sub_I_main
FN:5,5,_Z41__static_initialization_and_destruction_0ii
FNDA:1,main
FNDA:1,_GLOBAL__sub_I_main
FNDA:1,_Z41__static_initialization_and_destruction_0ii
FNF:3
FNH:3
DA:3,1
DA:4,1
DA:5,4
LF:3
LH:3
end_of_record

0 comments on commit 2d53bdb

Please sign in to comment.