diff options
| author | Russ Cox <rsc@golang.org> | 2017-12-01 13:42:53 -0500 |
|---|---|---|
| committer | Russ Cox <rsc@golang.org> | 2017-12-01 21:06:23 +0000 |
| commit | 7ef9f7250e2abece8b688cc4fcadc3e32d93f0fc (patch) | |
| tree | 1d65bb9bfd3615f1ff3eaf4e20f489ba244a1da6 /src/cmd/internal/test2json | |
| parent | 232b2e3352b0e3913421dc43cb29003eac1c5130 (diff) | |
| download | go-7ef9f7250e2abece8b688cc4fcadc3e32d93f0fc.tar.xz | |
cmd/go: fix missing conversions in -json output
1. Apply JSON conversion when -bench is in use.
2. Apply JSON conversion to "no test files" result.
3. Apply JSON conversion to test case-ending SKIP status.
Fixes #22769.
Fixes #22790.
Change-Id: I67ad656fc58bacae8c51d23b1e6d543cad190f08
Reviewed-on: https://go-review.googlesource.com/81535
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/cmd/internal/test2json')
| -rw-r--r-- | src/cmd/internal/test2json/test2json.go | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/cmd/internal/test2json/test2json.go b/src/cmd/internal/test2json/test2json.go index fa08e34a98..3e09c8d915 100644 --- a/src/cmd/internal/test2json/test2json.go +++ b/src/cmd/internal/test2json/test2json.go @@ -54,7 +54,7 @@ type converter struct { start time.Time // time converter started testName string // name of current test, for output attribution report []*event // pending test result reports (nested for subtests) - passed bool // whether we've seen the final whole-package PASS line + result string // overall test result if seen input lineBuffer // input buffer output lineBuffer // output buffer } @@ -139,9 +139,13 @@ var ( reports = [][]byte{ []byte("--- PASS: "), []byte("--- FAIL: "), + []byte("--- SKIP: "), } fourSpace = []byte(" ") + + skipLinePrefix = []byte("? \t") + skipLineSuffix = []byte("\t[no test files]\n") ) // handleInputLine handles a single whole test output line. @@ -152,10 +156,20 @@ func (c *converter) handleInputLine(line []byte) { if bytes.Equal(line, bigPass) || bytes.Equal(line, bigFail) { c.flushReport(0) c.output.write(line) - c.passed = bytes.Equal(line, bigPass) + if bytes.Equal(line, bigPass) { + c.result = "pass" + } else { + c.result = "fail" + } return } + // Special case for entirely skipped test binary: "? \tpkgname\t[no test files]\n" is only line. + // Report it as plain output but remember to say skip in the final summary. + if bytes.HasPrefix(line, skipLinePrefix) && bytes.HasSuffix(line, skipLineSuffix) && len(c.report) == 0 { + c.result = "skip" + } + // "=== RUN " // "=== PAUSE " // "=== CONT " @@ -171,6 +185,7 @@ func (c *converter) handleInputLine(line []byte) { if !ok { // "--- PASS: " // "--- FAIL: " + // "--- SKIP: " // but possibly indented. for bytes.HasPrefix(line, fourSpace) { line = line[4:] @@ -257,8 +272,8 @@ func (c *converter) Close() error { c.input.flush() c.output.flush() e := &event{Action: "fail"} - if c.passed { - e.Action = "pass" + if c.result != "" { + e.Action = c.result } if c.mode&Timestamp != 0 { dt := time.Since(c.start).Round(1 * time.Millisecond).Seconds() |
