1
0
mirror of https://github.com/golang/go synced 2024-09-29 11:24:28 -06:00

test2json: default to "pass" when the test doesn't report failures

When a test has a TestMain that doesn't run any tests (doesn't invoke
m.Run), `go test` passes, but `go test -json` reports a "fail" event
though the exit code is still 0.

This CL fixes test2json to behave similarly to `go test` in such cases -
no output from the test is taken as "pass" by default, not as "fail".

Fixes #31969

Change-Id: I1829d40fc30dc2879e73974fac416f6a34212ccd
Reviewed-on: https://go-review.googlesource.com/c/go/+/192104
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Eli Bendersky 2019-08-28 12:34:48 -07:00 committed by Ian Lance Taylor
parent bac5b3f0fe
commit d47526ed77
4 changed files with 3 additions and 2 deletions

View File

@ -284,7 +284,7 @@ func (c *converter) flushReport(depth int) {
func (c *converter) Close() error { func (c *converter) Close() error {
c.input.flush() c.input.flush()
c.output.flush() c.output.flush()
e := &event{Action: "fail"} e := &event{Action: "pass"}
if c.result != "" { if c.result != "" {
e.Action = c.result e.Action = c.result
} }

View File

@ -4,4 +4,4 @@
{"Action":"output","Output":"# but to avoid questions of timing, we just use a file with no \\n at all.\n"} {"Action":"output","Output":"# but to avoid questions of timing, we just use a file with no \\n at all.\n"}
{"Action":"output","Output":"BenchmarkFoo \t"} {"Action":"output","Output":"BenchmarkFoo \t"}
{"Action":"output","Output":"10000 early EOF"} {"Action":"output","Output":"10000 early EOF"}
{"Action":"fail"} {"Action":"pass"}

View File

@ -0,0 +1 @@
{"Action":"pass"}

View File