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

cmd/go: go test -json has non-JSON printed to stdout when build fails #35169

Closed
ailurarctos opened this issue Oct 26, 2019 · 5 comments
Closed
Labels
FeatureRequest GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@ailurarctos
Copy link

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

$ go version
go version go1.13.3 linux/amd64

Does this issue reproduce with the latest release?

Yes.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/me/.cache/go-build"
GOENV="/home/me/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/me/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/home/me/example.com/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 -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build779567786=/tmp/go-build -gno-record-gcc-switches"
GOROOT/bin/go version: go version go1.13.3 linux/amd64
GOROOT/bin/go tool compile -V: compile version go1.13.3
uname -sr: Linux 5.3.7-arch1-1-ARCH
/usr/lib/libc.so.6: GNU C Library (GNU libc) stable release version 2.30.

What did you do?

Run go test -json when a package has a build failure. Here is my example_test.go:

package example

import "testing"

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

What did you expect to see?

I expected to see JSON events similar to when a package is skipped because it has no tests. Here is an example:

{"Time":"2019-10-26T09:09:27.272054198+09:00","Action":"output","Package":"example.com","Output":"FAIL\texample.com [build failed]\n"}
{"Time":"2019-10-26T09:09:27.272173706+09:00","Action":"fail","Package":"example.com","Elapsed":0}

What did you see instead?

The package result is printed as-is to stdout:

example.com]$ go test -json 2>/dev/null
FAIL	example.com [build failed]
@ailurarctos
Copy link
Author

This issue might be related to (or a duplicate of) #23037 but I'm not sure because that ticket seems to ask for -json support in go build. What I'm hoping for is to not have go test -json print non-JSON to stdout.

@dmitshur dmitshur added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Oct 29, 2019
@dmitshur dmitshur changed the title go test -json: non-JSON printed to stdout when build fails cmd/go: go test -json has non-JSON printed to stdout when build fails Oct 29, 2019
@dmitshur
Copy link
Contributor

/cc @bcmills @jayconrod

@rsc
Copy link
Contributor

rsc commented Feb 21, 2023

For now I believe the rule is that stdout gets JSON and stderr gets non-JSON.
It sounds like there is a FAIL line printed to stdout that should be JSON'ed.

We should probably open a separate issue for structuring go build's failures (go build -json?) and then we'd just enable it during go test -json too.

@gopherbot
Copy link

Change https://go.dev/cl/529120 mentions this issue: cmd/go: avoid writing non-JSON "build failed" errors from 'go test -json'

@dmitshur dmitshur added NeedsFix The path to resolution is known, but the work has not been done. and removed NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Sep 18, 2023
@dmitshur dmitshur modified the milestones: Unplanned, Go1.22 Sep 18, 2023
@gopherbot
Copy link

Change https://go.dev/cl/536399 mentions this issue: cmd/go: print build errors during go test -json in JSON

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest GoCommand cmd/go NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants