-
Notifications
You must be signed in to change notification settings - Fork 3
/
super_test.go
63 lines (55 loc) · 1.19 KB
/
super_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
package fb
import (
"path/filepath"
"runtime"
"strings"
"testing"
)
type SuperTest struct {
*testing.T
}
func (st *SuperTest) Equal(expected interface{}, actual interface{}) {
if expected != actual {
st.fail(expected, actual, false)
}
}
func (st *SuperTest) MustEqual(expected interface{}, actual interface{}) {
if expected != actual {
st.fail(expected, actual, true)
}
}
func (st *SuperTest) False(actual bool) {
if actual {
st.fail(false, true, false)
}
}
func (st *SuperTest) True(actual bool) {
if !actual {
st.fail(true, false, false)
}
}
func (st *SuperTest) Nil(actual interface{}) {
if actual != nil {
st.fail(nil, actual, false)
}
}
func (st *SuperTest) fail(expected, actual interface{}, must bool) {
pc, file, line, ok := runtime.Caller(2)
var name string
if ok {
name = runtime.FuncForPC(pc).Name()
if i := strings.LastIndex(name, "."); i >= 0 {
name = name[i+1:]
}
file = filepath.Base(file)
} else {
name = "unknown func"
file = "unknown file"
line = 1
}
if must {
st.Fatalf("\t%s:%d: %s: Expected %v, got %v\n", file, line, name, expected, actual)
} else {
st.Errorf("\t%s:%d: %s: Expected %v, got %v\n", file, line, name, expected, actual)
}
}