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

Commit

Permalink
Use build & test tags in debug test at cursor cmd #2953
Browse files Browse the repository at this point in the history
  • Loading branch information
ramya-rao-a committed Dec 27, 2019
1 parent da2c54c commit d6b6668
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/goRunTestCodelens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import path = require('path');
import { CancellationToken, CodeLens, Command, TextDocument } from 'vscode';
import { GoBaseCodeLensProvider } from './goBaseCodelens';
import { GoDocumentSymbolProvider } from './goOutline';
import { getBenchmarkFunctions, getTestFlags, getTestFunctionDebugArgs, getTestFunctions } from './testUtils';
import { getBenchmarkFunctions, getTestFlags, getTestFunctionDebugArgs, getTestFunctions, getTestTags } from './testUtils';
import { getCurrentGoPath, getGoConfig } from './util';

export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
Expand Down Expand Up @@ -88,9 +88,9 @@ export class GoRunTestCodeLensProvider extends GoBaseCodeLensProvider {
const env = Object.assign({}, this.debugConfig.env, vsConfig['testEnvVars']);
const envFile = vsConfig['testEnvFile'];
const buildFlags = getTestFlags(vsConfig);
if (vsConfig['buildTags'] && buildFlags.indexOf('-tags') === -1) {
buildFlags.push('-tags');
buildFlags.push(`${vsConfig['buildTags']}`);
const tags = getTestTags(vsConfig);
if (tags && buildFlags.indexOf('-tags') === -1) {
buildFlags.push('-tags', tags);
}
const currentDebugConfig = Object.assign({}, this.debugConfig, { program, env, envFile, buildFlags: buildFlags.map(x => `'${x}'`).join(' ') });

Expand Down
5 changes: 3 additions & 2 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import path = require('path');
import vscode = require('vscode');
import { applyCodeCoverageToAllEditors } from './goCover';
import { isModSupported } from './goModules';
import { extractInstanceTestName, findAllTestSuiteRuns, getBenchmarkFunctions, getTestFlags, getTestFunctionDebugArgs, getTestFunctions, goTest, TestConfig } from './testUtils';
import { extractInstanceTestName, findAllTestSuiteRuns, getBenchmarkFunctions, getTestFlags, getTestFunctionDebugArgs, getTestFunctions, goTest, TestConfig, getTestTags } from './testUtils';
import { getTempFilePath } from './util';

// lastTestConfig holds a reference to the last executed TestConfig which allows
Expand Down Expand Up @@ -106,7 +106,8 @@ async function debugTestAtCursor(editor: vscode.TextEditor, testFunctionName: st
program: editor.document.fileName,
env: goConfig.get('testEnvVars', {}),
envFile: goConfig.get('testEnvFile'),
args
args,
buildFlags: ['-tags', getTestTags(goConfig)].join(' ')
};
return await vscode.debug.startDebugging(workspaceFolder, debugConfig);
}
Expand Down
6 changes: 5 additions & 1 deletion src/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ export function getTestFlags(goConfig: vscode.WorkspaceConfiguration, args?: any
return (args && args.hasOwnProperty('flags') && Array.isArray(args['flags'])) ? args['flags'] : testFlags;
}

export function getTestTags(goConfig: vscode.WorkspaceConfiguration): string {
return goConfig['testTags'] !== null ? goConfig['testTags'] : goConfig['buildTags'];
}

/**
* Returns all Go unit test functions in the given source file.
*
Expand Down Expand Up @@ -193,7 +197,7 @@ export function goTest(testconfig: TestConfig): Thenable<boolean> {
outputChannel.show(true);
}

const testTags: string = testconfig.goConfig['testTags'] !== null ? testconfig.goConfig['testTags'] : testconfig.goConfig['buildTags'];
const testTags: string = getTestTags(testconfig.goConfig);
const args: Array<string> = ['test'];
const testType: string = testconfig.isBenchmark ? 'Benchmarks' : 'Tests';

Expand Down

0 comments on commit d6b6668

Please # to comment.