Skip to content

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

Closed

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

Activity

  1. added
    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.
    on Nov 26, 2019
  2. added this to the Backlog milestone on Nov 26, 2019
  3. dmitshur commented on Nov 26, 2019

    @dmitshur
    Member
  4. 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`[/+] on Nov 26, 2019
  5. skipor commented on Dec 12, 2019

    @skipor

    Duplicate of #26325

  6. 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[/+] on Aug 18, 2020
  7. bcmills commented on Aug 18, 2020

    @bcmills
    Contributor

    Duplicate of #26325

  8. locked and limited conversation to collaborators on Aug 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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