callString not to panic on nil

Fixes stretchr/testify#936.
pull/939/head
Yaroslav Kolomiiets 2020-04-28 15:18:33 +01:00 committed by Boyan Soubachov
parent d3decad621
commit 3bf8d0aa5e
2 changed files with 2 additions and 1 deletions

View File

@ -855,7 +855,7 @@ func (args Arguments) String(indexOrNil ...int) string {
// normal String() method - return a string representation of the args
var argsStr []string
for _, arg := range args {
argsStr = append(argsStr, reflect.TypeOf(arg).String())
argsStr = append(argsStr, fmt.Sprintf("%T", arg)) // handles nil nicely
}
return strings.Join(argsStr, ",")
} else if len(indexOrNil) == 1 {

View File

@ -778,6 +778,7 @@ func Test_Mock_findExpectedCall_Respects_Repeatability(t *testing.T) {
func Test_callString(t *testing.T) {
assert.Equal(t, `Method(int,bool,string)`, callString("Method", []interface{}{1, true, "something"}, false))
assert.Equal(t, `Method(<nil>)`, callString("Method", []interface{}{nil}, false))
}