Skip to content

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

@marcusljx

Description

@marcusljx

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"}

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeGoCommandcmd/goNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions