Skip to content

Commit

Permalink
src/goTest.ts: prompt for subtest name if there is no subtest at cursor
Browse files Browse the repository at this point in the history
Updates #1602

Change-Id: Ibcea9c5980c6c08257f0c6925502eb0b9fd00cdb
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/333309
Trust: Suzy Mueller <suzmue@golang.org>
Trust: Hyang-Ah Hana Kim <hyangah@gmail.com>
Reviewed-by: Hyang-Ah Hana Kim <hyangah@gmail.com>
  • Loading branch information
suzmue committed Jul 16, 2021
1 parent 800dd70 commit 805b29c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,22 @@ export async function subTestAtCursor(goConfig: vscode.WorkspaceConfiguration, a
}
}

let subtest: string;
if (!simpleMatch) {
vscode.window.showInformationMessage('No subtest function with a simple subtest name found at cursor.');
return;
const input = await vscode.window.showInputBox({
prompt: 'Enter sub test name'
});
if (input) {
subtest = input;
} else {
vscode.window.showInformationMessage('No subtest function with a simple subtest name found at cursor.');
return;
}
} else {
subtest = simpleMatch[1];
}

const subTestName = testFunctionName + '/' + simpleMatch[1];
const subTestName = testFunctionName + '/' + subtest;

return await runTestAtCursor(editor, subTestName, testFunctions, goConfig, 'test', args);
} catch (err) {
Expand Down
9 changes: 9 additions & 0 deletions test/integration/codelens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,19 @@ suite('Code lenses for testing and benchmarking', function () {
test('Subtests - does nothing for a dynamically defined subtest', async () => {
const editor = await vscode.window.showTextDocument(document);
editor.selection = new vscode.Selection(17, 4, 17, 4);
sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves(undefined);
const result = await subTestAtCursor(goConfig, []);
assert.equal(result, undefined);
});

test('Subtests - runs a test with curson on t.Run line and dynamic test name is passed in input box', async () => {
const editor = await vscode.window.showTextDocument(document);
editor.selection = new vscode.Selection(17, 4, 17, 4);
sinon.stub(vscode.window, 'showInputBox').onFirstCall().resolves('dynamic test name');
const result = await subTestAtCursor(goConfig, []);
assert.equal(result, false);
});

test('Subtests - does nothing when cursor outside of a test function', async () => {
const editor = await vscode.window.showTextDocument(document);
editor.selection = new vscode.Selection(5, 0, 5, 0);
Expand Down

0 comments on commit 805b29c

Please sign in to comment.