Skip to content

Commit 6cb0be5

Browse files
Merge remote-tracking branch 'upstream/release/1.11'
# Conflicts: # mock/mock.go # mock/mock_test.go
2 parents 2650ce7 + 2a57335 commit 6cb0be5

File tree

2 files changed

+9
-48
lines changed

2 files changed

+9
-48
lines changed

mock/mock.go

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@ import (
1212
"time"
1313

1414
"github.com/davecgh/go-spew/spew"
15+
"github.com/pmezard/go-difflib/difflib"
1516
"github.com/stretchr/objx"
17+
1618
"github.com/stretchr/testify/assert"
17-
"github.com/stretchr/testify/internal/difflib"
1819
)
1920

2021
// regex for GCCGO functions
@@ -603,12 +604,11 @@ func AssertExpectationsForObjects(t TestingT, testObjects ...interface{}) bool {
603604
h.Helper()
604605
}
605606
for _, obj := range testObjects {
606-
m, ok := obj.(assertExpectationiser)
607-
if !ok {
608-
t.Errorf("Invalid test object type %T. Expected reference to a mock.Mock, eg: 'AssertExpectationsForObjects(t, myMock)' or 'AssertExpectationsForObjects(t, &myMock.Mock)'", obj)
609-
continue
610-
607+
if m, ok := obj.(*Mock); ok {
608+
t.Logf("Deprecated mock.AssertExpectationsForObjects(myMock.Mock) use mock.AssertExpectationsForObjects(myMock)")
609+
obj = m
611610
}
611+
m := obj.(assertExpectationiser)
612612
if !m.AssertExpectations(t) {
613613
t.Logf("Expectations didn't match for Mock: %+v", reflect.TypeOf(m))
614614
return false
@@ -712,8 +712,8 @@ func (m *Mock) AssertNotCalled(t TestingT, methodName string, arguments ...inter
712712
return true
713713
}
714714

715-
// IsMethodCallable returns true if given methodName and arguments have an
716-
// unsatisfied expected call registered in the Mock.
715+
// IsMethodCallable checking that the method can be called
716+
// If the method was called more than `Repeatability` return false
717717
func (m *Mock) IsMethodCallable(t TestingT, methodName string, arguments ...interface{}) bool {
718718
if h, ok := t.(tHelper); ok {
719719
h.Helper()
@@ -833,10 +833,6 @@ type IsTypeArgument struct {
833833
// For example:
834834
//
835835
// args.Assert(t, IsType(""), IsType(0))
836-
//
837-
// Mock cannot match interface types because the contained type will be passed
838-
// to both IsType and Mock.Called, for the zero value of all interfaces this
839-
// will be <nil> type.
840836
func IsType(t interface{}) *IsTypeArgument {
841837
return &IsTypeArgument{t: reflect.TypeOf(t)}
842838
}
@@ -1016,7 +1012,7 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
10161012
actualT := reflect.TypeOf(actual)
10171013
if actualT != expected.t {
10181014
differences++
1019-
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, safeTypeName(expected.t), safeTypeName(actualT), actualFmt)
1015+
output = fmt.Sprintf("%s\t%d: FAIL: type %s != type %s - %s\n", output, i, expected.t.Name(), actualT.Name(), actualFmt)
10201016
}
10211017
case *FunctionalOptionsArgument:
10221018
var name string
@@ -1145,15 +1141,6 @@ func (args Arguments) Bool(index int) bool {
11451141
return s
11461142
}
11471143

1148-
// safeTypeName returns the reflect.Type's name without causing a panic.
1149-
// If the provided reflect.Type is nil, it returns the placeholder string "<nil>"
1150-
func safeTypeName(t reflect.Type) string {
1151-
if t == nil {
1152-
return "<nil>"
1153-
}
1154-
return t.Name()
1155-
}
1156-
11571144
func typeAndKind(v interface{}) (reflect.Type, reflect.Kind) {
11581145
t := reflect.TypeOf(v)
11591146
k := t.Kind()

mock/mock_test.go

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package mock
22

33
import (
4-
"context"
54
"errors"
65
"fmt"
76
"regexp"
@@ -2000,25 +1999,6 @@ func Test_Arguments_Diff_WithIsTypeArgument_Failing(t *testing.T) {
20001999
assert.Contains(t, diff, `string != type int - (int=123)`)
20012000
}
20022001

2003-
func Test_Arguments_Diff_WithIsTypeArgument_InterfaceType(t *testing.T) {
2004-
t.Parallel()
2005-
var ctx = context.Background()
2006-
args := Arguments([]interface{}{IsType(ctx)})
2007-
_, count := args.Diff([]interface{}{context.Background()})
2008-
assert.Equal(t, 0, count)
2009-
}
2010-
2011-
func Test_Arguments_Diff_WithIsTypeArgument_InterfaceType_Failing(t *testing.T) {
2012-
t.Parallel()
2013-
2014-
var ctx context.Context
2015-
var args = Arguments([]interface{}{IsType(ctx)})
2016-
diff, count := args.Diff([]interface{}{context.Background()})
2017-
assert.Equal(t, 1, count)
2018-
assert.Contains(t, diff, `type <nil> != type `)
2019-
2020-
}
2021-
20222002
func Test_Arguments_Diff_WithArgMatcher(t *testing.T) {
20232003
t.Parallel()
20242004

@@ -2461,9 +2441,3 @@ func TestIssue1785ArgumentWithMutatingStringer(t *testing.T) {
24612441
m.MethodCalled("Method", &mutatingStringer{N: 2})
24622442
m.AssertExpectations(t)
24632443
}
2464-
2465-
func TestIssue1227AssertExpectationsForObjectsWithMock(t *testing.T) {
2466-
mockT := &MockTestingT{}
2467-
AssertExpectationsForObjects(mockT, Mock{})
2468-
assert.Equal(t, 1, mockT.errorfCount)
2469-
}

0 commit comments

Comments
 (0)