diff options
| author | Jay Conrod <jayconrod@google.com> | 2020-03-05 11:11:47 -0500 |
|---|---|---|
| committer | Jay Conrod <jayconrod@google.com> | 2020-03-06 17:28:04 +0000 |
| commit | 5ea58c63468bbc7e8705ee13d0bddbf3693785fe (patch) | |
| tree | 8ec6fc26a9344d4e913e4321a17fb3f02aba82bc /src/cmd/internal/test2json/test2json.go | |
| parent | 2b0f481278cc093e9f61945592257e6d651a169c (diff) | |
| download | go-5ea58c63468bbc7e8705ee13d0bddbf3693785fe.tar.xz | |
cmd/go: make go test -json report failures for panicking/exiting tests
'go test -json' should report that a test failed if the test binary
did not exit normally with status 0. This covers panics, non-zero
exits, and abnormal terminations.
These tests don't print a final result when run with -test.v (which is
used by 'go test -json'). The final result should be "PASS" or "FAIL"
on a line by itself. 'go test' prints "FAIL" in this case, but
includes error information.
test2json was changed in CL 192104 to report that a test passed if it
does not report a final status. This caused 'go test -json' to report
that a test passed after a panic or non-zero exit.
With this change, test2json treats "FAIL" with error information the
same as "FAIL" on a line by itself. This is intended to be a minimal
fix for backporting, but it will likely be replaced by a complete
solution for #29062.
Fixes #37555
Updates #29062
Updates #31969
Change-Id: Icb67bcd36bed97e6a8d51f4d14bf71f73c83ac3d
Reviewed-on: https://go-review.googlesource.com/c/go/+/222243
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/internal/test2json/test2json.go')
| -rw-r--r-- | src/cmd/internal/test2json/test2json.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/cmd/internal/test2json/test2json.go b/src/cmd/internal/test2json/test2json.go index aa63c8b9a6..098128ef3a 100644 --- a/src/cmd/internal/test2json/test2json.go +++ b/src/cmd/internal/test2json/test2json.go @@ -128,9 +128,16 @@ func (c *converter) Write(b []byte) (int, error) { } var ( + // printed by test on successful run. bigPass = []byte("PASS\n") + + // printed by test after a normal test failure. bigFail = []byte("FAIL\n") + // printed by 'go test' along with an error if the test binary terminates + // with an error. + bigFailErrorPrefix = []byte("FAIL\t") + updates = [][]byte{ []byte("=== RUN "), []byte("=== PAUSE "), @@ -155,7 +162,7 @@ var ( // before or after emitting other events. func (c *converter) handleInputLine(line []byte) { // Final PASS or FAIL. - if bytes.Equal(line, bigPass) || bytes.Equal(line, bigFail) { + if bytes.Equal(line, bigPass) || bytes.Equal(line, bigFail) || bytes.HasPrefix(line, bigFailErrorPrefix) { c.flushReport(0) c.output.write(line) if bytes.Equal(line, bigPass) { |
