Skip to content

Sub-unit tests are run based on text cursor and not test selected with mouse #3908

@tpyle

Description

@tpyle

What version of Go, VS Code & VS Code Go extension are you using?

Version Information
  • Run go version to get version of Go from the VS Code integrated terminal.
    • go version go1.25.3 linux/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.20.0
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.104.1 0f0d87fa9e96c856c5212fc86db137ac0d783365 x64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.50.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /home/tp6958/.go
GOROOT: /snap/go/10971
PATH: /home/tp6958/.cargo/bin:/home/tp6958/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:/snap/bin:~/.local/bin:/home/tp6958/.go/bin

## Tools

	go:	/snap/go/current/bin/go: go version go1.25.3 linux/amd64

	gopls:	/home/tp6958/.go/bin/gopls	(version: v0.20.0 built with go: go1.25.2)
	gotests:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/home/tp6958/.go/bin/dlv	(version: v1.25.2 built with go: go1.25.2)
	staticcheck:	/home/tp6958/.go/bin/staticcheck	(version: v0.6.1 built with go: go1.25.2)

## Go env

Workspace Folder (nats-authorizer): /home/tp6958/projects/team/alt-trifecta/svc/nats-authorizer

	AR='ar'
	CC='gcc'
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_ENABLED='1'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	CXX='g++'
	GCCGO='gccgo'
	GO111MODULE=''
	GOAMD64='v1'
	GOARCH='amd64'
	GOAUTH='netrc'
	GOBIN=''
	GOCACHE='/home/tp6958/.cache/go-build'
	GOCACHEPROG=''
	GODEBUG=''
	GOENV='/home/tp6958/.config/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFIPS140='off'
	GOFLAGS=''
	GOGCCFLAGS='-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3235621858=/tmp/go-build -gno-record-gcc-switches'
	GOHOSTARCH='amd64'
	GOHOSTOS='linux'
	GOINSECURE=''
	GOMOD='/home/tp6958/projects/team/alt-trifecta/svc/nats-authorizer/go.mod'
	GOMODCACHE='/home/tp6958/.go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='linux'
	GOPATH='/home/tp6958/.go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/snap/go/10971'
	GOSUMDB='sum.golang.org'
	GOTELEMETRY='local'
	GOTELEMETRYDIR='/home/tp6958/.config/go/telemetry'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/snap/go/10971/pkg/tool/linux_amd64'
	GOVCS=''
	GOVERSION='go1.25.3'
	GOWORK=''
	PKG_CONFIG='pkg-config'
	

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file.
Share all the settings with the go. or ["go"] or gopls prefixes.

"go.toolsManagement.autoUpdate": true,

Describe the bug

Description:

When running a test inside of another test (a t.Run) and clicking the run test button added in vscode, it runs the test at the cursor, not the test that was clicked.

Expectation:

The test that is run should be the test that is selected.

Steps to reproduce the behavior:

  1. Create a go file like the following:
package main

import (
	"fmt"
	"testing"
)

func TestExample(t *testing.T) {
	t.Run("subtest1", func(t *testing.T) {
		fmt.Println("In subtest1")
	})

	t.Run("subtest2", func(t *testing.T) {
		fmt.Println("In subtest2")
	})
}
  1. Place your cursor inside subtest 2 (e.g. line 14 in the above)
  2. Click the run test added by vscode before line 9
  3. Observe that the output is -run ^TestExample$/^subtest2$ instead of -run ^TestExample$/^subtest1$

Screenshots or recordings

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions