-
Notifications
You must be signed in to change notification settings - Fork 454
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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).
- Loading branch information
Showing
7 changed files
with
196 additions
and
4 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
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'); | ||
|
||
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