forked from smartystreets/goconvey
-
Notifications
You must be signed in to change notification settings - Fork 0
/
registration.go
71 lines (57 loc) · 1.44 KB
/
registration.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 convey
import (
"reflect"
"runtime"
"github.com/smartystreets/goconvey/convey/gotest"
)
type registration struct {
Situation string
action *action
Test t
File string
Line int
Focus bool
}
func (self *registration) IsTopLevel() bool {
return self.Test != nil
}
func newRegistration(situation string, action *action, test t) *registration {
file, line, _ := gotest.ResolveExternalCaller()
self := new(registration)
self.Situation = situation
self.action = action
self.Test = test
self.File = file
self.Line = line
return self
}
////////////////////////// action ///////////////////////
type action struct {
wrapped func()
name string
}
func (self *action) Invoke() {
self.wrapped()
}
func newAction(wrapped func()) *action {
self := new(action)
self.name = functionName(wrapped)
self.wrapped = wrapped
return self
}
func newSkippedAction(wrapped func()) *action {
self := new(action)
// The choice to use the filename and line number as the action name
// reflects the need for something unique but also that corresponds
// in a determinist way to the action itself.
self.name = gotest.FormatExternalFileAndLine()
self.wrapped = wrapped
return self
}
///////////////////////// helpers //////////////////////////////
func functionName(action func()) string {
return runtime.FuncForPC(functionId(action)).Name()
}
func functionId(action func()) uintptr {
return reflect.ValueOf(action).Pointer()
}