Skip to content

Commit 5a65ba3

Browse files
committed
test/goDebugConfiguration.test.ts: test settings.json debug config effects
The delveConfig user settings applied in settings.json, should be applied to the debug configuration. Test that these are correctly applied. Additionally, testFlags and buildFlags do not currently affect the debug configuration, so we also test that to document that behavior. This behavior is likely to change and the test should be updated when it does. This change also reintroduces the --user-data-dir= argument to the launch configuration for running the integration tests. This starts the test with the default user settings, so running the tests should not be affected by the user settings. Update #43 Change-Id: I99c9d7f17892e6766fae731c9288880b109ba3fd Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/267217 Trust: Suzy Mueller <suzmue@golang.org> Trust: Hyang-Ah Hana Kim <hyangah@gmail.com> Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
1 parent cc84cbe commit 5a65ba3

File tree

5 files changed

+155
-3
lines changed

5 files changed

+155
-3
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ dist/
33
node_modules/
44
.vscode-test/
55
.DS_Store
6+
.user-data-dir-test/

.vscode/launch.json

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
"--disable-extensions",
6262
"--extensionDevelopmentPath=${workspaceFolder}",
6363
"--extensionTestsPath=${workspaceFolder}/out/test/integration/index",
64+
"--user-data-dir=${workspaceFolder}/.user-data-dir-test",
6465
"--timeout",
6566
"999999"
6667
],
@@ -86,6 +87,7 @@
8687
"--disable-extensions",
8788
"--extensionDevelopmentPath=${workspaceFolder}",
8889
"--extensionTestsPath=${workspaceFolder}/out/test/gopls/index",
90+
"--user-data-dir=${workspaceFolder}/.user-data-dir-test",
8991
"--timeout", "999999",
9092
],
9193
"env": {

src/goDebugConfiguration.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
6262
debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;
6363

6464
const goConfig = getGoConfig(folder && folder.uri);
65-
const dlvConfig = goConfig.get<any>('delveConfig');
65+
const dlvConfig = goConfig['delveConfig'];
6666
let useApiV1 = false;
6767
if (debugConfiguration.hasOwnProperty('useApiV1')) {
6868
useApiV1 = debugConfiguration['useApiV1'] === true;

test/integration/goDebugConfiguration.test.ts

+146-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import vscode = require('vscode');
77
import { GoDebugConfigurationProvider } from '../../src/goDebugConfiguration';
88
import goEnv = require('../../src/goEnv');
99
import { updateGoVarsFromConfig } from '../../src/goInstallTools';
10-
import { getCurrentGoPath, rmdirRecursive } from '../../src/util';
10+
import { getGoConfig, rmdirRecursive } from '../../src/util';
1111

1212
suite('Debug Environment Variable Merge Test', () => {
1313
const debugConfigProvider = new GoDebugConfigurationProvider();
@@ -134,3 +134,148 @@ suite('Debug Environment Variable Merge Test', () => {
134134
});
135135
});
136136
});
137+
138+
suite('Debug Configuration Merge User Settings', () => {
139+
const debugConfigProvider = new GoDebugConfigurationProvider();
140+
const utils = require('../../src/util');
141+
142+
teardown(() => sinon.restore());
143+
144+
suite(`merge 'go' config from settings.json`, () => {
145+
test('go flags config does not affect debug config', () => {
146+
// This tests that the testFlags and GOOS and GOARCH set
147+
// in settings.json do not affect the resolved debug configuration.
148+
// When this expected behavior changes, this test can be updated.
149+
150+
// Run resolveDebugConfiguration with the default workspace settings.
151+
const cfg1 = {
152+
name: 'Launch',
153+
type: 'go',
154+
request: 'launch',
155+
mode: 'auto',
156+
program: '${fileDirname}',
157+
};
158+
159+
const emptyResult = debugConfigProvider.resolveDebugConfiguration(undefined, cfg1);
160+
const goConfig = Object.create(getGoConfig(), {
161+
testFlags: {value: '-tags=myTagTest'},
162+
buildFlags: {value: '-tags=myTagBuild'},
163+
goroot: {value: '/path/to/goroot'},
164+
gopath: {value: '/path/to/gopath'}
165+
}) as vscode.WorkspaceConfiguration;
166+
167+
// Adjust the workspace config.
168+
sinon.stub(utils, 'getGoConfig').returns(goConfig);
169+
170+
const cfg2 = {
171+
name: 'Launch',
172+
type: 'go',
173+
request: 'launch',
174+
mode: 'auto',
175+
program: '${fileDirname}',
176+
};
177+
178+
const filledResult = debugConfigProvider.resolveDebugConfiguration(undefined, cfg2);
179+
180+
assert.strictEqual(filledResult.name, emptyResult.name);
181+
assert.strictEqual(filledResult.type, emptyResult.type);
182+
assert.strictEqual(filledResult.mode, emptyResult.mode);
183+
assert.strictEqual(filledResult.request, emptyResult.request);
184+
assert.strictEqual(filledResult.program, emptyResult.program);
185+
assert.strictEqual(filledResult.dlvToolPath, emptyResult.dlvToolPath);
186+
assert.strictEqual(filledResult.apiVersion, emptyResult.apiVersion);
187+
assert.strictEqual(filledResult.showGlobalVariables, emptyResult.showGlobalVariables);
188+
});
189+
190+
test('delve config in settings.json is added to debug config', () => {
191+
// This tests that the testFlags and GOOS and GOARCH set
192+
// in settings.json do not affect the resolved debug configuration.
193+
// When this expected behavior changes, this test can be updated.
194+
195+
// Run resolveDebugConfiguration with the default workspace settings.
196+
const goConfig = Object.create(getGoConfig(), {
197+
delveConfig: { value: {
198+
dlvLoadConfig: {
199+
followPointers: false,
200+
maxVariableRecurse: 3,
201+
maxStringLen: 32,
202+
maxArrayValues: 32,
203+
maxStructFields: 5
204+
},
205+
apiVersion: 1,
206+
showGlobalVariables: true
207+
}
208+
}
209+
}) as vscode.WorkspaceConfiguration;
210+
sinon.stub(utils, 'getGoConfig').returns(goConfig);
211+
212+
const cfg = {
213+
name: 'Launch',
214+
type: 'go',
215+
request: 'launch',
216+
mode: 'auto',
217+
program: '${fileDirname}',
218+
};
219+
220+
const result = debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
221+
assert.strictEqual(result.apiVersion, 1);
222+
assert.strictEqual(result.showGlobalVariables, true);
223+
const dlvLoadConfig = result.dlvLoadConfig;
224+
assert.strictEqual(dlvLoadConfig.followPointers, false);
225+
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 3);
226+
assert.strictEqual(dlvLoadConfig.maxStringLen, 32);
227+
assert.strictEqual(dlvLoadConfig.maxArrayValues, 32);
228+
assert.strictEqual(dlvLoadConfig.maxStructFields, 5);
229+
});
230+
231+
test('delve config in settings.json is overriden by launch.json', () => {
232+
// This tests that the testFlags and GOOS and GOARCH set
233+
// in settings.json do not affect the resolved debug configuration.
234+
// When this expected behavior changes, this test can be updated.
235+
236+
// Run resolveDebugConfiguration with the default workspace settings.
237+
const goConfig = Object.create(getGoConfig(), {
238+
delveConfig: { value: {
239+
dlvLoadConfig: {
240+
followPointers: false,
241+
maxVariableRecurse: 3,
242+
maxStringLen: 32,
243+
maxArrayValues: 32,
244+
maxStructFields: 5
245+
},
246+
apiVersion: 1,
247+
showGlobalVariables: true
248+
}
249+
}
250+
}) as vscode.WorkspaceConfiguration;
251+
sinon.stub(utils, 'getGoConfig').returns(goConfig);
252+
253+
const cfg = {
254+
name: 'Launch',
255+
type: 'go',
256+
request: 'launch',
257+
mode: 'auto',
258+
program: '${fileDirname}',
259+
apiVersion: 2,
260+
showGlobalVariables: false,
261+
dlvLoadConfig: {
262+
followPointers: true,
263+
maxVariableRecurse: 6,
264+
maxStringLen: 128,
265+
maxArrayValues: 128,
266+
maxStructFields: -1
267+
},
268+
};
269+
270+
const result = debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
271+
assert.strictEqual(result.apiVersion, 2);
272+
assert.strictEqual(result.showGlobalVariables, false);
273+
const dlvLoadConfig = result.dlvLoadConfig;
274+
assert.strictEqual(dlvLoadConfig.followPointers, true);
275+
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 6);
276+
assert.strictEqual(dlvLoadConfig.maxStringLen, 128);
277+
assert.strictEqual(dlvLoadConfig.maxArrayValues, 128);
278+
assert.strictEqual(dlvLoadConfig.maxStructFields, -1);
279+
});
280+
});
281+
});

test/runTest.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ async function main() {
2020
await runTests({
2121
extensionDevelopmentPath,
2222
extensionTestsPath,
23-
launchArgs: ['--disable-extensions'], // disable all other extensions
23+
launchArgs: [
24+
'--disable-extensions',
25+
'--user-data-dir=${workspaceFolder}/.user-data-dir-test',
26+
], // disable all other extensions
2427
});
2528
} catch (err) {
2629
console.error('Failed to run integration tests' + err);
@@ -37,6 +40,7 @@ async function main() {
3740
extensionTestsPath: path.resolve(__dirname, './gopls/index'),
3841
launchArgs: [
3942
'--disable-extensions', // disable all other extensions
43+
'--user-data-dir=${workspaceFolder}/.user-data-dir-test',
4044
],
4145
});
4246
} catch (err) {

0 commit comments

Comments
 (0)