diff options
Diffstat (limited to 'libgo/go/cmd/internal/test2json/test2json.go')
-rw-r--r-- | libgo/go/cmd/internal/test2json/test2json.go | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/libgo/go/cmd/internal/test2json/test2json.go b/libgo/go/cmd/internal/test2json/test2json.go index 3e09c8d9151..f8052136be6 100644 --- a/libgo/go/cmd/internal/test2json/test2json.go +++ b/libgo/go/cmd/internal/test2json/test2json.go @@ -16,6 +16,7 @@ import ( "strconv" "strings" "time" + "unicode" "unicode/utf8" ) @@ -140,6 +141,7 @@ var ( []byte("--- PASS: "), []byte("--- FAIL: "), []byte("--- SKIP: "), + []byte("--- BENCH: "), } fourSpace = []byte(" ") @@ -173,6 +175,7 @@ func (c *converter) handleInputLine(line []byte) { // "=== RUN " // "=== PAUSE " // "=== CONT " + actionColon := false origLine := line ok := false indent := 0 @@ -186,6 +189,7 @@ func (c *converter) handleInputLine(line []byte) { // "--- PASS: " // "--- FAIL: " // "--- SKIP: " + // "--- BENCH: " // but possibly indented. for bytes.HasPrefix(line, fourSpace) { line = line[4:] @@ -193,6 +197,7 @@ func (c *converter) handleInputLine(line []byte) { } for _, magic := range reports { if bytes.HasPrefix(line, magic) { + actionColon = true ok = true break } @@ -206,8 +211,15 @@ func (c *converter) handleInputLine(line []byte) { } // Parse out action and test name. - action := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(string(line[4:4+6])), ":")) - name := strings.TrimSpace(string(line[4+6:])) + i := 0 + if actionColon { + i = bytes.IndexByte(line, ':') + 1 + } + if i == 0 { + i = len(updates[0]) + } + action := strings.ToLower(strings.TrimSuffix(strings.TrimSpace(string(line[4:i])), ":")) + name := strings.TrimSpace(string(line[i:])) e := &event{Action: action} if line[0] == '-' { // PASS or FAIL report @@ -226,6 +238,7 @@ func (c *converter) handleInputLine(line []byte) { if len(c.report) < indent { // Nested deeper than expected. // Treat this line as plain output. + c.output.write(origLine) return } // Flush reports at this indentation level or deeper. @@ -342,6 +355,15 @@ func (l *lineBuffer) write(b []byte) { for i < len(l.b) { j := bytes.IndexByte(l.b[i:], '\n') if j < 0 { + if !l.mid { + if j := bytes.IndexByte(l.b[i:], '\t'); j >= 0 { + if isBenchmarkName(bytes.TrimRight(l.b[i:i+j], " ")) { + l.part(l.b[i : i+j+1]) + l.mid = true + i += j + 1 + } + } + } break } e := i + j + 1 @@ -383,6 +405,21 @@ func (l *lineBuffer) flush() { } } +var benchmark = []byte("Benchmark") + +// isBenchmarkName reports whether b is a valid benchmark name +// that might appear as the first field in a benchmark result line. +func isBenchmarkName(b []byte) bool { + if !bytes.HasPrefix(b, benchmark) { + return false + } + if len(b) == len(benchmark) { // just "Benchmark" + return true + } + r, _ := utf8.DecodeRune(b[len(benchmark):]) + return !unicode.IsLower(r) +} + // trimUTF8 returns a length t as close to len(b) as possible such that b[:t] // does not end in the middle of a possibly-valid UTF-8 sequence. // |