(t *testing.T, err error, expectedDepth int)
| 84 | func makeErr4() error { return withstack.WithStackDepth(errors.New(""), 1) } |
| 85 | |
| 86 | func checkStackTrace(t *testing.T, err error, expectedDepth int) { |
| 87 | tt := testutils.T{T: t} |
| 88 | |
| 89 | t.Logf("looking at err %# v", pretty.Formatter(err)) |
| 90 | |
| 91 | r := withstack.GetReportableStackTrace(err) |
| 92 | tt.Assert(r != nil) |
| 93 | |
| 94 | // We're expecting the Run() functions in second position. |
| 95 | tt.Assert(len(r.Frames) >= expectedDepth+2) |
| 96 | |
| 97 | for i, f := range r.Frames { |
| 98 | t.Logf("frame %d:", i) |
| 99 | t.Logf("absolute path: %s", f.AbsPath) |
| 100 | t.Logf("file: %s", f.Filename) |
| 101 | t.Logf("line: %d", f.Lineno) |
| 102 | t.Logf("module: %s", f.Module) |
| 103 | t.Logf("function: %s", f.Function) |
| 104 | } |
| 105 | |
| 106 | // The reportable frames are in reversed order. For the test, |
| 107 | // we want to look at them in the "good" order. |
| 108 | for i, j := 0, len(r.Frames)-1; i < j; i, j = i+1, j-1 { |
| 109 | r.Frames[i], r.Frames[j] = r.Frames[j], r.Frames[i] |
| 110 | } |
| 111 | |
| 112 | for i := expectedDepth; i < expectedDepth+2; i++ { |
| 113 | f := r.Frames[i] |
| 114 | tt.Check(strings.Contains(f.Filename, "/errors/") || strings.Contains(f.Filename, "/errors@")) |
| 115 | |
| 116 | tt.Check(strings.HasSuffix(f.AbsPath, f.Filename)) |
| 117 | |
| 118 | switch i { |
| 119 | case expectedDepth: |
| 120 | tt.Check(strings.HasSuffix(f.Filename, "reportable_test.go")) |
| 121 | |
| 122 | case expectedDepth + 1, expectedDepth + 2: |
| 123 | tt.Check(strings.HasSuffix(f.Filename, "internal/run.go")) |
| 124 | |
| 125 | tt.Check(strings.HasSuffix(f.Module, "withstack/internal")) |
| 126 | |
| 127 | tt.Check(strings.HasPrefix(f.Function, "Run")) |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | // Check that Run2() is after Run() in the source code. |
| 132 | tt.Check(r.Frames[expectedDepth+1].Lineno != 0 && |
| 133 | r.Frames[expectedDepth+2].Lineno != 0 && |
| 134 | (r.Frames[expectedDepth+1].Lineno > r.Frames[expectedDepth+2].Lineno)) |
| 135 | } |
no test coverage detected
searching dependent graphs…