From: Eli Bendersky Date: Wed, 28 Aug 2019 19:34:48 +0000 (-0700) Subject: test2json: default to "pass" when the test doesn't report failures X-Git-Tag: go1.14beta1~1247 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=d47526ed777958aa4a2542382e931eb7b3c4c6a9;p=gostls13.git 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 TryBot-Result: Gobot Gobot Reviewed-by: Ian Lance Taylor --- diff --git a/src/cmd/internal/test2json/test2json.go b/src/cmd/internal/test2json/test2json.go index f8052136be..aa63c8b9a6 100644 --- a/src/cmd/internal/test2json/test2json.go +++ b/src/cmd/internal/test2json/test2json.go @@ -284,7 +284,7 @@ func (c *converter) flushReport(depth int) { func (c *converter) Close() error { c.input.flush() c.output.flush() - e := &event{Action: "fail"} + e := &event{Action: "pass"} if c.result != "" { e.Action = c.result } diff --git a/src/cmd/internal/test2json/testdata/benchshort.json b/src/cmd/internal/test2json/testdata/benchshort.json index 8c61d95d8d..28e287c848 100644 --- a/src/cmd/internal/test2json/testdata/benchshort.json +++ b/src/cmd/internal/test2json/testdata/benchshort.json @@ -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":"BenchmarkFoo \t"} {"Action":"output","Output":"10000 early EOF"} -{"Action":"fail"} +{"Action":"pass"} diff --git a/src/cmd/internal/test2json/testdata/empty.json b/src/cmd/internal/test2json/testdata/empty.json new file mode 100644 index 0000000000..80b5217501 --- /dev/null +++ b/src/cmd/internal/test2json/testdata/empty.json @@ -0,0 +1 @@ +{"Action":"pass"} diff --git a/src/cmd/internal/test2json/testdata/empty.test b/src/cmd/internal/test2json/testdata/empty.test new file mode 100644 index 0000000000..e69de29bb2