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

When using go1.24 or later, the Go: Test command no longer displays compile errors

Open shibayu36 opened this issue 8 months ago • 7 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.24.1 darwin/arm64
  • Run gopls -v version to get version of Gopls from the VS Code integrated terminal.
    • golang.org/x/tools/gopls v0.18.1
  • Run code -v or code-insiders -v to get version of VS Code or VS Code Insiders.
    • 1.98.2 ddc367ed5c8936efe395cffeec279b04ffd7db78 arm64
  • Check your installed extensions to get the version of the VS Code Go extension
    • 0.46.1
  • Run Ctrl+Shift+P (Cmd+Shift+P on Mac OS) > Go: Locate Configured Go Tools command.
# Tools Configuration


## Environment

GOBIN: undefined
toolsGopath: 
gopath: /Users/shibayu36/go
GOROOT: /opt/homebrew/Cellar/go/1.24.1/libexec
PATH: /opt/homebrew/Cellar/go/1.24.1/libexec/bin:/Users/shibayu36/.codeium/windsurf/bin:/Users/shibayu36/.poetry/bin:/opt/homebrew/Cellar/zplug/2.4.2/bin:/opt/homebrew/opt/zplug/bin:/opt/homebrew/opt/gettext/bin:/opt/homebrew/opt/libpq/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/imagemagick@6/bin:/usr/local/opt/texinfo/bin:/opt/homebrew/opt/openssl@3/bin:/usr/local/heroku/bin:/Users/shibayu36/go/bin:/Users/shibayu36/.asdf/shims:/opt/homebrew/opt/asdf/libexec/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/shibayu36/.local/bin:/Users/shibayu36/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/opt/local/sbin:/bin:/sbin:/Users/shibayu36/.tfenv/bin:/usr/local/opt/scala/bin:/Users/shibayu36/.poetry/bin:/Users/shibayu36/dotnet:/Users/shibayu36/.orbstack/bin:/opt/homebrew/opt/fzf/bin:/Users/shibayu36/.cache/lm-studio/bin
PATH (vscode launched with): /Users/shibayu36/.codeium/windsurf/bin:/Users/shibayu36/.poetry/bin:/opt/homebrew/Cellar/zplug/2.4.2/bin:/opt/homebrew/opt/zplug/bin:/opt/homebrew/opt/gettext/bin:/opt/homebrew/opt/libpq/bin:/opt/homebrew/opt/[email protected]/bin:/opt/homebrew/opt/imagemagick@6/bin:/usr/local/opt/texinfo/bin:/opt/homebrew/opt/openssl@3/bin:/usr/local/heroku/bin:/Users/shibayu36/go/bin:/Users/shibayu36/.asdf/shims:/opt/homebrew/opt/asdf/libexec/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/Users/shibayu36/.local/bin:/Users/shibayu36/bin:/usr/local/bin:/usr/local/sbin:/opt/local/bin:/usr/bin:/usr/sbin:/opt/local/sbin:/bin:/sbin:/Users/shibayu36/.tfenv/bin:/usr/local/opt/scala/bin:/Users/shibayu36/.poetry/bin:/Users/shibayu36/dotnet:/Users/shibayu36/.orbstack/bin:/opt/homebrew/opt/fzf/bin:/Users/shibayu36/.cache/lm-studio/bin

## Tools

	go:	/opt/homebrew/bin/go: go version go1.24.1 darwin/arm64

	gopls:	/Users/shibayu36/go/bin/gopls	(version: v0.18.1 built with go: go1.24.0)
	gotests:	not installed
	gomodifytags:	not installed
	impl:	not installed
	goplay:	not installed
	dlv:	/Users/shibayu36/go/bin/dlv	(version: v1.24.0 built with go: go1.24.0)
	golangci-lint:	/Users/shibayu36/go/bin/golangci-lint	(version: v1.64.6 built with go: go1.24.0)

## Go env

Workspace Folder (vscode-go): /Users/shibayu36/development/src/github.com/golang/vscode-go

	AR='ar'
	CC='cc'
	CGO_CFLAGS='-O2 -g'
	CGO_CPPFLAGS=''
	CGO_CXXFLAGS='-O2 -g'
	CGO_ENABLED='1'
	CGO_FFLAGS='-O2 -g'
	CGO_LDFLAGS='-O2 -g'
	CXX='c++'
	GCCGO='gccgo'
	GO111MODULE=''
	GOARCH='arm64'
	GOARM64='v8.0'
	GOAUTH='netrc'
	GOBIN=''
	GOCACHE='/Users/shibayu36/Library/Caches/go-build'
	GOCACHEPROG=''
	GODEBUG=''
	GOENV='/Users/shibayu36/Library/Application Support/go/env'
	GOEXE=''
	GOEXPERIMENT=''
	GOFIPS140='off'
	GOFLAGS=''
	GOGCCFLAGS='-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/7r/7nyxrx15693bsgd6gwv749g00000gn/T/go-build2791924945=/tmp/go-build -gno-record-gcc-switches -fno-common'
	GOHOSTARCH='arm64'
	GOHOSTOS='darwin'
	GOINSECURE=''
	GOMOD='/Users/shibayu36/development/src/github.com/golang/vscode-go/go.mod'
	GOMODCACHE='/Users/shibayu36/go/pkg/mod'
	GONOPROXY=''
	GONOSUMDB=''
	GOOS='darwin'
	GOPATH='/Users/shibayu36/go'
	GOPRIVATE=''
	GOPROXY='https://proxy.golang.org,direct'
	GOROOT='/opt/homebrew/Cellar/go/1.24.1/libexec'
	GOSUMDB='sum.golang.org'
	GOTELEMETRY='local'
	GOTELEMETRYDIR='/Users/shibayu36/Library/Application Support/go/telemetry'
	GOTMPDIR=''
	GOTOOLCHAIN='auto'
	GOTOOLDIR='/opt/homebrew/Cellar/go/1.24.1/libexec/pkg/tool/darwin_arm64'
	GOVCS=''
	GOVERSION='go1.24.1'
	GOWORK=''
	PKG_CONFIG='pkg-config'

Share the Go related settings you have added/edited

Run Preferences: Open Settings (JSON) command to open your settings.json file. Share all the settings with the go. or ["go"] or gopls prefixes.

  "go.alternateTools": {
    "go": "/opt/homebrew/bin/go",
    "go-langserver": "gopls"
  },
  "go.languageServerExperimentalFeatures": {
    "autoComplete": true,
    "format": true
  },
  "go.lintFlags": [
    "--fast"
  ],
  "go.lintTool": "golangci-lint",
  "go.testFlags": [
    "-v",
    "-count=1",
    "-timeout=120s"
  ],
  "go.toolsManagement.autoUpdate": true,
  "[go]": {
    "editor.codeActionsOnSave": {
      "source.organizeImports": "explicit"
    },
    "editor.formatOnSave": true,
    "editor.snippetSuggestions": "none"
  },

Describe the bug

After upgrading to Go 1.24, running the Go: Test command (e.g. Go: Test File) no longer displays compile errors in the Output.

It is probably because in go1.24, go test -json now returns the build output in JSON as well.

https://tip.golang.org/doc/go1.24

Furthermore, go test -json now reports build output and failures in JSON, interleaved with test result JSON. These are distinguished by new Action types, but if they cause problems in a test integration system, you can revert to the text build output with GODEBUG setting gotestjsonbuildtext=1.

Steps to reproduce the behavior:

  1. Edit a file to cause a compilation error.
  2. Run the Go: Test File command.
  3. Check the output.

Screenshots or recordings

If applicable, add screenshots or recordings to help explain your problem.

Cause a compile error Image

When running Go: Test File using go1.24 Image

When running Go: Test File using go1.23

Image

shibayu36 avatar Apr 03 '25 00:04 shibayu36

CC @h9jiang

I'm confused, as I get build errors on stderr both 1.23 and 1.24, so I'm not sure why the Go version would matter here.

findleyr avatar Apr 04 '25 14:04 findleyr

@findleyr Go 1.24 changes how go test -json behaves. Given:

func Test(t *testing.T) { 1 }

go1.23.1 test -json writes build errors to stderr, unformatted:

# test [test.test]
./test_test.go:5:27: 1 (untyped int constant) is not used
{"Time":"2025-04-04T12:08:57.467679875-05:00","Action":"start","Package":"test"}
{"Time":"2025-04-04T12:08:57.467719442-05:00","Action":"output","Package":"test","Output":"FAIL\ttest [build failed]\n"}
{"Time":"2025-04-04T12:08:57.467723667-05:00","Action":"fail","Package":"test","Elapsed":0}

go1.24.2 test -json JSON-ifies build errors and writes them to stdout, the same as regular error output:

{"ImportPath":"test [test.test]","Action":"build-output","Output":"# test [test.test]\n"}
{"ImportPath":"test [test.test]","Action":"build-output","Output":"./test_test.go:5:27: 1 (untyped int constant) is not used\n"}
{"ImportPath":"test [test.test]","Action":"build-fail"}
{"Time":"2025-04-04T12:14:45.320982183-05:00","Action":"start","Package":"test"}
{"Time":"2025-04-04T12:14:45.32101052-05:00","Action":"output","Package":"test","Output":"FAIL\ttest [build failed]\n"}
{"Time":"2025-04-04T12:14:45.321015248-05:00","Action":"fail","Package":"test","Elapsed":0,"FailedBuild":"test [test.test]"}

Presumably, the existing code is detecting output that's written to stderr (and probably the return code) and using that to detect and display failures. And now, the build error output has been merged into the JSON event stream with new Action values (build-output, build-fail) that aren't handled.

firelizzard18 avatar Apr 04 '25 17:04 firelizzard18

Thanks @firelizzard18 and @shibayu36 for investigating.

@h9jiang this is a semi-urgent bug to fix. Putting in the next milestone. It should hopefully be easy to address.

findleyr avatar Apr 04 '25 17:04 findleyr

I believe the relevant code is in extension/src/testUtils.ts, goTest or one of the functions it calls. Though now that I look at it I'm confused. The test explorer (old or new) always uses -json but it appears that @shibayu36 is using the legacy test support and I can reproduce this issue with the legacy code lenses. And I thought that would run the test without -json and would use processTestResultLineInStandardMode to handle output, which shouldn't have this issue. But maybe it's still adding -json somewhere. If that's the case, then updating processTestResultLineInJSONMode may be sufficient:

- 			if (m.Action !== 'output' || !m.Output) {
+ 			if (!(m.Action === 'output' || m.Action === 'build-output') || !m.Output) {
 				return;
 			}

firelizzard18 avatar Apr 04 '25 18:04 firelizzard18

I think the -json flag is being added because I have -v in go.testFlags.

"go.testFlags": [
  "-v",
  "-count=1",
  "-timeout=120s"
]

As a result, the -json output might be enabled by const addJSONFlag = (userFlags.includes('-v') || testconfig.goTestOutputConsumer) && !userFlags.includes('-json');

and that could be why outBuf.onLine((line) => processTestResultLine(line)); can't handle the output properly.

By the way, when I removed -v from the settings, the compile errors started showing up again.

shibayu36 avatar Apr 07 '25 00:04 shibayu36

That does seem like the answer and I think I also have -v set. Thanks for pointing that out, I missed it when I looked at that code.

firelizzard18 avatar Apr 07 '25 01:04 firelizzard18

I’m experiencing a similar issue with the Test Results view. It only shows:

FAIL    <package> [build failed]

No additional information is provided.

anttsov avatar Aug 29 '25 09:08 anttsov