Skip to content

Commit

Permalink
test/goDebugConfiguration.test.ts: test settings.json debug config ef…
Browse files Browse the repository at this point in the history
…fects

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 golang#43

Change-Id: I99c9d7f17892e6766fae731c9288880b109ba3fd
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/267217
Trust: Suzy Mueller <[email protected]>
Trust: Hyang-Ah Hana Kim <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
  • Loading branch information
suzmue committed Nov 10, 2020
1 parent cc84cbe commit 5a65ba3
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist/
node_modules/
.vscode-test/
.DS_Store
.user-data-dir-test/
2 changes: 2 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/integration/index",
"--user-data-dir=${workspaceFolder}/.user-data-dir-test",
"--timeout",
"999999"
],
Expand All @@ -86,6 +87,7 @@
"--disable-extensions",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionTestsPath=${workspaceFolder}/out/test/gopls/index",
"--user-data-dir=${workspaceFolder}/.user-data-dir-test",
"--timeout", "999999",
],
"env": {
Expand Down
2 changes: 1 addition & 1 deletion src/goDebugConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class GoDebugConfigurationProvider implements vscode.DebugConfigurationPr
debugConfiguration['packagePathToGoModPathMap'] = packagePathToGoModPathMap;

const goConfig = getGoConfig(folder && folder.uri);
const dlvConfig = goConfig.get<any>('delveConfig');
const dlvConfig = goConfig['delveConfig'];
let useApiV1 = false;
if (debugConfiguration.hasOwnProperty('useApiV1')) {
useApiV1 = debugConfiguration['useApiV1'] === true;
Expand Down
147 changes: 146 additions & 1 deletion test/integration/goDebugConfiguration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import vscode = require('vscode');
import { GoDebugConfigurationProvider } from '../../src/goDebugConfiguration';
import goEnv = require('../../src/goEnv');
import { updateGoVarsFromConfig } from '../../src/goInstallTools';
import { getCurrentGoPath, rmdirRecursive } from '../../src/util';
import { getGoConfig, rmdirRecursive } from '../../src/util';

suite('Debug Environment Variable Merge Test', () => {
const debugConfigProvider = new GoDebugConfigurationProvider();
Expand Down Expand Up @@ -134,3 +134,148 @@ suite('Debug Environment Variable Merge Test', () => {
});
});
});

suite('Debug Configuration Merge User Settings', () => {
const debugConfigProvider = new GoDebugConfigurationProvider();
const utils = require('../../src/util');

teardown(() => sinon.restore());

suite(`merge 'go' config from settings.json`, () => {
test('go flags config does not affect debug config', () => {
// This tests that the testFlags and GOOS and GOARCH set
// in settings.json do not affect the resolved debug configuration.
// When this expected behavior changes, this test can be updated.

// Run resolveDebugConfiguration with the default workspace settings.
const cfg1 = {
name: 'Launch',
type: 'go',
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
};

const emptyResult = debugConfigProvider.resolveDebugConfiguration(undefined, cfg1);
const goConfig = Object.create(getGoConfig(), {
testFlags: {value: '-tags=myTagTest'},
buildFlags: {value: '-tags=myTagBuild'},
goroot: {value: '/path/to/goroot'},
gopath: {value: '/path/to/gopath'}
}) as vscode.WorkspaceConfiguration;

// Adjust the workspace config.
sinon.stub(utils, 'getGoConfig').returns(goConfig);

const cfg2 = {
name: 'Launch',
type: 'go',
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
};

const filledResult = debugConfigProvider.resolveDebugConfiguration(undefined, cfg2);

assert.strictEqual(filledResult.name, emptyResult.name);
assert.strictEqual(filledResult.type, emptyResult.type);
assert.strictEqual(filledResult.mode, emptyResult.mode);
assert.strictEqual(filledResult.request, emptyResult.request);
assert.strictEqual(filledResult.program, emptyResult.program);
assert.strictEqual(filledResult.dlvToolPath, emptyResult.dlvToolPath);
assert.strictEqual(filledResult.apiVersion, emptyResult.apiVersion);
assert.strictEqual(filledResult.showGlobalVariables, emptyResult.showGlobalVariables);
});

test('delve config in settings.json is added to debug config', () => {
// This tests that the testFlags and GOOS and GOARCH set
// in settings.json do not affect the resolved debug configuration.
// When this expected behavior changes, this test can be updated.

// Run resolveDebugConfiguration with the default workspace settings.
const goConfig = Object.create(getGoConfig(), {
delveConfig: { value: {
dlvLoadConfig: {
followPointers: false,
maxVariableRecurse: 3,
maxStringLen: 32,
maxArrayValues: 32,
maxStructFields: 5
},
apiVersion: 1,
showGlobalVariables: true
}
}
}) as vscode.WorkspaceConfiguration;
sinon.stub(utils, 'getGoConfig').returns(goConfig);

const cfg = {
name: 'Launch',
type: 'go',
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
};

const result = debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
assert.strictEqual(result.apiVersion, 1);
assert.strictEqual(result.showGlobalVariables, true);
const dlvLoadConfig = result.dlvLoadConfig;
assert.strictEqual(dlvLoadConfig.followPointers, false);
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 3);
assert.strictEqual(dlvLoadConfig.maxStringLen, 32);
assert.strictEqual(dlvLoadConfig.maxArrayValues, 32);
assert.strictEqual(dlvLoadConfig.maxStructFields, 5);
});

test('delve config in settings.json is overriden by launch.json', () => {
// This tests that the testFlags and GOOS and GOARCH set
// in settings.json do not affect the resolved debug configuration.
// When this expected behavior changes, this test can be updated.

// Run resolveDebugConfiguration with the default workspace settings.
const goConfig = Object.create(getGoConfig(), {
delveConfig: { value: {
dlvLoadConfig: {
followPointers: false,
maxVariableRecurse: 3,
maxStringLen: 32,
maxArrayValues: 32,
maxStructFields: 5
},
apiVersion: 1,
showGlobalVariables: true
}
}
}) as vscode.WorkspaceConfiguration;
sinon.stub(utils, 'getGoConfig').returns(goConfig);

const cfg = {
name: 'Launch',
type: 'go',
request: 'launch',
mode: 'auto',
program: '${fileDirname}',
apiVersion: 2,
showGlobalVariables: false,
dlvLoadConfig: {
followPointers: true,
maxVariableRecurse: 6,
maxStringLen: 128,
maxArrayValues: 128,
maxStructFields: -1
},
};

const result = debugConfigProvider.resolveDebugConfiguration(undefined, cfg);
assert.strictEqual(result.apiVersion, 2);
assert.strictEqual(result.showGlobalVariables, false);
const dlvLoadConfig = result.dlvLoadConfig;
assert.strictEqual(dlvLoadConfig.followPointers, true);
assert.strictEqual(dlvLoadConfig.maxVariableRecurse, 6);
assert.strictEqual(dlvLoadConfig.maxStringLen, 128);
assert.strictEqual(dlvLoadConfig.maxArrayValues, 128);
assert.strictEqual(dlvLoadConfig.maxStructFields, -1);
});
});
});
6 changes: 5 additions & 1 deletion test/runTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ async function main() {
await runTests({
extensionDevelopmentPath,
extensionTestsPath,
launchArgs: ['--disable-extensions'], // disable all other extensions
launchArgs: [
'--disable-extensions',
'--user-data-dir=${workspaceFolder}/.user-data-dir-test',
], // disable all other extensions
});
} catch (err) {
console.error('Failed to run integration tests' + err);
Expand All @@ -37,6 +40,7 @@ async function main() {
extensionTestsPath: path.resolve(__dirname, './gopls/index'),
launchArgs: [
'--disable-extensions', // disable all other extensions
'--user-data-dir=${workspaceFolder}/.user-data-dir-test',
],
});
} catch (err) {
Expand Down

0 comments on commit 5a65ba3

Please sign in to comment.