diff --git a/assert/assertions.go b/assert/assertions.go index c276316b4..4d669d734 100644 --- a/assert/assertions.go +++ b/assert/assertions.go @@ -114,7 +114,19 @@ func copyExportedFields(expected interface{}) interface{} { result.Elem().Set(reflect.ValueOf(unexportedRemoved)) return result.Interface() - case reflect.Array, reflect.Slice: + case reflect.Array: + result := reflect.New(reflect.ArrayOf(expectedValue.Len(), expectedType.Elem())).Elem() + for i := 0; i < expectedValue.Len(); i++ { + index := expectedValue.Index(i) + if isNil(index) { + continue + } + unexportedRemoved := copyExportedFields(index.Interface()) + result.Index(i).Set(reflect.ValueOf(unexportedRemoved)) + } + return result.Interface() + + case reflect.Slice: result := reflect.MakeSlice(expectedType, expectedValue.Len(), expectedValue.Len()) for i := 0; i < expectedValue.Len(); i++ { index := expectedValue.Index(i) 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 {