in go/tools/bzltestutil/test2json.go [179:302]
func (c *Converter) handleInputLine(line []byte) {
// Final PASS or FAIL.
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) {
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 "
actionColon := false
origLine := line
ok := false
indent := 0
for _, magic := range updates {
if bytes.HasPrefix(line, magic) {
ok = true
break
}
}
if !ok {
// "--- PASS: "
// "--- FAIL: "
// "--- SKIP: "
// "--- BENCH: "
// but possibly indented.
for bytes.HasPrefix(line, fourSpace) {
line = line[4:]
indent++
}
for _, magic := range reports {
if bytes.HasPrefix(line, magic) {
actionColon = true
ok = true
break
}
}
}
// Not a special test output line.
if !ok {
// Lookup the name of the test which produced the output using the
// indentation of the output as an index into the stack of the current
// subtests.
// If the indentation is greater than the number of current subtests
// then the output must have included extra indentation. We can't
// determine which subtest produced this output, so we default to the
// old behaviour of assuming the most recently run subtest produced it.
if indent > 0 && indent <= len(c.report) {
c.testName = c.report[indent-1].Test
}
c.output.write(origLine)
return
}
// Parse out action and test name.
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
// Parse out elapsed time.
if i := strings.Index(name, " ("); i >= 0 {
if strings.HasSuffix(name, "s)") {
t, err := strconv.ParseFloat(name[i+2:len(name)-2], 64)
if err == nil {
if c.mode&Timestamp != 0 {
e.Elapsed = &t
}
}
}
name = name[:i]
}
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.
c.flushReport(indent)
e.Test = name
c.testName = name
c.report = append(c.report, e)
c.output.write(origLine)
return
}
// === update.
// Finish any pending PASS/FAIL reports.
c.flushReport(0)
c.testName = name
if action == "pause" {
// For a pause, we want to write the pause notification before
// delivering the pause event, just so it doesn't look like the test
// is generating output immediately after being paused.
c.output.write(origLine)
}
c.writeEvent(e)
if action != "pause" {
c.output.write(origLine)
}
return
}