Skip to content

Run test button cannot locate the test path correctly for embedded tests #3657

Open
@emreisikligil

Description

@emreisikligil

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.23.2 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • Version: 1.96.2
      Commit: fabdb6a30b49f79a7aba0f2ad9df9b399473380f
      Date: 2024-12-19T10:22:47.216Z
      Electron: 32.2.6
      ElectronBuildId: 10629634
      Chromium: 128.0.6613.186
      Node.js: 20.18.1
      V8: 12.8.374.38-electron.0
      OS: Darwin x64 24.2.0
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.45.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • Tools Configuration

          ## Environment
          
          GOBIN: undefined
          toolsGopath: 
          gopath: /Users/emreisikligil/go
          GOROOT: /usr/local/Cellar/go/1.23.2/libexec
          PATH: /Library/Frameworks/Python.framework/Versions/3.9/bin:/usr/local/sbin:/Applications/apache-jmeter-5.0/bin:/usr/local/opt/[email protected]/bin:/Users/emreisikligil/go/bin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/opt/X11/bin:/usr/texbin:/usr/local/go/bin
          
          ## Tools
          
              go:	/usr/local/bin/go: go version go1.23.2 darwin/amd64
          
              gopls:	/Users/emreisikligil/go/bin/gopls	(version: v0.17.1 built with go: go1.23.2)
              gotests:	not installed
              gomodifytags:	/Users/emreisikligil/go/bin/gomodifytags	(version: v1.17.0 built with go: go1.23.2)
              impl:	/Users/emreisikligil/go/bin/impl	(version: v1.4.0 built with go: go1.23.2)
              goplay:	not installed
              dlv:	/Users/emreisikligil/go/bin/dlv	(version: v1.23.1 built with go: go1.23.2)
              golangci-lint:	/Users/emreisikligil/go/bin/golangci-lint	(version: v1.61.0 built with go: go1.23.2)
          
          ## Go env
          
          Workspace Folder (test): /Users/emreisikligil/Desktop/test
          
              GO111MODULE=''
              GOARCH='amd64'
              GOBIN=''
              GOCACHE='/Users/emreisikligil/Library/Caches/go-build'
              GOENV='/Users/emreisikligil/Library/Application Support/go/env'
              GOEXE=''
              GOEXPERIMENT=''
              GOFLAGS=''
              GOHOSTARCH='amd64'
              GOHOSTOS='darwin'
              GOINSECURE=''
              GOMODCACHE='/Users/emreisikligil/go/pkg/mod'
              GONOPROXY='github.com/SharperShape'
              GONOSUMDB='github.com/SharperShape'
              GOOS='darwin'
              GOPATH='/Users/emreisikligil/go'
              GOPRIVATE='github.com/SharperShape'
              GOPROXY='https://proxy.golang.org,direct'
              GOROOT='/usr/local/Cellar/go/1.23.2/libexec'
              GOSUMDB='sum.golang.org'
              GOTMPDIR=''
              GOTOOLCHAIN='local'
              GOTOOLDIR='/usr/local/Cellar/go/1.23.2/libexec/pkg/tool/darwin_amd64'
              GOVCS=''
              GOVERSION='go1.23.2'
              GODEBUG=''
              GOTELEMETRY='local'
              GOTELEMETRYDIR='/Users/emreisikligil/Library/Application Support/go/telemetry'
              GCCGO='gccgo'
              GOAMD64='v1'
              AR='ar'
              CC='cc'
              CXX='c++'
              CGO_ENABLED='1'
              GOMOD='/Users/emreisikligil/Desktop/test/go.mod'
              GOWORK=''
              CGO_CFLAGS='-O2 -g'
              CGO_CPPFLAGS=''
              CGO_CXXFLAGS='-O2 -g'
              CGO_FFLAGS='-O2 -g'
              CGO_LDFLAGS='-O2 -g'
              PKG_CONFIG='pkg-config'
              GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/kj/09g_3wgs5tn10g33fnqxm02r0000gn/T/go-build2279188997=/tmp/go-build -gno-record-gcc-switches -fno-common'
      

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.gopath": "",
  "go.testFlags": ["-v"],
  "go.lintTool": "golangci-lint",
  "go.lintFlags": ["--fast"],
  "go.delveConfig": {
    "dlvLoadConfig": {
      "followPointers": true,
      "maxVariableRecurse": 1,
      "maxStringLen": 1024,
      "maxArrayValues": 64,
      "maxStructFields": -1
    },
    "apiVersion": 2,
    "showGlobalVariables": false,
    "debugAdapter": "dlv-dap"
  },
  "go.lintOnSave": "file"
  "go.toolsManagement.autoUpdate": true,
  "go.coverageDecorator": {
    "type": "gutter",
    "uncoveredGutterStyle": "blockyellow"
  },
  "go.testTimeout": "5m",
  "go.inlayHints.constantValues": true,
  "go.coverOnTestPackage": false,

Describe the bug

When I run or debug an embedded test on level 2 or more using run test | debug test button on top of t.Run statement, the extension passes a wrong path to the go tool and it returns with testing: warning: no tests to run.

Let's say I have 3 layer of tests as below. When I try to run Inner test, it executes the following command which ends up failing to find the correct test.

func Test(t *testing.T) {
	
	t.Run("Middle test", func(t *testing.T) {
		
		t.Run("Inner test", func(t *testing.T) {
			t.Log("Inner test")
		})
	})
}
Running tool: /usr/local/bin/go test -timeout 5m -run ^Test$/^Inner_test$ github.com/emreisikligil/test -v

=== RUN   Test
--- PASS: Test (0.00s)
testing: warning: no tests to run
PASS
ok  	github.com/emreisikligil/test	0.466s [no tests to run]

The expected behavior is to run the corresponding test.

Steps to reproduce the behavior:

  1. Create a folder named test.
  2. Put the following files into the folder

main_test.go:

package main

import "testing"

func Test(t *testing.T) {
	
	t.Run("Middle test", func(t *testing.T) {
		
		t.Run("Inner test", func(t *testing.T) {
			t.Log("Inner test")
			t.Log("Inner test")
		})
	})
}

go.mod:

module github.com/test/test

go 1.23
  1. Open main_test in VSCode
  2. Click on run test or debug test on top of t.Run("Inner test", func(t *testing.T) {

Screenshots or recordings

Screenshot 2025-01-09 at 3 14 36 PM

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