vscode-go icon indicating copy to clipboard operation
vscode-go copied to clipboard

Cannot run nested tests over more than 2 levels

Open betonetotbo opened this issue 1 year ago • 6 comments

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

betonetotbo avatar Oct 24 '23 12:10 betonetotbo

This is a known issue. https://go-review.git.corp.google.com/c/vscode-go/+/451755/8..11/src/goRunTestCodelens.ts#b125

// BUG: this does not handle nested subtests. This should
// be solved once codelens is handled by gopls and not by
// vscode.

Unfortunately, this is getting harder to handle from the vscode that currently only relies on the document symbol info and regexp.

hyangah avatar Oct 26 '23 14:10 hyangah

https://github.com/golang/go/issues/59445 is the issue discussing about moving test discovery to gopls.

hyangah avatar Oct 26 '23 20:10 hyangah

Change https://go.dev/cl/546260 mentions this issue: src/goTest: fix bugs in subtest handling

gopherbot avatar Dec 04 '23 19:12 gopherbot

I saw you made a fix for subtest handling, but is that related to this particular issue? I am using 0.40.1

I have similar setup to the issue creator.

Here's a terminal command that works - hopefully it explains the nesting: go test -v -run TestCreateFormEntry/Valid_form_entry_data/Without_linked_data

However in VSC, I am unable to Run/Debug the "Without linked data" subtest. I can however run the "Valid form entry data" test.

Thank you

lkp-k avatar Jan 20 '24 05:01 lkp-k