diff options
| author | Dave Collins <[email protected]> | 2013-12-02 00:50:11 -0800 |
|---|---|---|
| committer | Dave Collins <[email protected]> | 2013-12-02 00:50:11 -0800 |
| commit | bde46cf02b3187ab268e4d0e10a0c361dc39112c (patch) | |
| tree | 62c6885ee422de8a4e8f50d5613ccaa32a0a6945 | |
| parent | e762b3d1320b76030bd7f6cc2bfc3d9acce874c0 (diff) | |
| parent | 264fa19defb385c37e0a849fab9e91e58b1b67ea (diff) | |
Merge pull request #14 from pmezard/fix-sorting-test-on-32bits
tests: fix TestSortValues on 32-bits platforms
| -rw-r--r-- | spew/common_test.go | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/spew/common_test.go b/spew/common_test.go index c27f798..3bea81f 100644 --- a/spew/common_test.go +++ b/spew/common_test.go @@ -116,6 +116,14 @@ func testFailed(result string, wants []string) bool { // TestSortValues ensures the sort functionality for relect.Value based sorting // works as intended. func TestSortValues(t *testing.T) { + getInterfaces := func(values []reflect.Value) []interface{} { + interfaces := []interface{}{} + for _, v := range values { + interfaces = append(interfaces, v.Interface()) + } + return interfaces + } + v := reflect.ValueOf a := v("a") @@ -171,8 +179,14 @@ func TestSortValues(t *testing.T) { } for _, test := range tests { spew.SortValues(test.input) - if !reflect.DeepEqual(test.input, test.expected) { - t.Errorf("Sort mismatch:\n %v != %v", test.input, test.expected) + // reflect.DeepEqual cannot really make sense of reflect.Value, + // probably because of all the pointer tricks. For instance, + // v(2.0) != v(2.0) on a 32-bits system. Turn them into interface{} + // instead. + input := getInterfaces(test.input) + expected := getInterfaces(test.expected) + if !reflect.DeepEqual(input, expected) { + t.Errorf("Sort mismatch:\n %v != %v", input, expected) } } } |
