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, testing: fmt.Print in tests preventing emission of Action:pass event when using `go test -json` #35845

Open
marcusljx opened this issue Nov 26, 2019 · 2 comments

Comments

@marcusljx
Copy link

@marcusljx marcusljx commented Nov 26, 2019

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

$ go version
go version go1.13 darwin/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="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/marcus.low/Library/Caches/go-build"
GOENV="/Users/marcus.low/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/marcus.low/gopath"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/marcus.low/repositories/sandbox/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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/6y/t2pc26794j30sdnn4fx1lkzc0000gq/T/go-build987539708=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. Create a test file:
some_test.go
package somepkg

import (
	"fmt"
	"testing"
)

func TestBad(t *testing.T) {
	fmt.Print("this is bad")
}

func TestOK(t *testing.T) {
	fmt.Println("this is ok")
}
  1. Run the tests:
go test -json -v . | grep '"Action":"pass"'

What did you expect to see?

3 lines of passes:

  • pass event for TestBad
  • pass event for TestOK
  • pass event for the whole somepkg package

What did you see instead?

pass event for TestBad is not emitted.

{"Time":"2019-11-26T17:17:07.640309+08:00","Action":"pass","Package":"sandbox/somepkg","Test":"TestOK","Elapsed":0}
{"Time":"2019-11-26T17:17:07.640327+08:00","Action":"pass","Package":"sandbox/somepkg","Elapsed":0}

However, the passing output line is included together with the fmt.Print output:

{"Time":"2019-11-26T17:19:24.851022+08:00","Action":"output","Package":"sandbox/somepkg","Test":"TestBad","Output":"this is bad--- PASS: TestBad (0.00s)\n"}
@dmitshur

This comment has been minimized.

Copy link
Member

@dmitshur dmitshur commented Nov 26, 2019

@odeke-em odeke-em changed the title fmt.Print in tests preventing emission of Action:pass event when using `go test -json` cmd/go, testing: fmt.Print in tests preventing emission of Action:pass event when using `go test -json` Nov 26, 2019
@skipor

This comment has been minimized.

Copy link

@skipor skipor commented Dec 12, 2019

Duplicate of #26325

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.