testOnlyStacktrace removes all but the test stacktraces from the full stacktrace.
(stacktrace string)
| 48 | |
| 49 | // testOnlyStacktrace removes all but the test stacktraces from the full stacktrace. |
| 50 | func testOnlyStacktrace(stacktrace string) string { |
| 51 | var res string |
| 52 | snap, _, err := stack.ScanSnapshot(strings.NewReader(stacktrace), io.Discard, stack.DefaultOpts()) |
| 53 | if err != nil && err != io.EOF { |
| 54 | return fmt.Sprintf("failed to parse stacktrace: %v", err) |
| 55 | } |
| 56 | if snap == nil { |
| 57 | return "failed to find a stacktrace" |
| 58 | } |
| 59 | res = "abridged stacktrace:\n" |
| 60 | for _, goroutine := range snap.Goroutines { |
| 61 | shouldPrint := slices.ContainsFunc(goroutine.Stack.Calls, func(call stack.Call) bool { |
| 62 | return strings.HasSuffix(call.RemoteSrcPath, "_test.go") |
| 63 | }) |
| 64 | if shouldPrint { |
| 65 | res += fmt.Sprintf("\tgoroutine %d [%v]:\n", goroutine.ID, goroutine.State) |
| 66 | for _, call := range goroutine.Stack.Calls { |
| 67 | file := call.RemoteSrcPath |
| 68 | res += fmt.Sprintf("\t\t%s:%d\n", file, call.Line) |
| 69 | } |
| 70 | res += "\n" |
| 71 | } |
| 72 | } |
| 73 | return res |
| 74 | } |
| 75 | |
| 76 | // alert captures a prominent issue detected from stdout/stderr of test runs. |
| 77 | type alert struct { |
no test coverage detected