@@ -17,23 +17,23 @@ import (
1717 "github.com/tkrop/go-testing/test"
1818)
1919
20- type IFace interface {
21- CallA (input string )
22- CallB (input string ) string
20+ type IFace [ T any ] interface {
21+ CallA (input T )
22+ CallB (input T ) T
2323}
2424
25- func CallA (input string ) mock.SetupFunc {
25+ func CallA [ T any ] (input T ) mock.SetupFunc {
2626 return func (mocks * mock.Mocks ) any {
27- return mock .Get (mocks , NewMockIFace ).EXPECT ().
28- CallA (mocks .Equal (input )).Do (mocks .Do (IFace .CallA ))
27+ return mock .Get (mocks , NewMockIFace [ T ] ).EXPECT ().
28+ CallA (mocks .Equal (input )).Do (mocks .Do (IFace [ T ] .CallA ))
2929 }
3030}
3131
32- func CallB (input string , output string ) mock.SetupFunc {
32+ func CallB [ T any ] (input T , output T ) mock.SetupFunc {
3333 return func (mocks * mock.Mocks ) any {
34- return mock .Get (mocks , NewMockIFace ).EXPECT ().
34+ return mock .Get (mocks , NewMockIFace [ T ] ).EXPECT ().
3535 CallB (mocks .Equal (input )).DoAndReturn (
36- mocks .Call (IFace .CallB , func (... any ) []any {
36+ mocks .Call (IFace [ T ] .CallB , func (... any ) []any {
3737 return []any {output }
3838 }))
3939 }
@@ -45,9 +45,9 @@ func CallB(input string, output string) mock.SetupFunc {
4545// })
4646// }
4747
48- func NoCall () mock.SetupFunc {
48+ func NoCall [ T any ] () mock.SetupFunc {
4949 return func (mocks * mock.Mocks ) any {
50- return mock .Get (mocks , NewMockIFace ).EXPECT ()
50+ return mock .Get (mocks , NewMockIFace [ T ] ).EXPECT ()
5151 }
5252}
5353
@@ -77,16 +77,16 @@ var mockTestCases = map[string]mockParams{
7777 CallA ("ok" ),
7878 ),
7979 call : func (_ test.Test , mocks * mock.Mocks ) {
80- mock .Get (mocks , NewMockIFace ).CallA ("ok" )
80+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("ok" )
8181 },
8282 },
8383 "single-mock-with-two-calls" : {
8484 setup : mock .Setup (
8585 CallA ("ok" ), CallA ("okay" ),
8686 ),
8787 call : func (_ test.Test , mocks * mock.Mocks ) {
88- mock .Get (mocks , NewMockIFace ).CallA ("ok" )
89- mock .Get (mocks , NewMockIFace ).CallA ("okay" )
88+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("ok" )
89+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("okay" )
9090 },
9191 },
9292 "single-mock-with-missing-calls" : {
@@ -95,26 +95,26 @@ var mockTestCases = map[string]mockParams{
9595 ),
9696 misses : test .MissingCalls (CallA ("okay" )),
9797 call : func (_ test.Test , mocks * mock.Mocks ) {
98- mock .Get (mocks , NewMockIFace ).CallA ("ok" )
98+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("ok" )
9999 },
100100 },
101101 "single-mock-with-unexpected-call" : {
102- misses : test .UnexpectedCall (NewMockIFace ,
102+ misses : test .UnexpectedCall (NewMockIFace [ string ] ,
103103 "CallA" , path .Join (SourceDir , "mocks_test.go:105" ), "ok" ),
104104 call : func (_ test.Test , mocks * mock.Mocks ) {
105- mock .Get (mocks , NewMockIFace ).CallA ("ok" )
105+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("ok" )
106106 },
107107 },
108108 "single-mock-with-more-than-expected-calls" : {
109109 setup : mock .Setup (
110110 CallA ("ok" ),
111111 ),
112- misses : test .ConsumedCall (NewMockIFace ,
112+ misses : test .ConsumedCall (NewMockIFace [ string ] ,
113113 "CallA" , path .Join (SourceDir , "mocks_test.go:117" ),
114114 path .Join (SourceDir , "mocks_test.go:28" ), "ok" ),
115115 call : func (_ test.Test , mocks * mock.Mocks ) {
116- mock .Get (mocks , NewMockIFace ).CallA ("ok" )
117- mock .Get (mocks , NewMockIFace ).CallA ("ok" )
116+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("ok" )
117+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("ok" )
118118 },
119119 },
120120
@@ -124,8 +124,8 @@ var mockTestCases = map[string]mockParams{
124124 CallB ("okay" , "okay" ),
125125 ),
126126 call : func (_ test.Test , mocks * mock.Mocks ) {
127- mock .Get (mocks , NewMockIFace ).CallA ("okay" )
128- mock .Get (mocks , NewMockIFace ).CallB ("okay" )
127+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("okay" )
128+ mock .Get (mocks , NewMockIFace [ string ] ).CallB ("okay" )
129129 },
130130 },
131131 "multiple-mocks-with-many-calls" : {
@@ -135,8 +135,8 @@ var mockTestCases = map[string]mockParams{
135135 CallC ("okay" ),
136136 ),
137137 call : func (_ test.Test , mocks * mock.Mocks ) {
138- mock .Get (mocks , NewMockIFace ).CallA ("okay" )
139- mock .Get (mocks , NewMockIFace ).CallB ("okay" )
138+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("okay" )
139+ mock .Get (mocks , NewMockIFace [ string ] ).CallB ("okay" )
140140 mock .Get (mocks , NewMockXFace ).CallC ("okay" )
141141 },
142142 },
@@ -258,7 +258,7 @@ var getMockTestCases = map[string]getMockParams{
258258 test : getMockTestFunc ,
259259 },
260260 "function-constructor" : {
261- expect : NewMockIFace ,
261+ expect : NewMockIFace [ string ] ,
262262 test : getMockTestMock ,
263263 },
264264}
@@ -309,7 +309,7 @@ func MockValidate(
309309}
310310
311311func SetupPermTestABC (mocks * mock.Mocks ) * perm.Test {
312- iface := mock .Get (mocks , NewMockIFace )
312+ iface := mock .Get (mocks , NewMockIFace [ string ] )
313313 return perm .NewTest (mocks ,
314314 perm.TestMap {
315315 "a" : func (test.Test ) { iface .CallA ("a" ) },
@@ -324,7 +324,7 @@ func SetupPermTestABC(mocks *mock.Mocks) *perm.Test {
324324}
325325
326326func SetupPermTestABCD (mocks * mock.Mocks ) * perm.Test {
327- iface := mock .Get (mocks , NewMockIFace )
327+ iface := mock .Get (mocks , NewMockIFace [ string ] )
328328 return perm .NewTest (mocks ,
329329 perm.TestMap {
330330 "a" : func (test.Test ) { iface .CallA ("a" ) },
@@ -339,7 +339,7 @@ func SetupPermTestABCD(mocks *mock.Mocks) *perm.Test {
339339}
340340
341341func SetupPermTestABCDEF (mocks * mock.Mocks ) * perm.Test {
342- iface := mock .Get (mocks , NewMockIFace )
342+ iface := mock .Get (mocks , NewMockIFace [ string ] )
343343 return perm .NewTest (mocks ,
344344 perm.TestMap {
345345 "a" : func (test.Test ) { iface .CallA ("a" ) },
@@ -620,35 +620,35 @@ type PanicParams struct {
620620
621621var panicTestCases = map [string ]PanicParams {
622622 "setup" : {
623- setup : mock .Setup (NoCall ()),
624- expectError : mock .NewErrNoCall (NewMockIFace (nil ).EXPECT ()),
623+ setup : mock .Setup (NoCall [ string ] ()),
624+ expectError : mock .NewErrNoCall (NewMockIFace [ string ] (nil ).EXPECT ()),
625625 },
626626 "chain" : {
627- setup : mock .Chain (NoCall ()),
628- expectError : mock .NewErrNoCall (NewMockIFace (nil ).EXPECT ()),
627+ setup : mock .Chain (NoCall [ string ] ()),
628+ expectError : mock .NewErrNoCall (NewMockIFace [ string ] (nil ).EXPECT ()),
629629 },
630630 "parallel" : {
631- setup : mock .Parallel (NoCall ()),
632- expectError : mock .NewErrNoCall (NewMockIFace (nil ).EXPECT ()),
631+ setup : mock .Parallel (NoCall [ string ] ()),
632+ expectError : mock .NewErrNoCall (NewMockIFace [ string ] (nil ).EXPECT ()),
633633 },
634634 "detach" : {
635- setup : mock .Detach (4 , NoCall ()),
635+ setup : mock .Detach (4 , NoCall [ string ] ()),
636636 expectError : mock .NewErrDetachMode (4 ),
637637 },
638638 "sub" : {
639- setup : mock .Sub (0 , 0 , NoCall ()),
640- expectError : mock .NewErrNoCall (NewMockIFace (nil ).EXPECT ()),
639+ setup : mock .Sub (0 , 0 , NoCall [ string ] ()),
640+ expectError : mock .NewErrNoCall (NewMockIFace [ string ] (nil ).EXPECT ()),
641641 },
642642 "sub-head" : {
643- setup : mock .Sub (0 , 0 , mock .Detach (mock .Head , NoCall ())),
643+ setup : mock .Sub (0 , 0 , mock .Detach (mock .Head , NoCall [ string ] ())),
644644 expectError : mock .NewErrDetachNotAllowed (mock .Head ),
645645 },
646646 "sub-tail" : {
647- setup : mock .Sub (0 , 0 , mock .Detach (mock .Tail , NoCall ())),
647+ setup : mock .Sub (0 , 0 , mock .Detach (mock .Tail , NoCall [ string ] ())),
648648 expectError : mock .NewErrDetachNotAllowed (mock .Tail ),
649649 },
650650 "sub-both" : {
651- setup : mock .Sub (0 , 0 , mock .Detach (mock .Both , NoCall ())),
651+ setup : mock .Sub (0 , 0 , mock .Detach (mock .Both , NoCall [ string ] ())),
652652 expectError : mock .NewErrDetachNotAllowed (mock .Both ),
653653 },
654654}
@@ -978,7 +978,7 @@ func TestFailures(t *testing.T) {
978978 param .test (t )
979979
980980 // Then
981- mock .Get (mocks , NewMockIFace ).CallA ("a" )
981+ mock .Get (mocks , NewMockIFace [ string ] ).CallA ("a" )
982982 mocks .Wait ()
983983 })
984984}
0 commit comments