Skip to content

Commit

Permalink
extension/src/goTest.ts: fix testFunctions filter
Browse files Browse the repository at this point in the history
Add conditional filtering for test functions based on provided
function name in _subTestAtCursor

Using functionName if it was provided as argument, otherwise
find any test function containing the cursor.

This change fixes a bug that previously required the cursor to be
within the parent function to run subtests.
Now, subtests can be executed even if the cursor is not positioned
in the parent function.

Change-Id: I2667acb6bd5586664ea3b306112bfd9eaa54db76
GitHub-Last-Rev: b80819a
GitHub-Pull-Request: #3639
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/638755
kokoro-CI: kokoro <[email protected]>
Reviewed-by: Hyang-Ah Hana Kim <[email protected]>
Reviewed-by: Hongxiang Jiang <[email protected]>
Commit-Queue: Ethan Reesor <[email protected]>
Reviewed-by: Ethan Reesor <[email protected]>
  • Loading branch information
Vaniog authored and hyangah committed Dec 26, 2024
1 parent 58145f9 commit 5bef85b
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion extension/src/goTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@ async function _subTestAtCursor(
const { testFunctions, suiteToTest } = await getTestFunctionsAndTestSuite(false, goCtx, editor.document);
// We use functionName if it was provided as argument
// Otherwise find any test function containing the cursor.
const currentTestFunctions = testFunctions.filter((func) => func.range.contains(editor.selection.start));
const currentTestFunctions = args.functionName
? testFunctions.filter((func) => func.name === args.functionName)
: testFunctions.filter((func) => func.range.contains(editor.selection.start));
const testFunctionName =
args && args.functionName ? args.functionName : currentTestFunctions.map((el) => el.name)[0];

Expand Down

0 comments on commit 5bef85b

Please sign in to comment.