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: test in package list mode doesn't print unexpected "exit status" messages #56637

Closed
prashantv opened this issue Nov 8, 2022 · 3 comments
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Milestone

Comments

@prashantv
Copy link
Contributor

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

$ go version
go version go1.19.3 darwin/arm64

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="arm64"
GOBIN=""
GOCACHE="/Users/prashant/Library/Caches/go-build"
GOENV="/Users/prashant/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/prashant/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/prashant/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/Users/prashant/.gimme/versions/go1.19.3.darwin.arm64"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/Users/prashant/.gimme/versions/go1.19.3.darwin.arm64/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.19.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/prashant/tmp/exit-status-repro/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 -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/2f/kn4pgn0x5dv1nqm97qh06sch0000gp/T/go-build1215746447=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Create a directory + module with the following test:

func TestOsExit(t *testing.T) {
	os.Exit(1)
}

I then ran go test in local directory mode (go test -v) and package list mode (go test -v .), and got different outputs.

# local directory mode includes "exit status 1" in the output.
$ go test -v
=== RUN   TestOsExit
exit status 1
FAIL	exit-status-repro	0.092s

# package list mode doesn't include "exit status 1" in the output.
> go test -v .
=== RUN   TestOsExit
FAIL	exit-status-repro	0.087s
FAIL

What did you expect to see?

The output to be the same regardless of the test being run in local directory mode or package list mode.

What did you see instead?

The "exit status 1" message is only printed in local directory mode, not in package list mode.

@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Nov 8, 2022
@mknyszek mknyszek added this to the Backlog milestone Nov 8, 2022
@mknyszek
Copy link
Contributor

mknyszek commented Nov 8, 2022

CC @bcmills

@mknyszek
Copy link
Contributor

mknyszek commented Nov 8, 2022

CC @matloob

@bcmills
Copy link
Contributor

bcmills commented Nov 10, 2022

The exit status print is a heuristic based on whether the test produced any other output:
https://cs.opensource.google/go/go/+/master:src/cmd/go/internal/test/test.go;l=1375-1377;drc=575964d42c7b3001c09f2676d0ee9d520debb5eb

In local directory mode, go test doesn't capture the output at all, so it doesn't know whether the test printed anything, so it ends up printing the exit status just to be sure.

It doesn't seem worth hooking *os.File to use some side-channel to record whether it wrote output, and barring that I don't see a good way to address this. Fundamentally, if you want the output to exactly match a particular execution mode, you have to execute the test in that mode.

@bcmills bcmills closed this as not planned Won't fix, can't repro, duplicate, stale Nov 10, 2022
@golang golang locked and limited conversation to collaborators Nov 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. Unfortunate
Projects
None yet
Development

No branches or pull requests

4 participants