mirror of https://github.com/stretchr/testify.git
Merge pull request #1517 from Lucaber/equalExportedValues-ptr
Support Pointer to Struct in EqualExportedValuespull/1284/head
commit
9f0ad86b78
|
@ -596,12 +596,19 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ..
|
|||
return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
|
||||
}
|
||||
|
||||
if aType.Kind() == reflect.Ptr {
|
||||
aType = aType.Elem()
|
||||
}
|
||||
if bType.Kind() == reflect.Ptr {
|
||||
bType = bType.Elem()
|
||||
}
|
||||
|
||||
if aType.Kind() != reflect.Struct {
|
||||
return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
|
||||
return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
|
||||
}
|
||||
|
||||
if bType.Kind() != reflect.Struct {
|
||||
return Fail(t, fmt.Sprintf("Types expected to both be struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
|
||||
return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
|
||||
}
|
||||
|
||||
expected = copyExportedFields(expected)
|
||||
|
|
|
@ -430,6 +430,25 @@ func TestEqualExportedValues(t *testing.T) {
|
|||
value2: S{[2]int{1, 2}, Nested{2, nil}, nil, Nested{}},
|
||||
expectedEqual: true,
|
||||
},
|
||||
{
|
||||
value1: &S{1, Nested{2, 3}, 4, Nested{5, 6}},
|
||||
value2: &S{1, Nested{2, nil}, nil, Nested{}},
|
||||
expectedEqual: true,
|
||||
},
|
||||
{
|
||||
value1: &S{1, Nested{2, 3}, 4, Nested{5, 6}},
|
||||
value2: &S{1, Nested{1, nil}, nil, Nested{}},
|
||||
expectedEqual: false,
|
||||
expectedFail: `
|
||||
Diff:
|
||||
--- Expected
|
||||
+++ Actual
|
||||
@@ -3,3 +3,3 @@
|
||||
Exported2: (assert.Nested) {
|
||||
- Exported: (int) 2,
|
||||
+ Exported: (int) 1,
|
||||
notExported: (interface {}) <nil>`,
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
|
|
Loading…
Reference in New Issue