aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/json
diff options
context:
space:
mode:
authorMarcel van Lohuizen <mpvl@golang.org>2019-02-08 17:52:08 +0100
committerMarcel van Lohuizen <mpvl@golang.org>2019-02-27 18:24:23 +0000
commitb9596aea50a0703f89c6f11c206cfd2c7dd189fa (patch)
tree2ba4e2cba925affa840454078788a4df26ef7457 /src/encoding/json
parentb34c5f0cb46d77c3929fc2b37e86f811c4d32377 (diff)
downloadgo-b9596aea50a0703f89c6f11c206cfd2c7dd189fa.tar.xz
encoding/json: remove use of DeepEqual for testing errors
Comparing errors using DeepEqual breaks if frame information is added as proposed in Issue #29934. Updates #29934. Change-Id: Ib430c9ddbe588dd1dd51314c408c74c07285e1ff Reviewed-on: https://go-review.googlesource.com/c/162179 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Damien Neil <dneil@google.com>
Diffstat (limited to 'src/encoding/json')
-rw-r--r--src/encoding/json/decode_test.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/encoding/json/decode_test.go b/src/encoding/json/decode_test.go
index 54432600a5..60454c6058 100644
--- a/src/encoding/json/decode_test.go
+++ b/src/encoding/json/decode_test.go
@@ -1021,12 +1021,22 @@ func TestMarshalEmbeds(t *testing.T) {
}
}
+func equalError(a, b error) bool {
+ if a == nil {
+ return b == nil
+ }
+ if b == nil {
+ return a == nil
+ }
+ return a.Error() == b.Error()
+}
+
func TestUnmarshal(t *testing.T) {
for i, tt := range unmarshalTests {
var scan scanner
in := []byte(tt.in)
if err := checkValid(in, &scan); err != nil {
- if !reflect.DeepEqual(err, tt.err) {
+ if !equalError(err, tt.err) {
t.Errorf("#%d: checkValid: %#v", i, err)
continue
}
@@ -1044,7 +1054,7 @@ func TestUnmarshal(t *testing.T) {
if tt.disallowUnknownFields {
dec.DisallowUnknownFields()
}
- if err := dec.Decode(v.Interface()); !reflect.DeepEqual(err, tt.err) {
+ if err := dec.Decode(v.Interface()); !equalError(err, tt.err) {
t.Errorf("#%d: %v, want %v", i, err, tt.err)
continue
} else if err != nil {
@@ -2270,7 +2280,7 @@ func TestUnmarshalEmbeddedUnexported(t *testing.T) {
for i, tt := range tests {
err := Unmarshal([]byte(tt.in), tt.ptr)
- if !reflect.DeepEqual(err, tt.err) {
+ if !equalError(err, tt.err) {
t.Errorf("#%d: %v, want %v", i, err, tt.err)
}
if !reflect.DeepEqual(tt.ptr, tt.out) {