Skip to content

Cannot run nested tests over more than 2 levels #3022

Open
@betonetotbo

Description

@betonetotbo

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.21.1 linux/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.
    1.83.1
    f1b07bd25dfad64b0167beb15359ae573aecd2cc
    x64
    ```
  • Check your installed extensions to get the version of the VS Code Go extension
    • v0.39.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
    • Checking configured tools....
      GOBIN: undefined
      toolsGopath: 
      gopath: /home/roberto.neto/go
      GOROOT: /usr/local/go
      PATH: /home/roberto.neto/.local/bin:/home/roberto.neto/.nvm/versions/node/v14.21.1/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/snap/bin:/usr/local/go/bin:/home/roberto.neto/go/bin:/usr/local/go/bin/
      
          go:	/usr/local/go/bin/go: go version go1.21.1 linux/amd64
      
          gotests:	not installed
          gomodifytags:	not installed
          impl:	not installed
          goplay:	not installed
          dlv:	/home/roberto.neto/go/bin/dlv	(version: v1.21.0 built with go: go1.21.1)
          staticcheck:	/home/roberto.neto/go/bin/staticcheck	(version: v0.4.6 built with go: go1.21.1)
          gopls:	/home/roberto.neto/go/bin/gopls	(version: v0.13.2 built with go: go1.21.1)
      
      go env
      Workspace Folder (legacy-gateway): /home/roberto.neto/sources/legacy-gateway
          GO111MODULE=''
          GOARCH='amd64'
          GOBIN=''
          GOCACHE='/home/roberto.neto/.cache/go-build'
          GOENV='/home/roberto.neto/.config/go/env'
          GOEXE=''
          GOEXPERIMENT=''
          GOFLAGS=''
          GOHOSTARCH='amd64'
          GOHOSTOS='linux'
          GOINSECURE=''
          GOMODCACHE='/home/roberto.neto/go/pkg/mod'
          GONOPROXY=''
          GONOSUMDB='git.senior.com.br'
          GOOS='linux'
          GOPATH='/home/roberto.neto/go'
          GOPRIVATE=''
          GOPROXY='https://proxy.golang.org,https://******:*******@**********/artifactory/api/go/go,direct'
          GOROOT='/usr/local/go'
          GOSUMDB='sum.golang.org'
          GOTMPDIR=''
          GOTOOLCHAIN='auto'
          GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
          GOVCS=''
          GOVERSION='go1.21.1'
          GCCGO='gccgo'
          GOAMD64='v1'
          AR='ar'
          CC='gcc'
          CXX='g++'
          CGO_ENABLED='0'
          GOMOD='/home/roberto.neto/sources/legacy-gateway/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 -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build1985667666=/tmp/go-build -gno-record-gcc-switches'
      

Share the Go related settings you have added/edited

    "go.testFlags": [
        "-v"
    ],
    "go.testTags": "testing,skip_postgres",
    "go.buildTags": "testing",
    "go.formatTool": "gofmt",
    "gopls": {
    },
    "go.testEnvVars": {
        "TF_ACC": "1",
    },

Describe the bug

When I write nested tests like this one:

func TestTokenSwitcherServiceImpl(t *testing.T) { // level 1

	t.Run("SwitchTokenToJwt", func(t *testing.T) { // level 2

		t.Run("AlreadyAJwt", func(t *testing.T) { // level 3
                    // .... code ...
                })
        })
}

I'm not able to run the "level 3" (AlreadyAJwt) test using the extension shortcut inside the code editor.

shortcut

The output prints an info saying warning: no tests to run:

Running tool: /usr/local/go/bin/go test -timeout 30s -tags testing,skip_postgres -run ^\QTestTokenSwitcherServiceImpl\E$/^\QAlreadyAJwt\E$ mygithost.com/project-name/mypackage -v

=== RUN   TestTokenSwitcherServiceImpl
--- PASS: TestTokenSwitcherServiceImpl (0.00s)
testing: warning: no tests to run
PASS
ok  	mygithost.com/project-name/mypackage	(cached) [no tests to run]

Note that the go test generated by the extension seams to be the problem, the arg -run is not considering the "parent-child" test SwitchTokenToJwt: -run ^\QTestTokenSwitcherServiceImpl\E$/^\QAlreadyAJwt\E$

Steps to reproduce the behavior:

  1. Create a test file
  2. Declare a test unit function
  3. Create a nested test A
  4. Create another nested test B inside A
  5. Try to run the test B using the editor shortcut

Metadata

Metadata

Assignees

No one assigned

    Labels

    Go CompanionIssues relating to the Go Companion extensionNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.go-testissues related to go test support (test output, test explorer, ...)

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions