Skip to content

Commit 3bf8d0a

Browse files
yarikkboyan-soubachov
authored andcommitted
callString not to panic on nil
Fixes #936.
1 parent d3decad commit 3bf8d0a

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

mock/mock.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ func (args Arguments) String(indexOrNil ...int) string {
855855
// normal String() method - return a string representation of the args
856856
var argsStr []string
857857
for _, arg := range args {
858-
argsStr = append(argsStr, reflect.TypeOf(arg).String())
858+
argsStr = append(argsStr, fmt.Sprintf("%T", arg)) // handles nil nicely
859859
}
860860
return strings.Join(argsStr, ",")
861861
} else if len(indexOrNil) == 1 {

mock/mock_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,7 @@ func Test_Mock_findExpectedCall_Respects_Repeatability(t *testing.T) {
778778
func Test_callString(t *testing.T) {
779779

780780
assert.Equal(t, `Method(int,bool,string)`, callString("Method", []interface{}{1, true, "something"}, false))
781+
assert.Equal(t, `Method(<nil>)`, callString("Method", []interface{}{nil}, false))
781782

782783
}
783784

0 commit comments

Comments
 (0)