(t *testing.T)
| 114 | } |
| 115 | |
| 116 | func TestStackTrace(t *testing.T) { |
| 117 | tests := []struct { |
| 118 | err error |
| 119 | want []string |
| 120 | }{{ |
| 121 | New("ooh"), []string{ |
| 122 | "github.com/pkg/errors.TestStackTrace\n" + |
| 123 | "\t.+/github.com/pkg/errors/stack_test.go:121", |
| 124 | }, |
| 125 | }, { |
| 126 | Wrap(New("ooh"), "ahh"), []string{ |
| 127 | "github.com/pkg/errors.TestStackTrace\n" + |
| 128 | "\t.+/github.com/pkg/errors/stack_test.go:126", // this is the stack of Wrap, not New |
| 129 | }, |
| 130 | }, { |
| 131 | Cause(Wrap(New("ooh"), "ahh")), []string{ |
| 132 | "github.com/pkg/errors.TestStackTrace\n" + |
| 133 | "\t.+/github.com/pkg/errors/stack_test.go:131", // this is the stack of New |
| 134 | }, |
| 135 | }, { |
| 136 | func() error { return New("ooh") }(), []string{ |
| 137 | `github.com/pkg/errors.TestStackTrace.func1` + |
| 138 | "\n\t.+/github.com/pkg/errors/stack_test.go:136", // this is the stack of New |
| 139 | "github.com/pkg/errors.TestStackTrace\n" + |
| 140 | "\t.+/github.com/pkg/errors/stack_test.go:136", // this is the stack of New's caller |
| 141 | }, |
| 142 | }, { |
| 143 | Cause(func() error { |
| 144 | return func() error { |
| 145 | return Errorf("hello %s", fmt.Sprintf("world: %s", "ooh")) |
| 146 | }() |
| 147 | }()), []string{ |
| 148 | `github.com/pkg/errors.TestStackTrace.func2.1` + |
| 149 | "\n\t.+/github.com/pkg/errors/stack_test.go:145", // this is the stack of Errorf |
| 150 | `github.com/pkg/errors.TestStackTrace.func2` + |
| 151 | "\n\t.+/github.com/pkg/errors/stack_test.go:146", // this is the stack of Errorf's caller |
| 152 | "github.com/pkg/errors.TestStackTrace\n" + |
| 153 | "\t.+/github.com/pkg/errors/stack_test.go:147", // this is the stack of Errorf's caller's caller |
| 154 | }, |
| 155 | }} |
| 156 | for i, tt := range tests { |
| 157 | x, ok := tt.err.(interface { |
| 158 | StackTrace() StackTrace |
| 159 | }) |
| 160 | if !ok { |
| 161 | t.Errorf("expected %#v to implement StackTrace() StackTrace", tt.err) |
| 162 | continue |
| 163 | } |
| 164 | st := x.StackTrace() |
| 165 | for j, want := range tt.want { |
| 166 | testFormatRegexp(t, i, st[j], "%+v", want) |
| 167 | } |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | func stackTrace() StackTrace { |
| 172 | const depth = 8 |
nothing calls this directly
no test coverage detected
searching dependent graphs…