@@ -3,27 +3,32 @@ package testdata
3
3
import (
4
4
"errors"
5
5
"testing"
6
+
7
+ "github.com/google/go-cmp/cmp"
8
+ "github.com/google/go-cmp/cmp/cmpopts"
6
9
)
7
10
8
11
func TestNoMock (t * testing.T ) {
9
- m0 := & M0 {new (T0 )}
12
+ t .Cleanup (func () { simpleCalled = false })
13
+ var m0 M0
10
14
m0 .Simple ()
11
- if ! m0 . simpleCalled {
15
+ if ! simpleCalled {
12
16
t .Error ("want Simple() call" )
13
17
}
14
18
}
15
19
16
20
func TestStub (t * testing.T ) {
17
- m0 := & M0 {new (T0 )}
21
+ t .Cleanup (func () { simpleCalled = false })
22
+ var m0 M0
18
23
m0 ._Simple_Stub ()
19
24
m0 .Simple ()
20
- if m0 . simpleCalled {
25
+ if simpleCalled {
21
26
t .Error ("want mock, got Simple() call" )
22
27
}
23
28
}
24
29
25
30
func TestOneResult (t * testing.T ) {
26
- m0 := & M0 { new ( T0 )}
31
+ var m0 M0
27
32
want := errors .New ("error result" )
28
33
m0 ._OneResult_Return (want )
29
34
if got := m0 .OneResult (); want != got {
@@ -36,7 +41,7 @@ func TestOneResult(t *testing.T) {
36
41
}
37
42
38
43
func TestOneResultQueue (t * testing.T ) {
39
- m0 := & M0 { new ( T0 )}
44
+ var m0 M0
40
45
err1 := errors .New ("error one" )
41
46
err2 := errors .New ("error two" )
42
47
m0 ._OneResult_Return (err1 )
@@ -51,3 +56,20 @@ func TestOneResultQueue(t *testing.T) {
51
56
t .Errorf ("M0.OneResult() call #3: want %q, got %q" , err1 , got )
52
57
}
53
58
}
59
+
60
+ func TestCalls (t * testing.T ) {
61
+ var m0 M0
62
+ m0 .OneParamNoResult ("call one" )
63
+ m0 .OneParamNoResult ("call two" )
64
+ m0 .OneParamNoResult ("call three" )
65
+ want := []_M0_OneParamNoResult_Call {
66
+ {"call one" },
67
+ {"call two" },
68
+ {"call three" },
69
+ }
70
+ got := m0 ._OneParamNoResult_Calls ()
71
+ opt := cmpopts .EquateComparable (_M0_OneParamNoResult_Call {})
72
+ if ! cmp .Equal (want , got , opt ) {
73
+ t .Errorf ("M0._OneParamNoResult_Calls():\n %s" , cmp .Diff (want , got , opt ))
74
+ }
75
+ }
0 commit comments