-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcallstack_test.go
54 lines (43 loc) · 1.15 KB
/
callstack_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
package errors
import (
"fmt"
"math/rand"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestCallStack_Format(t *testing.T) {
var (
ptName = t.Name()
cstk callStack
skippedFn = func() { cstk = newCallStack() }
f1 = func() { skippedFn() }
)
f1()
t.Run("'v' verb", func(t *testing.T) {
var s = fmt.Sprintf("%v", cstk)
var sls = strings.Split(s, "\n")
assert.Contains(t, sls[0], fmt.Sprintf("errors.%s.func2", ptName))
assert.Contains(t, sls[1], "errors/callstack_test.go:17")
})
t.Run("'v' verb and '-' flags", func(t *testing.T) {
var s = fmt.Sprintf("%-v", cstk)
var sls = strings.Split(s, "\n")
assert.Contains(t, sls[0], fmt.Sprintf("errors.%s.func2", ptName))
})
t.Run("any other verb", func(t *testing.T) {
var verbs = [...]string{
"t", "b", "c", "d", "o", "q", "x", "X", "U", "e", "E", "f", "F", "g", "G", "q", "p", "s",
}
var f = fmt.Sprintf("%%%s", verbs[rand.Intn(len(verbs))])
var s = fmt.Sprintf(f, cstk)
assert.Empty(t, s)
})
t.Run("empty stack", func(t *testing.T) {
var (
ecstk = callStack(nil)
s = fmt.Sprintf("%v", ecstk)
)
assert.Empty(t, s)
})
}