forked from tlog-dev/tlog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
location_stacktrace_test.go
69 lines (56 loc) · 1.83 KB
/
location_stacktrace_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
package tlog
import (
"fmt"
"regexp"
"testing"
"github.com/stretchr/testify/assert"
)
func TestLocationStackTraceFill(t *testing.T) {
st := make(Trace, 1)
st = FillStackTrace(0, st)
assert.Len(t, st, 1)
assert.Equal(t, "location_stacktrace_test.go:14", st[0].String())
}
func testStackTraceInside() (st Trace) {
func() {
func() {
st = StackTrace(1, 3)
}()
}()
return
}
func TestLocationStackTraceString(t *testing.T) {
var st Trace
func() {
func() {
st = testStackTraceInside()
}()
}()
assert.Len(t, st, 3)
assert.Equal(t, "location_stacktrace_test.go:24", st[0].String())
assert.Equal(t, "location_stacktrace_test.go:25", st[1].String())
assert.Equal(t, "location_stacktrace_test.go:33", st[2].String())
re := `tlog.testStackTraceInside.func1 at [\w.-/]*location_stacktrace_test.go:24
tlog.testStackTraceInside at [\w.-/]*location_stacktrace_test.go:25
tlog.TestLocationStackTraceString.func1.1 at [\w.-/]*location_stacktrace_test.go:33
`
ok, err := regexp.MatchString(re, st.String())
assert.NoError(t, err)
assert.True(t, ok, "expected:\n%v\ngot:\n%v\n", re, st.String())
}
func TestLocationStackTraceFormat(t *testing.T) {
var st Trace
func() {
func() {
st = testStackTraceInside()
}()
}()
assert.Equal(t, "location_stacktrace_test.go:24 at location_stacktrace_test.go:25 at location_stacktrace_test.go:55", fmt.Sprintf("%v", st))
assert.Equal(t, "testStackTraceInside.func1:24 at testStackTraceInside:25 at TestLocationStackTraceFormat.func1.1:55", fmt.Sprintf("%#v", st))
re := `at [\w.-/]*location_stacktrace_test.go:24
at [\w.-/]*location_stacktrace_test.go:25
at [\w.-/]*location_stacktrace_test.go:55
`
v := fmt.Sprintf("%+v", st)
assert.True(t, regexp.MustCompile(re).MatchString(v), "expected:\n%vgot:\n%v", re, v)
}