This repository was archived by the owner on Sep 22, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack_test.go
More file actions
58 lines (48 loc) · 1.37 KB
/
stack_test.go
File metadata and controls
58 lines (48 loc) · 1.37 KB
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
package apperrors
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewStackTrace(t *testing.T) {
var st0 StackTrace
func() {
st0 = newStackTrace(0)
}()
var st1 StackTrace
func() {
func() {
st1 = newStackTrace(1)
}()
}()
t.Run("offset 0", func(t *testing.T) {
assert.NotEmpty(t, st0)
assert.Equal(t, "TestNewStackTrace", st0[0].Func)
assert.Equal(t, "github.com/creasty/apperrors/stack_test.go", st0[0].File)
assert.NotZero(t, st0[0].Line)
})
t.Run("offset n", func(t *testing.T) {
assert.NotEmpty(t, st1)
assert.Equal(t, "TestNewStackTrace", st1[0].Func)
assert.Equal(t, "github.com/creasty/apperrors/stack_test.go", st1[0].File)
assert.NotZero(t, st1[0].Line)
})
}
func TestFuncname(t *testing.T) {
tests := map[string]string{
"": "",
"runtime.main": "main",
"github.com/creasty/apperrors.funcname": "funcname",
"funcname": "funcname",
"io.copyBuffer": "copyBuffer",
"main.(*R).Write": "(*R).Write",
}
for input, expect := range tests {
assert.Equal(t, expect, funcname(input))
}
}
func TestTrimGOPATH(t *testing.T) {
gopath := "/home/user"
file := gopath + "/src/pkg/sub/file.go"
funcName := "pkg/sub.Type.Method"
assert.Equal(t, "pkg/sub/file.go", trimGOPATH(funcName, file))
}