parseTestTimeouts parses the stdout of a test run and returns the stacktrace and names of tests that timed out.
(stdout string)
| 18 | |
| 19 | // parseTestTimeouts parses the stdout of a test run and returns the stacktrace and names of tests that timed out. |
| 20 | func parseTestTimeouts(stdout string) (stacktrace string, timedoutTests []string) { |
| 21 | lines := strings.Split(strings.ReplaceAll(stdout, "\r\n", "\n"), "\n") |
| 22 | for i := 0; i < len(lines); i++ { |
| 23 | line := lines[i] |
| 24 | if strings.HasPrefix(line, "FAIL") { |
| 25 | // ignore |
| 26 | } else if strings.HasPrefix(line, "panic: test timed out after") { |
| 27 | // parse names of tests that timed out |
| 28 | for { |
| 29 | i++ |
| 30 | line = strings.TrimSpace(lines[i]) |
| 31 | if strings.HasPrefix(line, "Test") { |
| 32 | timedoutTests = append(timedoutTests, strings.Split(line, " ")[0]) |
| 33 | } |
| 34 | if line == "" { |
| 35 | break |
| 36 | } |
| 37 | } |
| 38 | } else if len(timedoutTests) > 0 { |
| 39 | // collect stracktrace |
| 40 | stacktrace += line + "\n" |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | stacktrace = fmt.Sprintf("%d timed out test(s):\n\t%v\n\n%v", |
| 45 | len(timedoutTests), strings.Join(timedoutTests, "\n\t"), testOnlyStacktrace(stacktrace)) |
| 46 | return |
| 47 | } |
| 48 | |
| 49 | // testOnlyStacktrace removes all but the test stacktraces from the full stacktrace. |
| 50 | func testOnlyStacktrace(stacktrace string) string { |