Skip to content

Commit f78c016

Browse files
committed
[release] package.json: default 'go.coverMode' to be 'default'
According to `go help testflag`, the actual default of `-covermode` when it's not explicitly set is affected by the `-race` flag. -covermode set,count,atomic Set the mode for coverage analysis for the package[s] being tested. The default is "set" unless -race is enabled, in which case it is "atomic". Introduce 'default' as the default option for 'go.coverMode' to indicate the covermode is unspecified. Fixes #666 Change-Id: I7c7059140947639e3fd0438e1bc6cc50c712ebbb Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/256117 Trust: Hyang-Ah Hana Kim <[email protected]> Trust: Peter Weinberger <[email protected]> Run-TryBot: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Peter Weinberger <[email protected]> TryBot-Result: kokoro <[email protected]> (cherry picked from commit 8d0bafa) Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/257602
1 parent 8b166d9 commit f78c016

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

docs/settings.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ Default: ``
6363

6464
### `go.coverMode`
6565

66-
When generating code coverage, the value for -covermode
66+
When generating code coverage, the value for -covermode. 'default' is the default value chosen by the 'go test' command.
6767

68-
Allowed Values:`[set count atomic]`
68+
Allowed Values:`[default set count atomic]`
6969

70-
Default: `set`
70+
Default: `default`
7171

7272
### `go.coverOnSave`
7373

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,12 +1316,13 @@
13161316
"go.coverMode": {
13171317
"type": "string",
13181318
"enum": [
1319+
"default",
13191320
"set",
13201321
"count",
13211322
"atomic"
13221323
],
1323-
"default": "set",
1324-
"description": "When generating code coverage, the value for -covermode",
1324+
"default": "default",
1325+
"description": "When generating code coverage, the value for -covermode. 'default' is the default value chosen by the 'go test' command.",
13251326
"scope": "resource"
13261327
},
13271328
"go.coverShowCounts": {

src/testUtils.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -270,17 +270,19 @@ export async function goTest(testconfig: TestConfig): Promise<boolean> {
270270
} else {
271271
args.push('-timeout', testconfig.goConfig['testTimeout']);
272272
if (testconfig.applyCodeCoverage) {
273-
let coverMode = testconfig.goConfig['coverMode'];
273+
args.push('-coverprofile=' + tmpCoverPath);
274+
const coverMode = testconfig.goConfig['coverMode'];
274275
switch (coverMode) {
275-
case 'set': case 'count': case 'atomic': break;
276+
case 'default':
277+
break;
278+
case 'set': case 'count': case 'atomic':
279+
args.push('-covermode', coverMode);
280+
break;
276281
default:
277282
vscode.window.showWarningMessage(
278-
`go.coverMode=${coverMode} is illegal. Use 'set', 'count', atomic'`
283+
`go.coverMode=${coverMode} is illegal. Use 'set', 'count', 'atomic', or 'default'.`
279284
);
280-
coverMode = 'set';
281285
}
282-
args.push('-coverprofile=' + tmpCoverPath);
283-
args.push('-covermode', coverMode);
284286
}
285287
}
286288
if (testTags && testconfig.flags.indexOf('-tags') === -1) {

test/integration/test.test.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ suite('Test Go Test', function () {
5050
}
5151

5252
async function runTest(
53-
input: { isMod: boolean, includeSubDirectories: boolean, testFlags?: string[] },
53+
input: { isMod: boolean, includeSubDirectories: boolean, testFlags?: string[], applyCodeCoverage?: boolean},
5454
wantFiles: string[]) {
5555

5656
fs.copySync(sourcePath, repoPath, { recursive: true });
@@ -65,8 +65,12 @@ suite('Test Go Test', function () {
6565
flags: input.testFlags ? input.testFlags : getTestFlags(config),
6666
isMod: input.isMod,
6767
includeSubDirectories: input.includeSubDirectories,
68+
applyCodeCoverage: input.applyCodeCoverage
6869
};
6970
try {
71+
// TODO: instead of calling goTest, consider to test
72+
// testCurrentPackage, testCurrentWorkspace, testCurrentFile
73+
// which are closer to the features exposed to users.
7074
const result = await goTest(testConfig);
7175
assert.equal(result, false); // we expect tests to fail.
7276
} catch (e) {
@@ -90,6 +94,9 @@ suite('Test Go Test', function () {
9094
await runTest(
9195
{ isMod: true, includeSubDirectories: true, testFlags: ['-v'] },
9296
[path.join(repoPath, 'a_test.go'), path.join(repoPath, 'b', 'b_test.go')]);
97+
await runTest(
98+
{ isMod: true, includeSubDirectories: true, testFlags: ['-race'], applyCodeCoverage: true },
99+
[path.join(repoPath, 'a_test.go'), path.join(repoPath, 'b', 'b_test.go')]);
93100
await runTest(
94101
{ isMod: true, includeSubDirectories: false, testFlags: ['-v'] },
95102
[path.join(repoPath, 'a_test.go')]);
@@ -106,6 +113,9 @@ suite('Test Go Test', function () {
106113
await runTest(
107114
{ isMod: true, includeSubDirectories: true, testFlags: ['-v'] },
108115
[path.join(repoPath, 'a_test.go'), path.join(repoPath, 'b', 'b_test.go')]);
116+
await runTest(
117+
{ isMod: true, includeSubDirectories: true, testFlags: ['-race'], applyCodeCoverage: true },
118+
[path.join(repoPath, 'a_test.go'), path.join(repoPath, 'b', 'b_test.go')]);
109119
await runTest(
110120
{ isMod: true, includeSubDirectories: false, testFlags: ['-v'] },
111121
[path.join(repoPath, 'a_test.go')]);

0 commit comments

Comments
 (0)