Skip to content

Commit 805b29c

Browse files
committed
src/goTest.ts: prompt for subtest name if there is no subtest at cursor
Updates #1602 Change-Id: Ibcea9c5980c6c08257f0c6925502eb0b9fd00cdb Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/333309 Trust: Suzy Mueller <[email protected]> Trust: Hyang-Ah Hana Kim <[email protected]> Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
1 parent 800dd70 commit 805b29c

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/goTest.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,22 @@ export async function subTestAtCursor(goConfig: vscode.WorkspaceConfiguration, a
175175
}
176176
}
177177

178+
let subtest: string;
178179
if (!simpleMatch) {
179-
vscode.window.showInformationMessage('No subtest function with a simple subtest name found at cursor.');
180-
return;
180+
const input = await vscode.window.showInputBox({
181+
prompt: 'Enter sub test name'
182+
});
183+
if (input) {
184+
subtest = input;
185+
} else {
186+
vscode.window.showInformationMessage('No subtest function with a simple subtest name found at cursor.');
187+
return;
188+
}
189+
} else {
190+
subtest = simpleMatch[1];
181191
}
182192

183-
const subTestName = testFunctionName + '/' + simpleMatch[1];
193+
const subTestName = testFunctionName + '/' + subtest;
184194

185195
return await runTestAtCursor(editor, subTestName, testFunctions, goConfig, 'test', args);
186196
} catch (err) {

test/integration/codelens.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,19 @@ suite('Code lenses for testing and benchmarking', function () {
8585
test('Subtests - does nothing for a dynamically defined subtest', async () => {
8686
const editor = await vscode.window.showTextDocument(document);
8787
editor.selection = new vscode.Selection(17, 4, 17, 4);
88+
sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves(undefined);
8889
const result = await subTestAtCursor(goConfig, []);
8990
assert.equal(result, undefined);
9091
});
9192

93+
test('Subtests - runs a test with curson on t.Run line and dynamic test name is passed in input box', async () => {
94+
const editor = await vscode.window.showTextDocument(document);
95+
editor.selection = new vscode.Selection(17, 4, 17, 4);
96+
sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves('dynamic test name');
97+
const result = await subTestAtCursor(goConfig, []);
98+
assert.equal(result, false);
99+
});
100+
92101
test('Subtests - does nothing when cursor outside of a test function', async () => {
93102
const editor = await vscode.window.showTextDocument(document);
94103
editor.selection = new vscode.Selection(5, 0, 5, 0);

0 commit comments

Comments
 (0)