-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcaller_test.go
103 lines (84 loc) · 1.92 KB
/
caller_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
package easyworker
import (
"errors"
"fmt"
"log"
"testing"
)
func simpleLoopReturn(a int) int {
ret := 0
for i := 0; i < a; i++ {
ret += i
}
return ret
}
func returnMultiValue() (i int, f float64, b bool, e error) {
i = 123
f = 1.2
b = true
e = errors.New("test return")
return
}
func TestInvokeNoArg(t *testing.T) {
result, err := invokeFun(simpleLoopNoArg)
if err != nil {
t.Error("test invoke with no argument failed, ", err)
} else {
log.Println("result: ", result)
}
}
func TestInvokeIncorrectNumArg(t *testing.T) {
_, err := invokeFun(simpleLoopWithPanic, 3, 3)
if err == nil {
t.Error("test invoke with incorrect argument failed")
}
}
func TestInvokeIncorrectNumArg2(t *testing.T) {
_, err := invokeFun(simpleLoopWithPanic)
fmt.Println(err)
if err == nil {
t.Error("test invoke with incorrect argument failed")
}
}
func TestInvokeIncorrectNumArg3(t *testing.T) {
_, err := invokeFun(simpleLoopWithPanic, "a")
if err == nil {
t.Error("test invoke with incorrect argument failed")
}
}
func TestInvokePanic(t *testing.T) {
_, err := invokeFun(simpleLoopWithPanic, 5)
if err == nil {
t.Error("expected error but no return error.")
} else {
log.Println("expected is ok, err: ", err)
}
}
func TestInvokePanic2(t *testing.T) {
printLog = true
_, err := invokeFun(simpleLoopWithPanic, 5)
if err == nil {
t.Error("expected error but no return error.")
} else {
log.Println("expected is ok, err: ", err)
}
}
func TestInvokeReturn(t *testing.T) {
result, err := invokeFun(simpleLoopReturn, 5)
if err != nil {
t.Error("test invoke with no argument failed, ", err)
} else {
log.Println("result: ", result)
if result[0] != 10 {
t.Error("return incorrect value")
}
}
}
func TestInvokeReturnMultiValue(t *testing.T) {
result, err := invokeFun(returnMultiValue)
if err != nil {
t.Error("test invoke with no argument failed, ", err)
} else {
log.Println("result: ", result)
}
}