-
Notifications
You must be signed in to change notification settings - Fork 1
/
frame_test.go
76 lines (55 loc) · 2.87 KB
/
frame_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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package errors_test
import (
"fmt"
"testing"
"github.com/jsteenb2/errors"
)
func TestStackTrace_SimpleError(t *testing.T) {
err := errors.New("some error")
frames := errors.StackTrace(err)
must(t, eqLen(t, 1, frames))
eq(t, "[ github.com/jsteenb2/errors/frame_test.go:11[TestStackTrace_SimpleError] ]", frames.String())
sVal := fmt.Sprintf("%s", frames)
eq(t, "[ frame_test.go ]", sVal)
sVal = fmt.Sprintf("%s", frames[0])
eq(t, "frame_test.go", sVal)
wantSPlusVal := `github.com/jsteenb2/errors/frame_test.go:11[TestStackTrace_SimpleError]`
eq(t, "[ "+wantSPlusVal+" ]", fmt.Sprintf("%+s", frames))
eq(t, wantSPlusVal, fmt.Sprintf("%+s", frames[0]))
wantLine := "11"
eq(t, "[ "+wantLine+" ]", fmt.Sprintf("%d", frames))
eq(t, wantLine, fmt.Sprintf("%d", frames[0]))
wantFile := "frame_test.go:" + wantLine
eq(t, "[ "+wantFile+" ]", fmt.Sprintf("%v", frames))
eq(t, wantFile, fmt.Sprintf("%v", frames[0]))
wantVPlusVal := `github.com/jsteenb2/errors/` + wantFile + `[TestStackTrace_SimpleError]`
eq(t, "[ "+wantVPlusVal+" ]", fmt.Sprintf("%+v", frames))
eq(t, wantVPlusVal, fmt.Sprintf("%+v", frames[0]))
}
func TestStackTrace_WrappedError(t *testing.T) {
err := errors.Wrap(
errors.New("some error"),
)
frames := errors.StackTrace(err)
must(t, eqLen(t, 2, frames))
wantStr := "[ github.com/jsteenb2/errors/frame_test.go:43[TestStackTrace_WrappedError], github.com/jsteenb2/errors/frame_test.go:44[TestStackTrace_WrappedError] ]"
eq(t, wantStr, frames.String())
eq(t, "[ frame_test.go, frame_test.go ]", fmt.Sprintf("%s", frames))
eq(t, "frame_test.go", fmt.Sprintf("%s", frames[0]))
eq(t, "frame_test.go", fmt.Sprintf("%s", frames[1]))
wantSPlusVal := `[ github.com/jsteenb2/errors/frame_test.go:43[TestStackTrace_WrappedError], github.com/jsteenb2/errors/frame_test.go:44[TestStackTrace_WrappedError] ]`
eq(t, wantSPlusVal, fmt.Sprintf("%+s", frames))
eq(t, `github.com/jsteenb2/errors/frame_test.go:43[TestStackTrace_WrappedError]`, fmt.Sprintf("%+s", frames[0]))
eq(t, `github.com/jsteenb2/errors/frame_test.go:44[TestStackTrace_WrappedError]`, fmt.Sprintf("%+s", frames[1]))
eq(t, "[ 43, 44 ]", fmt.Sprintf("%d", frames))
eq(t, "43", fmt.Sprintf("%d", frames[0]))
eq(t, "44", fmt.Sprintf("%d", frames[1]))
wantFile := `[ frame_test.go:43, frame_test.go:44 ]`
eq(t, wantFile, fmt.Sprintf("%v", frames))
eq(t, "frame_test.go:43", fmt.Sprintf("%v", frames[0]))
eq(t, "frame_test.go:44", fmt.Sprintf("%v", frames[1]))
wantVPlusFrame := `[ github.com/jsteenb2/errors/frame_test.go:43[TestStackTrace_WrappedError], github.com/jsteenb2/errors/frame_test.go:44[TestStackTrace_WrappedError] ]`
eq(t, wantVPlusFrame, fmt.Sprintf("%+v", frames))
eq(t, "github.com/jsteenb2/errors/frame_test.go:43[TestStackTrace_WrappedError]", fmt.Sprintf("%+v", frames[0]))
eq(t, "github.com/jsteenb2/errors/frame_test.go:44[TestStackTrace_WrappedError]", fmt.Sprintf("%+v", frames[1]))
}