Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot run nested tests over more than 2 levels #3022

Open
betonetotbo opened this issue Oct 24, 2023 · 5 comments
Open

Cannot run nested tests over more than 2 levels #3022

betonetotbo opened this issue Oct 24, 2023 · 5 comments
Labels
go-test issues related to go test support (test output, test explorer, ...) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@betonetotbo
Copy link

betonetotbo commented Oct 24, 2023

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
@gopherbot gopherbot added this to the Untriaged milestone Oct 24, 2023
@ansaba ansaba added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 24, 2023
@hyangah
Copy link
Contributor

hyangah commented Oct 26, 2023

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 hyangah modified the milestones: Untriaged, vscode-go/backlog Oct 26, 2023
@hyangah hyangah added the go-test issues related to go test support (test output, test explorer, ...) label Oct 26, 2023
@hyangah
Copy link
Contributor

hyangah commented Oct 26, 2023

golang/go#59445 is the issue discussing about moving test discovery to gopls.

@gopherbot
Copy link
Collaborator

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

gopherbot pushed a commit that referenced this issue Dec 8, 2023
This change addresses two issues

1. When the subtest name includes regexp metacharacters,
   they need to be escaped before passing as `-run` flag value
   that assumes regexp. We split around '/' and then escape meta
   characters using escapeRegExp.

2. A bug in getOrCreateSubTest's child search prevented
   looking up a node for the nested subtest. We should've compared
   label with label. Added comments to clarify the difference
   between label and name.

Fixes #3070
Fixes #2624
For #3022 (even though the issue is for the codelens)

Change-Id: I250d1188e91679aee5704e1bccfcd2344cf1ae90
Reviewed-on: https://go-review.googlesource.com/c/vscode-go/+/546260
Reviewed-by: Suzy Mueller <[email protected]>
Commit-Queue: Hyang-Ah Hana Kim <[email protected]>
TryBot-Result: kokoro <[email protected]>
@lkp-k
Copy link

lkp-k commented Jan 20, 2024

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

@firelizzard18
Copy link
Contributor

This should be addressed by #3523

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go-test issues related to go test support (test output, test explorer, ...) NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: No status
Development

No branches or pull requests

6 participants