File tree Expand file tree Collapse file tree 2 files changed +22
-1
lines changed
Expand file tree Collapse file tree 2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -728,7 +728,7 @@ func (f argumentMatcher) Matches(argument interface{}) bool {
728728}
729729
730730func (f argumentMatcher ) String () string {
731- return fmt .Sprintf ("func(%s) bool" , f .fn .Type ().In (0 ).Name ())
731+ return fmt .Sprintf ("func(%s) bool" , f .fn .Type ().In (0 ).String ())
732732}
733733
734734// MatchedBy can be used to match a mock call based on only certain properties
Original file line number Diff line number Diff line change @@ -1482,6 +1482,10 @@ func (s *timer) GetTime(i int) string {
14821482 return s .Called (i ).Get (0 ).(string )
14831483}
14841484
1485+ func (s * timer ) GetTimes (times []int ) string {
1486+ return s .Called (times ).Get (0 ).(string )
1487+ }
1488+
14851489type tCustomLogger struct {
14861490 * testing.T
14871491 logs []string
@@ -1554,6 +1558,23 @@ func TestArgumentMatcherToPrintMismatch(t *testing.T) {
15541558 m .AssertExpectations (t )
15551559}
15561560
1561+ func TestArgumentMatcherToPrintMismatchWithReferenceType (t * testing.T ) {
1562+ defer func () {
1563+ if r := recover (); r != nil {
1564+ matchingExp := regexp .MustCompile (
1565+ `\s+mock: Unexpected Method Call\s+-*\s+GetTimes\(\[\]int\)\s+0: \[\]int\{1\}\s+The closest call I have is:\s+GetTimes\(mock.argumentMatcher\)\s+0: mock.argumentMatcher\{.*?\}\s+Diff:.*\(\[\]int=\[1\]\) not matched by func\(\[\]int\) bool` )
1566+ assert .Regexp (t , matchingExp , r )
1567+ }
1568+ }()
1569+
1570+ m := new (timer )
1571+ m .On ("GetTimes" , MatchedBy (func (_ []int ) bool { return false })).Return ("SomeTime" ).Once ()
1572+
1573+ res := m .GetTimes ([]int {1 })
1574+ require .Equal (t , "SomeTime" , res )
1575+ m .AssertExpectations (t )
1576+ }
1577+
15571578func TestClosestCallMismatchedArgumentInformationShowsTheClosest (t * testing.T ) {
15581579 defer func () {
15591580 if r := recover (); r != nil {
You can’t perform that action at this time.
0 commit comments