-
Notifications
You must be signed in to change notification settings - Fork 463
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Native coverage integration for the CTest test controller (#4094)
* Added lcov-parser as dependency Used to parse lcov coverage info files. * Update vscode engine to 1.88.0 Needed for accessing the Test Coverage API in vscode * Native test coverage implementation Test coverage implementation for the CTest test controller. It relies on lcov coverage info files being specefied by the user in the settings.json of the project. Optionally, the user can specify CMake (utility) targets that should be built before and/or after the tests are/have been executed. These targets could reasonably zero the coverage counters (pre) and filter the coverage info files (post). * CMake fixes in single-root-UI test * Added end-to-end test for coverage * Unit test for coverage * Removed specifying gcov tool as it is not needed Also removed dynamic `--dynamic-list-data` linker flag * Use setup-lcov action * Removed log from coverage unit test * Test additions and fixes * Rationale notes in code * grab from feed * Review fixes + disable coverage test on Win MSVC can not produce gcov based coverage data, therefore the coverage end-to-end tests are disabled on Windows. * Added changelog entry for the coverage feature --------- Co-authored-by: Garrett Campbell <86264750+gcampbell-msft@users.noreply.github.com> Co-authored-by: Garrett Campbell <gcampbell@microsoft.com>
- Loading branch information
1 parent
a5775cc
commit 9a24c14
Showing
24 changed files
with
432 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import * as vscode from 'vscode'; | ||
import { lcovParser } from "@friedemannsommer/lcov-parser"; | ||
import * as nls from 'vscode-nls'; | ||
import * as logging from '@cmt/logging'; | ||
|
||
nls.config({ messageFormat: nls.MessageFormat.bundle, bundleFormat: nls.BundleFormat.standalone })(); | ||
const localize: nls.LocalizeFunc = nls.loadMessageBundle(); | ||
|
||
const log = logging.createLogger('ctest-coverage'); | ||
|
||
export async function handleCoverageInfoFiles(run: vscode.TestRun, coverageInfoFiles: string[], coverageData: WeakMap<vscode.FileCoverage, vscode.FileCoverageDetail[]>) { | ||
for (const coverageInfoFile of coverageInfoFiles) { | ||
let contents: Uint8Array; | ||
try { | ||
contents = await vscode.workspace.fs.readFile(vscode.Uri.file(coverageInfoFile)); | ||
} catch (e) { | ||
log.warning(localize('test.openCoverageInfoFile', 'Could not open coverage info file: {0}. Skipping...', coverageInfoFile)); | ||
return; | ||
} | ||
const sections = await lcovParser({ from: contents }); | ||
for (const section of sections) { | ||
const coverage = new vscode.FileCoverage(vscode.Uri.file(section.path), | ||
new vscode.TestCoverageCount( | ||
section.lines.hit, | ||
section.lines.instrumented | ||
), new vscode.TestCoverageCount( | ||
section.branches.hit, | ||
section.branches.instrumented | ||
), new vscode.TestCoverageCount( | ||
section.functions.hit, | ||
section.functions.instrumented | ||
)); | ||
|
||
const lineBranches = new Map<number, vscode.BranchCoverage[]>(); | ||
for (const branch of section.branches.details) { | ||
const branchCoverage = new vscode.BranchCoverage(branch.hit, | ||
new vscode.Position(branch.line - 1, 0), branch.branch); | ||
|
||
const curr = lineBranches.get(branch.line); | ||
if (curr === undefined) { | ||
lineBranches.set(branch.line, [branchCoverage]); | ||
} else { | ||
curr.push(branchCoverage); | ||
lineBranches.set(branch.line, curr); | ||
} | ||
} | ||
|
||
const declarations: vscode.DeclarationCoverage[] = []; | ||
for (const declaration of section.functions.details) { | ||
declarations.push(new vscode.DeclarationCoverage(declaration.name, declaration.hit, | ||
new vscode.Position(declaration.line - 1, 0))); | ||
} | ||
|
||
const statements: vscode.StatementCoverage[] = []; | ||
for (const line of section.lines.details) { | ||
statements.push(new vscode.StatementCoverage(line.hit, | ||
new vscode.Position(line.line - 1, 0), | ||
lineBranches.get(line.line) ?? [])); | ||
} | ||
coverageData.set(coverage, [...statements, ...declarations]); | ||
run.addCoverage(coverage); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 6 additions & 1 deletion
7
test/end-to-end-tests/single-root-UI/project-folder/.vscode/settings.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,10 @@ | ||
{ | ||
"cmake.buildDirectory": "${workspaceFolder}/build", | ||
"cmake.useCMakePresets": "never", | ||
"cmake.configureOnOpen": false | ||
"cmake.configureOnOpen": false, | ||
"cmake.preRunCoverageTarget": "init-coverage", | ||
"cmake.postRunCoverageTarget": "capture-coverage", | ||
"cmake.coverageInfoFiles": [ | ||
"${workspaceFolder}/build/lcov.info" | ||
] | ||
} |
Oops, something went wrong.