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 debug single test in VS Code #1177

Closed
zxy198717 opened this issue Apr 16, 2022 · 5 comments
Closed

cannot debug single test in VS Code #1177

zxy198717 opened this issue Apr 16, 2022 · 5 comments

Comments

@zxy198717
Copy link

image

click debug test, but debug console output:

Starting: [/Users/tom/go/bin/dlv]() dap --check-go-version=false --listen=127.0.0.1:60712 --log-dest=3 from [/Users/tom/workspace/playground/tests]()
DAP server listening at: 127.0.0.1:60712
Type 'dlv help' for list of commands.
testing: warning: no tests to run
PASS
Process 38235 has exited with status 0
Detaching
dlv dap (38199) exited with code: 0

seems no test detect, works ok when click run test.

@brackendawson
Copy link
Collaborator

This works fine for me. Post your environment details and a full compilable example.

@zxy198717 zxy198717 reopened this Apr 19, 2022
@zxy198717
Copy link
Author

zxy198717 commented Apr 19, 2022

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.

    • go1.17.2 darwin/amd64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.

    • golang.org/x/tools/gopls v0.8.3
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.

    • 1.66.2
  • Check your installed extensions to get the version of the VS Code Go extension

    • v0.32.0
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.

    • Checking configured tools....
      GOBIN: undefined
      toolsGopath:
      gopath: /Users/tom/go
      GOROOT: /usr/local/Cellar/go/1.17.2/libexec
      PATH: /Users/tom/.rvm/gems/ruby-2.7.0/bin:/Users/tom/.rvm/gems/ruby-2.7.0@global/bin:/Users/tom/.rvm/rubies/ruby-2.7.0/bin:/usr/local/opt/[email protected]/bin:/Users/tom/torch/install/bin:/Users/tom/.nvm/versions/node/v14.8.0/bin:/Users/tom/.gem/bin:/Users/tom/go/bin:/usr/local/sbin:/Users/tom/.sdkman/candidates/gradle/current/bin:/Users/tom/.pyenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/Library/Apple/usr/bin:/Users/Tom/Library/Android/sdk/tools:/Users/Tom/Library/Android/sdk/platform-tools:/Users/tom/.rvm/bin

    go: /usr/local/bin/go: go version go1.17.2 darwin/amd64

    go-outline: /Users/tom/go/bin/go-outline (version: v0.0.0-20210608161538-9736a4bde949 built with go: go1.17.2)
    gotests: /Users/tom/go/bin/gotests (version: v1.6.0 built with go: go1.17.2)
    gomodifytags: /Users/tom/go/bin/gomodifytags (version: v1.16.0 built with go: go1.17.2)
    impl: /Users/tom/go/bin/impl (version: v1.1.0 built with go: go1.17.2)
    goplay: /Users/tom/go/bin/goplay (version: v1.0.0 built with go: go1.17.2)
    dlv: /Users/tom/go/bin/dlv (version: v1.8.2 built with go: go1.17.2)
    golangci-lint: /Users/tom/go/bin/golangci-lint (version: (devel) built with go: go1.17.7)
    gopls: /Users/tom/go/bin/gopls (version: v0.8.3 built with go: go1.17.2)

go env
Workspace Folder (playground): /Users/tom/workspace/playground
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/tom/Library/Caches/go-build"
GOENV="/Users/tom/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS="-mod=vendor"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/tom/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/tom/go"
GOPRIVATE=""
GOPROXY="https://goproxy.cn,direct"
GOROOT="/usr/local/Cellar/go/1.17.2/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.17.2/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.17.2"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/tom/workspace/playground/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/xx/rkz1tt1j1nb5wt4j8zr7kcp00000gn/T/go-build3718678352=/tmp/go-build -gno-record-gcc-switches -fno-common"

  • main_test.go
package main

import (
	"log"
	"testing"

	"github.com/stretchr/testify/suite"
)

type PlaygroundSuite struct {
	suite.Suite
}

func TestPlaygroundSuite(t *testing.T) {
	mallSuit := new(PlaygroundSuite)
	suite.Run(t, mallSuit)
}

// can debug
func (self *PlaygroundSuite) TestFoo() {
	v := "bar"

	log.Println(v)
}

  • other_test.go
package main

import (
	"log"

	_ "github.com/stretchr/testify/suite"
)

// cannot debug
func (self *PlaygroundSuite) TestFar() {
	v := "bar"

	log.Println(v)
}

@brackendawson seems cannnot debug test case in file other_test.go

@brackendawson
Copy link
Collaborator

With the above file layout I can re-create this on Go 1.18.

This run configuration works though:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch TestFar",
            "type": "go",
            "request": "launch",
            "mode": "test",
            "program": "${fileDirname}",
            "args": ["-test.run", "PlaygroundSuite/TestFar"],
        }
    ]
}

I suspect this is probably a bug in the run configuration generated by the "debug test" button in the VSCode Go plugin, I'm actually surprised it works with testify/suite at all. I don't know how to see the run configuration VSCode uses here, probably best to open an issue here.

@brackendawson
Copy link
Collaborator

Which I see you already did golang/vscode-go#2189

@zxy198717
Copy link
Author

Thanks, will track it by golang/vscode-go#2189.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants