-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Closed
Labels
assert.EqualValuesAbout equalityAbout equalitybugpkg-assertChange related to package testify/assertChange related to package testify/assert
Description
Hi
package main
import (
"github.com/stretchr/testify/assert"
)
type Foo struct {
Array [2]int
}
func main() {
a := Foo{[2]int{1, 2}}
b := Foo{[2]int{2, 1}}
assert.EqualExportedValues(nil, a, b)
}Will panic with "panic: reflect.MakeSlice of non-slice type"
Reason is there in assertion.go:113 :
case reflect.Array, reflect.Slice:
result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len())reflect.MakeSlice only work with slice, not with Array. Fix could be follow:
case reflect.Array, reflect.Slice:
result := reflect.New(expectedType).Elem()
if expectedKind == reflect.Slice {
result = reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len())
}Or even carry reflect.Array to different switch case
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
assert.EqualValuesAbout equalityAbout equalitybugpkg-assertChange related to package testify/assertChange related to package testify/assert