vscode-go
vscode-go copied to clipboard
Cannot run nested tests over more than 2 levels
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.-
Build info ---------- golang.org/x/tools/gopls v0.13.2 golang.org/x/tools/[email protected] h1:Pyvx6MKvatbX3zzZmdGiFRfQZl0ohPlt2sFxO/5j6Ro= github.com/BurntSushi/[email protected] h1:9F2/+DoOYIOksmaJFPw1tGFy1eDnIJXg+UHjuD8lTak= github.com/google/[email protected] h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/sergi/[email protected] h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= golang.org/x/[email protected] h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA= golang.org/x/exp/[email protected] h1:2O2DON6y3XMJiQRAS1UWU+54aec2uopH3x7MAiqGW6Y= golang.org/x/[email protected] h1:rmsUpXtvNzj340zd98LZ4KntptpfRHwpFOHG188oHXc= golang.org/x/[email protected] h1:ftCYgMx6zT/asHUrPw8BLLscYtGznsLAnjq5RH9P66E= golang.org/x/[email protected] h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA= golang.org/x/[email protected] h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4= golang.org/x/[email protected] h1:Oush7UwPamr2/iNeNFBuNFj89YyHn0YY69EKDdvANnk= golang.org/x/[email protected] h1:A9kONVi4+AnuOr1dopsibH6hLi1Huy54cbeJxnq4vmU= honnef.co/go/[email protected] h1:6qXr+R5w+ktL5UkwEbPp+fEvfyoMPche6GkOpGHZcLc= mvdan.cc/[email protected] h1:JVf4NN1mIpHogBj7ABpgOyZc65/UUOkKQFkoURsz4MM= mvdan.cc/xurls/[email protected] h1:tzxjVAj+wSBmDcF6zBB7/myTy3gX9xvi8Tyr28AuQgc= go: go1.21.1
-
- Run
code -v
orcode-insiders -v
to get version of VS Code or VS Code Insiders. -
- 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.
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:
- Create a test file
- Declare a test unit function
- Create a nested test A
- Create another nested test B inside A
- Try to run the test B using the editor shortcut
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.
https://github.com/golang/go/issues/59445 is the issue discussing about moving test discovery to gopls.
Change https://go.dev/cl/546260 mentions this issue: src/goTest: fix bugs in subtest handling
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