-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrapt_test.go
61 lines (46 loc) · 1.32 KB
/
wrapt_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
package wrapt_test
import (
"errors"
"testing"
"github.com/metrumresearchgroup/wrapt"
)
func Test_T_RunFatal(tt *testing.T) {
t := wrapt.WrapT(tt)
t.RunFatal("positive assertion without failure", func(t *wrapt.T) {
t.A.True(true, "not true")
})
}
func Test_T_ResultHandler(tt *testing.T) {
t := wrapt.WrapT(tt)
var success bool
t.FatalHandler = func(t *wrapt.T, suc bool, msgAndArgs ...interface{}) {
success = suc
}
t.RunFatal("antifail", func(t *wrapt.T) {
// do nothing
})
t.A.True(success)
}
// Test_Assert_WantError is a wiring test, and does not walk any negative
// paths, because we're passing through a real testing.T.
func Test_Assert_WantError(tt *testing.T) {
type Wanter interface {
//
WantError(wantErr bool, err error, msgAndArgs ...interface{}) (success bool)
}
t := wrapt.WrapT(tt)
wanter := Wanter(t.A)
t.A.True(wanter.WantError(false, nil))
t.A.True(wanter.WantError(true, errors.New("error")))
}
// Test_Require_WantError is a wiring test, and does not walk any negative
// paths, because we're passing through a real testing.T.
func Test_Require_WantError(tt *testing.T) {
type Wanter interface {
WantError(wantErr bool, err error, msgAndArgs ...interface{})
}
t := wrapt.WrapT(tt)
wanter := Wanter(t.R)
wanter.WantError(false, nil)
wanter.WantError(true, errors.New("error"))
}