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

stdout messes up go test --json #36576

Closed
tehsphinx opened this issue Jan 15, 2020 · 1 comment
Closed

stdout messes up go test --json #36576

tehsphinx opened this issue Jan 15, 2020 · 1 comment

Comments

@tehsphinx
Copy link

Note: Possibly related to #33419.

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

$ go version
go version go1.13.6 darwin/amd64

Does this issue reproduce with the latest release?

I'm using the latest release.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/user/Library/Caches/go-build"
GOENV="/Users/user/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY="git.rrdc.de"
GONOSUMDB="git.rrdc.de"
GOOS="darwin"
GOPATH="/Users/user/go"
GOPRIVATE="git.rrdc.de"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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/40/qhkn9k653kd0rjgtp0mljpb40000gn/T/go-build357004700=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Running a test that outputs something to stdout without a newline at the end will mess up go test --json.

For example:

package main

import (
	"fmt"
	"testing"
)

func TestX(t *testing.T) {
	fmt.Print("foo")
}

What did you expect to see?

go test --json should output:

{"Time":"2020-01-15T18:44:23.197981+01:00","Action":"run","Package":"git.raceresult.com/la/TestMain","Test":"TestX"}
{"Time":"2020-01-15T18:44:23.199111+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Test":"TestX","Output":"=== RUN   TestX\n"}
{"Time":"2020-01-15T18:44:23.199129+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Test":"TestX","Output":"foo"}
{"Time":"2020-01-15T18:44:23.199158+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Test":"TestX","Output":"--- PASS: TestX (0.00s)\n"}
{"Time":"2020-01-15T18:44:23.199163+01:00","Action":"pass","Package":"git.raceresult.com/la/TestMain","Test":"TestX","Elapsed":0}
{"Time":"2020-01-15T18:44:23.199229+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Output":"PASS\n"}
{"Time":"2020-01-15T18:44:23.199261+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Output":"ok  \tgit.raceresult.com/la/TestMain\t0.321s\n"}
{"Time":"2020-01-15T18:44:23.200981+01:00","Action":"pass","Package":"git.raceresult.com/la/TestMain","Elapsed":0.323}

What did you see instead?

go test --json outputs:

{"Time":"2020-01-15T18:36:09.586716+01:00","Action":"run","Package":"git.raceresult.com/la/TestMain","Test":"TestX"}
{"Time":"2020-01-15T18:36:09.586898+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Test":"TestX","Output":"=== RUN   TestX\n"}
{"Time":"2020-01-15T18:36:09.586909+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Test":"TestX","Output":"foo--- PASS: TestX (0.00s)\n"}
{"Time":"2020-01-15T18:36:09.586914+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Output":"PASS\n"}
{"Time":"2020-01-15T18:36:09.586918+01:00","Action":"output","Package":"git.raceresult.com/la/TestMain","Output":"ok  \tgit.raceresult.com/la/TestMain\t(cached)\n"}
{"Time":"2020-01-15T18:36:09.586923+01:00","Action":"pass","Package":"git.raceresult.com/la/TestMain","Elapsed":0}
@ianlancetaylor
Copy link
Contributor

This is the same problem as #33419. Closing as a dup.

@golang golang locked and limited conversation to collaborators Jan 14, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants