-
Notifications
You must be signed in to change notification settings - Fork 0
/
trace_test.go
84 lines (78 loc) · 2.64 KB
/
trace_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
77
78
79
80
81
82
83
84
package berr
import (
"strings"
"github.com/stretchr/testify/assert"
)
func (suite *betterErrorsTestSuite) TestTraceSupport() {
for _, c := range traceTestCases {
suite.Run(c.name, func() {
Options.PrintStack = c.showTrace
Options.ShowCompleteStack = c.showCompleteTrace
out := Format(c.args)
assert.Equal(suite.T(), c.want, out)
Reset()
})
}
}
var (
traceTestCases = []struct {
name string
args error
want string
showTrace bool
showCompleteTrace bool
}{
{
"should print trace ignoring berr functions",
complexError,
strings.Join([]string{
"complex error",
"",
"caused by:",
" 0: simple error",
"",
"Stack trace (without berr functions):",
" github.com/sebastianwebber/berr.(*betterErrorsTestSuite).TestTraceSupport.func1:",
" /Users/seba/projetos/github.com/sebastianwebber/berr/trace_test.go:15",
" github.com/stretchr/testify/suite.(*Suite).Run.func1:",
" /Users/seba/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:115",
" testing.tRunner:",
" /nix/store/k9srp8ngvblscg68fdpcyqkydh86429k-go-1.22.1/share/go/src/testing/testing.go:1689",
" runtime.goexit:",
" /nix/store/k9srp8ngvblscg68fdpcyqkydh86429k-go-1.22.1/share/go/src/runtime/asm_arm64.s:1222",
}, "\n"),
true,
false,
},
{
"should print complete trace",
complexError,
strings.Join([]string{
"complex error",
"",
"caused by:",
" 0: simple error",
"",
"Stack trace:",
" github.com/sebastianwebber/berr.getStack:",
" /Users/seba/projetos/github.com/sebastianwebber/berr/trace.go:53",
" github.com/sebastianwebber/berr.collectStackTrace:",
" /Users/seba/projetos/github.com/sebastianwebber/berr/trace.go:38",
" github.com/sebastianwebber/berr.betterError.Error:",
" /Users/seba/projetos/github.com/sebastianwebber/berr/berr.go:40",
" github.com/sebastianwebber/berr.Format:",
" /Users/seba/projetos/github.com/sebastianwebber/berr/format.go:24",
" github.com/sebastianwebber/berr.(*betterErrorsTestSuite).TestTraceSupport.func1:",
" /Users/seba/projetos/github.com/sebastianwebber/berr/trace_test.go:15",
" github.com/stretchr/testify/suite.(*Suite).Run.func1:",
" /Users/seba/go/pkg/mod/github.com/stretchr/[email protected]/suite/suite.go:115",
" testing.tRunner:",
" /nix/store/k9srp8ngvblscg68fdpcyqkydh86429k-go-1.22.1/share/go/src/testing/testing.go:1689",
" runtime.goexit:",
" /nix/store/k9srp8ngvblscg68fdpcyqkydh86429k-go-1.22.1/share/go/src/runtime/asm_arm64.s:1222",
}, "\n"),
true,
true,
},
}
)