-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfunc_test.go
71 lines (50 loc) · 1.33 KB
/
func_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
package loc
import (
"reflect"
"testing"
"unsafe"
"github.com/stretchr/testify/assert"
)
type eface struct {
_ unsafe.Pointer
_ unsafe.Pointer
}
func TestFuncFunc(t *testing.T) {
var f interface{}
f = TestSetCache
r := reflect.ValueOf(f)
t.Logf("reflect: %v %v %v %x", r.Kind(), r.Type(), r, *(*eface)(unsafe.Pointer(&f)))
f = TestFuncFunc
r = reflect.ValueOf(f)
t.Logf("reflect: %v %v %v %x", r.Kind(), r.Type(), r, *(*eface)(unsafe.Pointer(&f)))
pc := FuncEntryFromFunc(TestFuncFunc)
name, file, line := pc.NameFileLine()
t.Logf("pc: %v %v %v", name, file, line)
assert.Equal(t, FuncEntry(0), pc)
assert.Equal(t, FuncEntry(0), PC(reflect.ValueOf(TestFuncFunc).Pointer()))
name, file, line = FuncEntryFromFunc(nil).NameFileLine()
t.Logf("pc: %v %v %v", name, file, line)
var q func()
name, file, line = FuncEntryFromFunc(q).NameFileLine()
t.Logf("pc: %v %v %v", name, file, line)
var e PC
q = func() {
t.Logf("closure func")
e = FuncEntry(0)
}
q()
rt := reflect.ValueOf(q).Type()
for i := 0; i < rt.NumIn(); i++ {
t.Logf("q in %v", rt.In(i))
}
for i := 0; i < rt.NumOut(); i++ {
t.Logf("q out %v", rt.Out(i))
}
pc = FuncEntryFromFunc(q)
name, file, line = pc.NameFileLine()
t.Logf("pc: %v %v %v", name, file, line)
assert.Equal(t, e, pc)
assert.Panics(t, func() {
pc = FuncEntryFromFunc(3)
})
}