-
Notifications
You must be signed in to change notification settings - Fork 0
/
assert_panic_test.go
60 lines (53 loc) · 1.58 KB
/
assert_panic_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
package actually
import (
"fmt"
"testing"
)
func TestPanic(t *testing.T) {
Got(func() { panic("OMG") }).Panic(t)
}
func TestPanic_Fail(t *testing.T) {
stubConfirm(t, func() {
Got(nil).Panic(t)
}, reason_GotShouldFuncType)
stubConfirm(t, func() {
Got(func() {}).Panic(t)
}, reason_ExpectPanic)
}
func TestPanicMessage(t *testing.T) {
Got(func() { panic("hidebu") }).Expect("hidebu").PanicMessage(t)
Got(func() { panic(fmt.Errorf("abeshi")) }).Expect(fmt.Errorf("abeshi")).PanicMessage(t)
}
func TestPanicMessage_Fail(t *testing.T) {
for tn, tt := range map[testName]testCase{
"Go should be func type": {
expected: "any", actuallyGot: nil, expectedFailReason: reason_GotShouldFuncType,
},
"Expect panic, but didn't": {
expected: "any", actuallyGot: func() {}, expectedFailReason: reason_ExpectPanic,
},
"the types of expect and panic message are different": {
expected: "OMG ERROR", actuallyGot: func() { panic(fmt.Errorf("OMG ERROR")) }, expectedFailReason: reason_PanicButMsgwrongType,
},
"expect and panic message are wrong": {
expected: "OMG", actuallyGot: func() { panic("OOPS") }, expectedFailReason: reason_PanicButMsgDifferent,
},
} {
t.Run(tn, func(t *testing.T) {
stubConfirm(t, func() {
Got(tt.actuallyGot).Expect(tt.expected).PanicMessage(t)
}, tt.expectedFailReason)
})
}
}
func TestNoPanic(t *testing.T) {
Got(func() {}).NoPanic(t)
}
func TestNoPanic_Fail(t *testing.T) {
stubConfirm(t, func() {
Got(nil).NoPanic(t)
}, reason_GotShouldFuncType)
stubConfirm(t, func() {
Got(func() { panic("OMG") }).NoPanic(t)
}, reason_ExpectNoPanic)
}