@@ -18,6 +18,9 @@ import (
18
18
"github.com/stretchr/testify/assert"
19
19
)
20
20
21
+ // regex for GCCGO functions
22
+ var gccgoRE = regexp .MustCompile (`\.pN\d+_` )
23
+
21
24
// TestingT is an interface wrapper around *testing.T
22
25
type TestingT interface {
23
26
Logf (format string , args ... interface {})
@@ -455,9 +458,8 @@ func (m *Mock) Called(arguments ...interface{}) Arguments {
455
458
// For Ex: github_com_docker_libkv_store_mock.WatchTree.pN39_github_com_docker_libkv_store_mock.Mock
456
459
// uses interface information unlike golang github.com/docker/libkv/store/mock.(*Mock).WatchTree
457
460
// With GCCGO we need to remove interface information starting from pN<dd>.
458
- re := regexp .MustCompile ("\\ .pN\\ d+_" )
459
- if re .MatchString (functionPath ) {
460
- functionPath = re .Split (functionPath , - 1 )[0 ]
461
+ if gccgoRE .MatchString (functionPath ) {
462
+ functionPath = gccgoRE .Split (functionPath , - 1 )[0 ]
461
463
}
462
464
parts := strings .Split (functionPath , "." )
463
465
functionName := parts [len (parts )- 1 ]
@@ -758,18 +760,26 @@ const (
758
760
Anything = "mock.Anything"
759
761
)
760
762
761
- // AnythingOfTypeArgument is a string that contains the type of an argument
763
+ // AnythingOfTypeArgument contains the type of an argument
764
+ // for use when type checking. Used in Diff and Assert.
765
+ //
766
+ // Deprecated: this is an implementation detail that must not be used. Use [AnythingOfType] instead.
767
+ type AnythingOfTypeArgument = anythingOfTypeArgument
768
+
769
+ // anythingOfTypeArgument is a string that contains the type of an argument
762
770
// for use when type checking. Used in Diff and Assert.
763
- type AnythingOfTypeArgument string
771
+ type anythingOfTypeArgument string
764
772
765
- // AnythingOfType returns an AnythingOfTypeArgument object containing the
766
- // name of the type to check for. Used in Diff and Assert.
773
+ // AnythingOfType returns a special value containing the
774
+ // name of the type to check for. The type name will be matched against the type name returned by [reflect.Type.String].
775
+ //
776
+ // Used in Diff and Assert.
767
777
//
768
778
// For example:
769
779
//
770
780
// Assert(t, AnythingOfType("string"), AnythingOfType("int"))
771
781
func AnythingOfType (t string ) AnythingOfTypeArgument {
772
- return AnythingOfTypeArgument (t )
782
+ return anythingOfTypeArgument (t )
773
783
}
774
784
775
785
// IsTypeArgument is a struct that contains the type of an argument
@@ -950,9 +960,9 @@ func (args Arguments) Diff(objects []interface{}) (string, int) {
950
960
differences ++
951
961
output = fmt .Sprintf ("%s\t %d: FAIL: %s not matched by %s\n " , output , i , actualFmt , matcher )
952
962
}
953
- } else if reflect .TypeOf (expected ) == reflect .TypeOf ((* AnythingOfTypeArgument )(nil )).Elem () {
963
+ } else if reflect .TypeOf (expected ) == reflect .TypeOf ((* anythingOfTypeArgument )(nil )).Elem () {
954
964
// type checking
955
- if reflect .TypeOf (actual ).Name () != string (expected .(AnythingOfTypeArgument )) && reflect .TypeOf (actual ).String () != string (expected .(AnythingOfTypeArgument )) {
965
+ if reflect .TypeOf (actual ).Name () != string (expected .(anythingOfTypeArgument )) && reflect .TypeOf (actual ).String () != string (expected .(anythingOfTypeArgument )) {
956
966
// not match
957
967
differences ++
958
968
output = fmt .Sprintf ("%s\t %d: FAIL: type %s != type %s - %s\n " , output , i , expected , reflect .TypeOf (actual ).Name (), actualFmt )
0 commit comments