-
Notifications
You must be signed in to change notification settings - Fork 0
/
stacktrace_test.go
62 lines (55 loc) · 959 Bytes
/
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
package e5
import (
"errors"
"io"
"strings"
"testing"
)
func TestStacktrace(t *testing.T) {
TestWrapFunc(t, WrapStacktrace)
trace := WrapStacktrace(io.EOF)
if !is(trace, io.EOF) {
t.Fatal()
}
if !strings.Contains(trace.Error(), "EOF") {
t.Fatalf("got %v", trace.Error())
}
}
func TestDeepStacktrace(t *testing.T) {
var foo func(int) error
foo = func(i int) error {
if i < 128 {
return foo(i + 1)
}
return WrapStacktrace(io.EOF)
}
err := foo(1)
if !errors.Is(err, io.EOF) {
t.Fatal()
}
}
func TestStacktraceIncluded(t *testing.T) {
err := Error{
WrapStacktrace(io.EOF),
}
if !stacktraceIncluded(err) {
t.Fatal()
}
err = Join(
io.EOF,
WrapStacktrace(io.EOF),
)
if !stacktraceIncluded(err) {
t.Fatal()
}
}
func TestJoinStacktrace(t *testing.T) {
err := Join(
WrapStacktrace(io.EOF),
WrapStacktrace(io.EOF),
)
str := err.Error()
if len(strings.Split(str, "$")) != 2 {
t.Fatalf("got %s", str)
}
}