compareStacks will compare a stack created using the errors package (actual) with a reference stack created with the callers function (expected). The first entry is not compared since the actual and expected stacks cannot be created at the exact same program counter position so the first entry will
(actual, expected []uintptr)
| 294 | // will always differ somewhat. Returns nil if the stacks are equal enough and |
| 295 | // an error containing a detailed error message otherwise. |
| 296 | func compareStacks(actual, expected []uintptr) error { |
| 297 | if len(actual) != len(expected) { |
| 298 | return stackCompareError("Stacks does not have equal length", actual, expected) |
| 299 | } |
| 300 | for i, pc := range actual { |
| 301 | if i != 0 && pc != expected[i] { |
| 302 | return stackCompareError(fmt.Sprintf("Stacks does not match entry %d (and maybe others)", i), actual, expected) |
| 303 | } |
| 304 | } |
| 305 | return nil |
| 306 | } |
| 307 | |
| 308 | func stackCompareError(msg string, actual, expected []uintptr) error { |
| 309 | return fmt.Errorf("%s\nActual stack trace:\n%s\nExpected stack trace:\n%s", msg, readableStackTrace(actual), readableStackTrace(expected)) |
no test coverage detected
searching dependent graphs…