golang / go

The Go programming language
https://go.dev
BSD 3-Clause "New" or "Revised" License
122.92k stars 17.52k forks source link

x/tools/gopls: no action for TestMain #59067

Open pfcouto opened 1 year ago

pfcouto commented 1 year ago

What version of Go are you using (go version)?

go version go1.19.6 linux/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env

GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/pedro/.cache/go-build"
GOENV="/home/pedro/.config/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/pedro/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/pedro/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/lib/golang"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/golang/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.19.6"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/pedro/Documents/Escola/Mestrado/2semestre/CC/projeto_individual/go.mod"
GOWORK=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build3618416135=/tmp/go-build -gno-record-gcc-switches"

What did you do?

In VSCode when I try to create a TestMain function with the *testing.M nothing appears on top of it to run the test, as shown in the first picture. However, if I change it to something else, like T or even nothing it appears. I don't believe that it is my problem.

image

image

What did you expect to see?

A "run test" clickable text on top of the function

What did you see instead?

The "run test" clickable test does not appear

findleyr commented 1 year ago

We can definitely produce code lenses here, though I think VS Code would also need an update to their middleware to actually invoke the test.

CC @hyangah

pfcouto commented 1 year ago

If you need anything else from me, just @ me and I will be at your disposal. Thanks for the help!

hyangah commented 1 year ago

Related: https://github.com/golang/vscode-go/issues/482

VS Code does not use gopls's test code lenses. The intention was not to present a code lens on TestMain(*testing.M) and obviously it didn't take into account the case where it's actively edited. (another related: https://github.com/golang/vscode-go/issues/2435)

For package-level testing, there is "run package tests" codelens.