add setting to apply test coverage when single test file is run (#2884)

This commit is contained in:
Oleg Kovalov 2019-11-10 05:03:36 +01:00 коммит произвёл Ramya Rao
Родитель 5916863d76
Коммит 6ffbcd8513
2 изменённых файлов: 15 добавлений и 2 удалений

Просмотреть файл

@ -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": [

Просмотреть файл

@ -195,6 +195,7 @@ 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(() => {
@ -202,7 +203,7 @@ export function testCurrentFile(goConfig: vscode.WorkspaceConfiguration, isBench
const testConfig: TestConfig = {
goConfig,
dir: path.dirname(editor.document.fileName),
flags: getTestFlags(goConfig, args),
flags: testFlags,
functions: testFunctions.map(sym => sym.name),
isBenchmark,
};
@ -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 => {