forked from pkg/errors
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstack_test.go
57 lines (55 loc) · 1.81 KB
/
stack_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package errors
import (
"testing"
)
func TestStackTrace(t *testing.T) {
tests := []struct {
err error
want []string
}{{
New("ooh"), []string{
"github.com/gregwebs/errors.TestStackTrace\n" +
"\tgithub.com/gregwebs/errors/stack_test.go:12",
},
}, {
Wrap(New("ooh"), "ahh"), []string{
"github.com/gregwebs/errors.TestStackTrace\n" +
"\tgithub.com/gregwebs/errors/stack_test.go:17", // this is the stack of Wrap, not New
},
}, {
Cause(Wrap(New("ooh"), "ahh")), []string{
"github.com/gregwebs/errors.TestStackTrace\n" +
"\tgithub.com/gregwebs/errors/stack_test.go:22", // this is the stack of New
},
}, {
func() error { return New("ooh") }(), []string{
`github.com/gregwebs/errors.(func·009|TestStackTrace.func1)` +
"\n\tgithub.com/gregwebs/errors/stack_test.go:27", // this is the stack of New
"github.com/gregwebs/errors.TestStackTrace\n" +
"\tgithub.com/gregwebs/errors/stack_test.go:27", // this is the stack of New's caller
},
}, {
func() error {
return func() error {
return Errorf("hello %s", "world")
}()
}(), []string{
`github.com/gregwebs/errors.(func·010|TestStackTrace.func2.1)` +
"\n\tgithub.com/gregwebs/errors/stack_test.go:36", // this is the stack of Errorf
`github.com/gregwebs/errors.(func·011|TestStackTrace.func2)` +
"\n\tgithub.com/gregwebs/errors/stack_test.go:37", // this is the stack of Errorf's caller
"github.com/gregwebs/errors.TestStackTrace\n" +
"\tgithub.com/gregwebs/errors/stack_test.go:38", // this is the stack of Errorf's caller's caller
},
}}
for i, tt := range tests {
ste := GetStackTracer(tt.err)
if ste == nil {
t.Fatalf("expected a stack trace from test %d error: %v", i+1, tt.err)
}
st := ste.StackTrace()
for j, want := range tt.want {
testFormatRegexp(t, i, st[j], "%+v", want)
}
}
}