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

testing: fmt.Print missing a trailing newline interferes with test output formatting #35845

Closed
marcusljx opened this issue Nov 26, 2019 · 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.
Milestone

Comments

@marcusljx
Copy link

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 dmitshur added GoCommand cmd/go NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. labels Nov 26, 2019
@dmitshur dmitshur added this to the Backlog milestone Nov 26, 2019
@dmitshur
Copy link
Contributor

/cc @bcmills @jayconrod per owners.

@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
Copy link

skipor commented Dec 12, 2019

Duplicate of #26325

@bcmills bcmills changed the title cmd/go, testing: fmt.Print in tests preventing emission of Action:pass event when using go test -json testing: fmt.Print missing a trailing newline interferes with test output formatting Aug 18, 2020
@bcmills
Copy link
Contributor

bcmills commented Aug 18, 2020

Duplicate of #26325

@bcmills bcmills marked this as a duplicate of #26325 Aug 18, 2020
@bcmills bcmills closed this as completed Aug 18, 2020
@golang golang locked and limited conversation to collaborators Aug 18, 2021
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.
Projects
None yet
Development

No branches or pull requests

5 participants