golang / go

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

x/playground: a test that terminates itself with a signal is spuriously reported as passing #46823

Open bcmills opened 3 years ago

bcmills commented 3 years ago

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

$ go version
go version devel go1.17-45f251ad6 Thu Jun 17 21:58:54 2021 +0000 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="/usr/local/google/home/bcmills/.cache/go-build"
GOENV="/usr/local/google/home/bcmills/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/tmp/tmp.BvIzRvpmLB/.gopath/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/tmp/tmp.BvIzRvpmLB/.gopath"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/google/home/bcmills/sdk/gotip"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/google/home/bcmills/sdk/gotip/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="devel go1.17-45f251ad6 Thu Jun 17 21:58:54 2021 +0000"
GCCGO="/usr/local/google/home/bcmills/bin/gccgo"
AR="ar"
CC="gcc"
CXX="c++"
CGO_ENABLED="1"
GOMOD="/tmp/tmp.BvIzRvpmLB/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-build2893288510=/tmp/go-build -gno-record-gcc-switches"

What did you do?

  1. Wrote the program in https://play.golang.org/p/Natjl4SGrTr into a file main_test.go in a local package.
  2. Ran go test .
  3. Compared the result with the output reported on https://play.golang.org/p/Natjl4SGrTr.

What did you expect to see?

I expected the Playground to produce roughly the same result as go test ., which reports the test as failing:

$ go test .
2021/06/18 13:32:15 Huh‽
FAIL    example.com/m   0.013s
FAIL

What did you see instead?

The output from the Playground is:

=== RUN   TestLogPrintf
2009/11/10 23:00:00 Huh‽

All tests passed.

CC @golang/release

prattmic commented 3 years ago

It looks like the playground looks only for "--- FAIL" in the output to determine the tests failed. https://cs.opensource.google/go/x/playground/+/master:sandbox.go;l=382

Since the test binary exited early, it wouldn't print "--- FAIL". We should probably use a non-zero exit code to indicate failure as well. I assume this is what the go command does?

bcmills commented 3 years ago

Yes. (See previously #40132, which I fixed by adding cmd/internal/test2json.(*Converter).Exited.)