Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

add single file coverage #2884

Merged
merged 2 commits into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,11 @@
"default": false,
"description": "If true, shows test coverage when Go: Test Function at cursor command is run."
},
"go.coverOnSingleTestFile": {
"type": "boolean",
"default": false,
"description": "If true, shows test coverage when Go: Test Single File command is run."
},
"go.coverageOptions": {
"type": "string",
"enum": [
Expand Down Expand Up @@ -1615,4 +1620,4 @@
]
}
}
}
}
12 changes: 10 additions & 2 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,15 @@ export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, isBench
return;
}

const { tmpCoverPath, testFlags } = makeCoverData(goConfig, 'coverOnSingleTestFile', args);
const getFunctions = isBenchmark ? getBenchmarkFunctions : getTestFunctions;

return editor.document.save().then(() => {
return getFunctions(editor.document, null).then(testFunctions => {
const testConfig: TestConfig = {
goConfig: goConfig,
dir: path.dirname(editor.document.fileName),
flags: getTestFlags(goConfig, args),
flags: testFlags,
functions: testFunctions.map(sym => sym.name),
isBenchmark: isBenchmark,
};
Expand All @@ -211,7 +212,14 @@ export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, isBench

return isModSupported(editor.document.uri).then(isMod => {
testConfig.isMod = isMod;
return goTest(testConfig);
return goTest(testConfig).then(success => {
if (tmpCoverPath) {
applyCodeCoverageToAllEditors(tmpCoverPath, testConfig.dir);
}
return Promise.resolve(success);
}, err => {
console.log(err);
});
});
});
}).then(null, err => {
Expand Down