diff --git a/assert/assertions.go b/assert/assertions.go index c276316b4..1e55fbf54 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -115,7 +115,12 @@ func copyExportedFields(expected interface{}) interface{} { return result.Interface() case reflect.Array, reflect.Slice: - result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) + var result reflect.Value + if expectedKind == reflect.Array { + result = reflect.New(reflect.ArrayOf(expectedValue.Len(), expectedType.Elem())).Elem() + } else { + result = reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) + } for i := 0; i < expectedValue.Len(); i++ { index := expectedValue.Index(i) if isNil(index) { diff --git a/assert/assertions_test.go b/assert/assertions_test.go index e1245b421..9a44f95eb 100644 --- a/assert/assertions_test.go +++ b/assert/assertions_test.go @@ -408,6 +408,11 @@ func TestEqualExportedValues(t *testing.T) { + Exported: (int) 2, notExported: (interface {}) `, }, + { + value1: S{[2]int{1, 2}, Nested{2, 3}, 4, Nested{5, 6}}, + value2: S{[2]int{1, 2}, Nested{2, nil}, nil, Nested{}}, + expectedEqual: true, + }, } for _, c := range cases {