From 2d53bdb94650126e8dada9bdfe69ad7fdf34483d Mon Sep 17 00:00:00 2001 From: Tofik Sonono Date: Mon, 4 Nov 2024 14:16:47 +0100 Subject: [PATCH] Unit test for coverage --- test/unit-tests/coverage.test.ts | 42 ++++++++++++++++++++++++++++++++ test/unit-tests/lcov.info | 16 ++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 test/unit-tests/coverage.test.ts create mode 100644 test/unit-tests/lcov.info diff --git a/test/unit-tests/coverage.test.ts b/test/unit-tests/coverage.test.ts new file mode 100644 index 000000000..0598ada09 --- /dev/null +++ b/test/unit-tests/coverage.test.ts @@ -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(); + 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)); + }); +}); diff --git a/test/unit-tests/lcov.info b/test/unit-tests/lcov.info new file mode 100644 index 000000000..fb7a8349c --- /dev/null +++ b/test/unit-tests/lcov.info @@ -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