Commit b9596aea authored by Marcel van Lohuizen's avatar Marcel van Lohuizen

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: default avatarRuss Cox <rsc@golang.org>
Reviewed-by: default avatarDamien Neil <dneil@google.com>
parent b34c5f0c
...@@ -1021,12 +1021,22 @@ func TestMarshalEmbeds(t *testing.T) { ...@@ -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) { func TestUnmarshal(t *testing.T) {
for i, tt := range unmarshalTests { for i, tt := range unmarshalTests {
var scan scanner var scan scanner
in := []byte(tt.in) in := []byte(tt.in)
if err := checkValid(in, &scan); err != nil { 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) t.Errorf("#%d: checkValid: %#v", i, err)
continue continue
} }
...@@ -1044,7 +1054,7 @@ func TestUnmarshal(t *testing.T) { ...@@ -1044,7 +1054,7 @@ func TestUnmarshal(t *testing.T) {
if tt.disallowUnknownFields { if tt.disallowUnknownFields {
dec.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) t.Errorf("#%d: %v, want %v", i, err, tt.err)
continue continue
} else if err != nil { } else if err != nil {
...@@ -2270,7 +2280,7 @@ func TestUnmarshalEmbeddedUnexported(t *testing.T) { ...@@ -2270,7 +2280,7 @@ func TestUnmarshalEmbeddedUnexported(t *testing.T) {
for i, tt := range tests { for i, tt := range tests {
err := Unmarshal([]byte(tt.in), tt.ptr) 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) t.Errorf("#%d: %v, want %v", i, err, tt.err)
} }
if !reflect.DeepEqual(tt.ptr, tt.out) { if !reflect.DeepEqual(tt.ptr, tt.out) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment