cleanGoRoot is similar to tracetest, but deals with GOROOT paths. It replaces paths+line numbers for fixed values so we can use the output in an example test.
(s string)
| 9 | // It replaces paths+line numbers for fixed values so we can use the |
| 10 | // output in an example test. |
| 11 | func cleanGoRoot(s string) string { |
| 12 | gorootPath := regexp.MustCompile("/.*/src/") |
| 13 | s = gorootPath.ReplaceAllString(s, "/goroot/src/") |
| 14 | |
| 15 | fileLine := regexp.MustCompile(`/goroot/.*:[0-9]+`) |
| 16 | return fileLine.ReplaceAllStringFunc(s, func(path string) string { |
| 17 | file, _, ok := strings.Cut(path, ":") |
| 18 | if !ok { |
| 19 | return path |
| 20 | } |
| 21 | |
| 22 | return file + ":0" |
| 23 | }) |
| 24 | } |