From 5bef85b160f5473f4894c7c76bc48cd9a3b0bc4a Mon Sep 17 00:00:00 2001 From: vaniog Date: Wed, 25 Dec 2024 22:43:16 +0000 Subject: [PATCH] extension/src/goTest.ts: fix testFunctions filter 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: b80819a031136530e54001aed7fd711eb70c71d2 GitHub-Pull-Request: golang/vscode-go#3639 Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/638755 kokoro-CI: kokoro Reviewed-by: Hyang-Ah Hana Kim Reviewed-by: Hongxiang Jiang Commit-Queue: Ethan Reesor Reviewed-by: Ethan Reesor --- extension/src/goTest.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extension/src/goTest.ts b/extension/src/goTest.ts index ea65083d0d..595b2c0eb2 100644 --- a/extension/src/goTest.ts +++ b/extension/src/goTest.ts @@ -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];