-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathhandler_test.go
More file actions
83 lines (71 loc) · 1.25 KB
/
handler_test.go
File metadata and controls
83 lines (71 loc) · 1.25 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
package parallel_test
import (
"fmt"
"github.com/buptmiao/parallel"
"testing"
)
func testFunc1(x, y int) int {
return x + y
}
func EatPanic(s chan struct{}) {
if r := recover(); r != nil {
s <- struct{}{}
}
}
func TestNewHandler(t *testing.T) {
h := parallel.NewHandler(testFunc1, 1, 1)
result := 0
h.SetReceivers(&result)
h.Do()
if result != 2 {
panic(fmt.Errorf("expect 2, but %d", result))
}
}
func testFunc10(a *int) {
}
func TestCheckPanic(t *testing.T) {
// test function type
s := make(chan struct{}, 1)
func() {
defer EatPanic(s)
h := parallel.NewHandler(0, 1, 1)
h.Do()
}()
<-s
// test argument length
func() {
defer EatPanic(s)
h := parallel.NewHandler(testFunc1, 1)
h.Do()
}()
<-s
// test return value length
func() {
defer EatPanic(s)
h := parallel.NewHandler(testFunc1, 1, 1)
h.Do()
}()
<-s
// test return value type
result := 0
func() {
defer EatPanic(s)
h := parallel.NewHandler(testFunc1, 1, 1).SetReceivers(result)
h.Do()
}()
<-s
// test return value nil
var res *int
func() {
defer EatPanic(s)
h := parallel.NewHandler(testFunc1, 1, 1).SetReceivers(res)
h.Do()
}()
<-s
// test arguments nil
var res1 interface{}
func() {
h := parallel.NewHandler(testFunc10, res1)
h.Do()
}()
}