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 {
728
728
}
729
729
730
730
func (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 ())
732
732
}
733
733
734
734
// 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 {
1482
1482
return s .Called (i ).Get (0 ).(string )
1483
1483
}
1484
1484
1485
+ func (s * timer ) GetTimes (times []int ) string {
1486
+ return s .Called (times ).Get (0 ).(string )
1487
+ }
1488
+
1485
1489
type tCustomLogger struct {
1486
1490
* testing.T
1487
1491
logs []string
@@ -1554,6 +1558,23 @@ func TestArgumentMatcherToPrintMismatch(t *testing.T) {
1554
1558
m .AssertExpectations (t )
1555
1559
}
1556
1560
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
+
1557
1578
func TestClosestCallMismatchedArgumentInformationShowsTheClosest (t * testing.T ) {
1558
1579
defer func () {
1559
1580
if r := recover (); r != nil {
You can’t perform that action at this time.
0 commit comments