Skip to content

Commit 419a04f

Browse files
Alysson Ribeirosonalys
authored andcommitted
fix(goTest): handler for debugging suite tests
1 parent 69d7004 commit 419a04f

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

extension/src/goTest.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ async function _testAtCursor(
4444
goCtx: GoExtensionContext,
4545
goConfig: vscode.WorkspaceConfiguration,
4646
cmd: TestAtCursorCmd,
47-
args: any
47+
args?: SubTestAtCursorArgs
4848
) {
4949
const editor = vscode.window.activeTextEditor;
5050
if (!editor) {
@@ -72,7 +72,7 @@ async function _testAtCursor(
7272
await editor.document.save();
7373

7474
if (cmd === 'debug') {
75-
return debugTestAtCursor(editor, testFunctionName, testFunctions, suiteToTest, goConfig);
75+
return debugTestAtCursor(editor, testFunctionName, testFunctions, suiteToTest, goConfig, undefined, args);
7676
} else if (cmd === 'benchmark' || cmd === 'test') {
7777
return runTestAtCursor(editor, testFunctionName, testFunctions, suiteToTest, goConfig, cmd, args);
7878
} else {
@@ -165,7 +165,7 @@ async function _subTestAtCursor(
165165
const escapedName = escapeSubTestName(testFunctionName, subTestName);
166166

167167
if (cmd === 'debug') {
168-
return debugTestAtCursor(editor, escapedName, testFunctions, suiteToTest, goConfig);
168+
return debugTestAtCursor(editor, escapedName, testFunctions, suiteToTest, goConfig, undefined, args);
169169
} else if (cmd === 'test') {
170170
return runTestAtCursor(editor, escapedName, testFunctions, suiteToTest, goConfig, cmd, args);
171171
} else {
@@ -308,10 +308,11 @@ export async function debugTestAtCursor(
308308
testFunctions: vscode.DocumentSymbol[],
309309
suiteToFunc: SuiteToTestMap,
310310
goConfig: vscode.WorkspaceConfiguration,
311-
sessionID?: string
311+
sessionID?: string,
312+
testArgs?: { isTestSuite?: boolean },
312313
) {
313314
const doc = 'document' in editorOrDocument ? editorOrDocument.document : editorOrDocument;
314-
const args = getTestFunctionDebugArgs(doc, testFunctionName, testFunctions, suiteToFunc);
315+
const args = getTestFunctionDebugArgs(doc, testFunctionName, testFunctions, suiteToFunc, testArgs?.isTestSuite);
315316
const tags = getTestTags(goConfig);
316317
const buildFlags = tags ? ['-tags', tags] : [];
317318
const flagsFromConfig = getTestFlags(goConfig);

extension/src/testUtils.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,12 +250,14 @@ export function extractInstanceTestName(symbolName: string): string {
250250
* @param document The document containing the tests
251251
* @param testFunctionName The test function to get the debug args
252252
* @param testFunctions The test functions found in the document
253+
* @param isTestSuite Indicator if the test function is part of a test suite
253254
*/
254255
export function getTestFunctionDebugArgs(
255256
document: vscode.TextDocument,
256257
testFunctionName: string,
257258
testFunctions: vscode.DocumentSymbol[],
258-
suiteToFunc: SuiteToTestMap
259+
suiteToFunc: SuiteToTestMap,
260+
isTestSuite ?: boolean,
259261
): string[] {
260262
if (benchmarkRegex.test(testFunctionName)) {
261263
return ['-test.bench', '^' + testFunctionName + '$', '-test.run', 'a^'];
@@ -265,7 +267,7 @@ export function getTestFunctionDebugArgs(
265267
const testFns = findAllTestSuiteRuns(document, testFunctions, suiteToFunc);
266268
return ['-test.run', `^${testFns.map((t) => t.name).join('|')}$/^${instanceMethod}$`];
267269
} else {
268-
return ['-test.run', `^${testFunctionName}$`];
270+
return ['-test.run', `${!!isTestSuite ? '/': ''}^${testFunctionName}$`];
269271
}
270272
}
271273
/**

0 commit comments

Comments
 (0)