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: using both -v and -json with go test has unintended effects #70384

Open
firelizzard18 opened this issue Nov 15, 2024 · 4 comments
Open
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@firelizzard18
Copy link
Contributor

Go version

go version go1.23.1 linux/amd64

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/firelizzard/.cache/go-build'
GOENV='/home/firelizzard/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/firelizzard/go/pkg/mod'
GOOS='linux'
GOPATH='/home/firelizzard/go'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/firelizzard/sdk/go1.23.1'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/firelizzard/sdk/go1.23.1/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.1'
GODEBUG=''
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/firelizzard/.config/go/telemetry'
GCCGO='/usr/bin/gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/firelizzard/src/yaegi/go-script/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 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4165056435=/tmp/go-build -gno-record-gcc-switches'

What did you do?

go test -v -json -run=- -bench=^BenchmarkSimple$ ./pkg/vm in the root of https://gitlab.com/firelizzard/go-script

What did you see happen?

Nothing but output events for the benchmark

What did you expect to see?

An "Action":"run" event for the benchmark

@firelizzard18
Copy link
Contributor Author

This is probably related to #61767 and CL 443596. It appears that the presence of -v results in the binary not being called with -test.v=test2json, preventing CL 443596's fix from working.

@firelizzard18 firelizzard18 changed the title go test: using both -v and -json has unintended effects cmd/go: using both -v and -json has unintended effects Nov 15, 2024
@firelizzard18 firelizzard18 changed the title cmd/go: using both -v and -json has unintended effects cmd/go: using both -v and -json with go test has unintended effects Nov 15, 2024
@dmitshur
Copy link
Contributor

This is documented at https://pkg.go.dev/cmd/test2json as:

The test should be invoked with -test.v=test2json. Using only -test.v (or -test.v=true) is permissible but produces lower fidelity results.

Note that "go test -json" takes care of invoking test2json correctly [...]

In other words, just go test -json does the right thing (it does go test -json -v=test2json under the hood), and go test -json -v (aka go test -json -v=true) is permitted but produces the lower fidelity results you're observing. I'm not sure why it's permitted, though, leaving it to cmd/go owners to see if anything should/can be done.

CC @matloob, @samthanawalla.

@dmitshur dmitshur added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. GoCommand cmd/go labels Nov 19, 2024
@dmitshur dmitshur added this to the Backlog milestone Nov 19, 2024
@firelizzard18
Copy link
Contributor Author

I guess instead of calling this a bug another way of putting it is: As a developer working on tooling (improved test support for vscode-go), it is unpleasantly surprising that adding -v degrades the utility of -json. I'd never use -v -json manually but it's not hard to miss when I'm shoving flags into an array in preparation for executing go test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants