From 42afde47afb5a116d5d2d42cbab8d6ea8d38c520 Mon Sep 17 00:00:00 2001 From: Brandon Bodnar <33429657+brandonbodnar-wk@users.noreply.github.com> Date: Mon, 17 Sep 2018 07:37:43 -0500 Subject: [PATCH] Introduce unexported match method to report errors matching Changes to the method signature for argumentMatcher.Matches may lead to breaking existing external uses of that function. Introducing a new method used internally allows presenting the error information out for internal testify functionality while not breaking other existing uses of Matches. --- mock/mock.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/mock/mock.go b/mock/mock.go index 3b4a31f..c47696d 100644 --- a/mock/mock.go +++ b/mock/mock.go @@ -580,7 +580,11 @@ type argumentMatcher struct { fn reflect.Value } -func (f argumentMatcher) Matches(argument interface{}) error { +func (f argumentMatcher) Matches(argument interface{}) bool { + return f.match(argument) == nil +} + +func (f argumentMatcher) match(argument interface{}) error { expectType := f.fn.Type().In(0) expectTypeNilSupported := false switch expectType.Kind() { @@ -718,7 +722,7 @@ func (args Arguments) Diff(objects []interface{}) (string, int) { } if matcher, ok := expected.(argumentMatcher); ok { - if matchError := matcher.Matches(actual); matchError == nil { + if matchError := matcher.match(actual); matchError == nil { output = fmt.Sprintf("%s\t%d: PASS: %s matched by %s\n", output, i, actualFmt, matcher) } else { differences++