diff --git a/mock/mock.go b/mock/mock.go index 5d445c6..853da6c 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -728,7 +728,7 @@ func (f argumentMatcher) Matches(argument interface{}) bool { } func (f argumentMatcher) String() string { - return fmt.Sprintf("func(%s) bool", f.fn.Type().In(0).Name()) + return fmt.Sprintf("func(%s) bool", f.fn.Type().In(0).String()) } // MatchedBy can be used to match a mock call based on only certain properties diff --git a/mock/mock_test.go b/mock/mock_test.go index 097addc..91828f8 100644 --- a/mock/mock_test.go +++ b/mock/mock_test.go @@ -1482,6 +1482,10 @@ func (s *timer) GetTime(i int) string { return s.Called(i).Get(0).(string) } +func (s *timer) GetTimes(times []int) string { + return s.Called(times).Get(0).(string) +} + type tCustomLogger struct { *testing.T logs []string @@ -1554,6 +1558,23 @@ func TestArgumentMatcherToPrintMismatch(t *testing.T) { m.AssertExpectations(t) } +func TestArgumentMatcherToPrintMismatchWithReferenceType(t *testing.T) { + defer func() { + if r := recover(); r != nil { + matchingExp := regexp.MustCompile( + `\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`) + assert.Regexp(t, matchingExp, r) + } + }() + + m := new(timer) + m.On("GetTimes", MatchedBy(func(_ []int) bool { return false })).Return("SomeTime").Once() + + res := m.GetTimes([]int{1}) + require.Equal(t, "SomeTime", res) + m.AssertExpectations(t) +} + func TestClosestCallMismatchedArgumentInformationShowsTheClosest(t *testing.T) { defer func() { if r := recover(); r != nil {