Skip to content

Commit 7efaf15

Browse files
Merge pull request #1586 from redachl/fix/equal-exported-values-accepts-everything
assert.EqualExportedValues: accepts everything
2 parents 75a239b + dce9e58 commit 7efaf15

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

assert/assertions.go

-15
Original file line numberDiff line numberDiff line change
@@ -621,21 +621,6 @@ func EqualExportedValues(t TestingT, expected, actual interface{}, msgAndArgs ..
621621
return Fail(t, fmt.Sprintf("Types expected to match exactly\n\t%v != %v", aType, bType), msgAndArgs...)
622622
}
623623

624-
if aType.Kind() == reflect.Ptr {
625-
aType = aType.Elem()
626-
}
627-
if bType.Kind() == reflect.Ptr {
628-
bType = bType.Elem()
629-
}
630-
631-
if aType.Kind() != reflect.Struct {
632-
return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", aType.Kind(), reflect.Struct), msgAndArgs...)
633-
}
634-
635-
if bType.Kind() != reflect.Struct {
636-
return Fail(t, fmt.Sprintf("Types expected to both be struct or pointer to struct \n\t%v != %v", bType.Kind(), reflect.Struct), msgAndArgs...)
637-
}
638-
639624
expected = copyExportedFields(expected)
640625
actual = copyExportedFields(actual)
641626

assert/assertions_test.go

+50
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,56 @@ func TestEqualExportedValues(t *testing.T) {
449449
+ Exported: (int) 1,
450450
notExported: (interface {}) <nil>`,
451451
},
452+
{
453+
value1: []int{1, 2},
454+
value2: []int{1, 2},
455+
expectedEqual: true,
456+
},
457+
{
458+
value1: []int{1, 2},
459+
value2: []int{1, 3},
460+
expectedEqual: false,
461+
expectedFail: `
462+
Diff:
463+
--- Expected
464+
+++ Actual
465+
@@ -2,3 +2,3 @@
466+
(int) 1,
467+
- (int) 2
468+
+ (int) 3
469+
}`,
470+
},
471+
{
472+
value1: []*Nested{
473+
{1, 2},
474+
{3, 4},
475+
},
476+
value2: []*Nested{
477+
{1, "a"},
478+
{3, "b"},
479+
},
480+
expectedEqual: true,
481+
},
482+
{
483+
value1: []*Nested{
484+
{1, 2},
485+
{3, 4},
486+
},
487+
value2: []*Nested{
488+
{1, "a"},
489+
{2, "b"},
490+
},
491+
expectedEqual: false,
492+
expectedFail: `
493+
Diff:
494+
--- Expected
495+
+++ Actual
496+
@@ -6,3 +6,3 @@
497+
(*assert.Nested)({
498+
- Exported: (int) 3,
499+
+ Exported: (int) 2,
500+
notExported: (interface {}) <nil>`,
501+
},
452502
}
453503

454504
for _, c := range cases {

0 commit comments

Comments
 (0)