Commit ec512340 authored by Sam Whited's avatar Sam Whited Committed by Ian Lance Taylor

encoding/xml: format test output using subtests

Change-Id: I2d155c838935cd8427abd142a462ff4c56829715
Reviewed-on: https://go-review.googlesource.com/37948Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent 0d3cd51c
...@@ -1652,28 +1652,31 @@ func TestMarshal(t *testing.T) { ...@@ -1652,28 +1652,31 @@ func TestMarshal(t *testing.T) {
if test.UnmarshalOnly { if test.UnmarshalOnly {
continue continue
} }
data, err := Marshal(test.Value)
if err != nil { t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
if test.MarshalError == "" { data, err := Marshal(test.Value)
t.Errorf("#%d: marshal(%#v): %s", idx, test.Value, err) if err != nil {
continue if test.MarshalError == "" {
t.Errorf("marshal(%#v): %s", test.Value, err)
return
}
if !strings.Contains(err.Error(), test.MarshalError) {
t.Errorf("marshal(%#v): %s, want %q", test.Value, err, test.MarshalError)
}
return
} }
if !strings.Contains(err.Error(), test.MarshalError) { if test.MarshalError != "" {
t.Errorf("#%d: marshal(%#v): %s, want %q", idx, test.Value, err, test.MarshalError) t.Errorf("Marshal succeeded, want error %q", test.MarshalError)
return
} }
continue if got, want := string(data), test.ExpectXML; got != want {
} if strings.Contains(want, "\n") {
if test.MarshalError != "" { t.Errorf("marshal(%#v):\nHAVE:\n%s\nWANT:\n%s", test.Value, got, want)
t.Errorf("#%d: Marshal succeeded, want error %q", idx, test.MarshalError) } else {
continue t.Errorf("marshal(%#v):\nhave %#q\nwant %#q", test.Value, got, want)
} }
if got, want := string(data), test.ExpectXML; got != want {
if strings.Contains(want, "\n") {
t.Errorf("#%d: marshal(%#v):\nHAVE:\n%s\nWANT:\n%s", idx, test.Value, got, want)
} else {
t.Errorf("#%d: marshal(%#v):\nhave %#q\nwant %#q", idx, test.Value, got, want)
} }
} })
} }
} }
...@@ -1781,27 +1784,29 @@ func TestUnmarshal(t *testing.T) { ...@@ -1781,27 +1784,29 @@ func TestUnmarshal(t *testing.T) {
dest := reflect.New(vt.Elem()).Interface() dest := reflect.New(vt.Elem()).Interface()
err := Unmarshal([]byte(test.ExpectXML), dest) err := Unmarshal([]byte(test.ExpectXML), dest)
switch fix := dest.(type) { t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
case *Feed: switch fix := dest.(type) {
fix.Author.InnerXML = "" case *Feed:
for i := range fix.Entry { fix.Author.InnerXML = ""
fix.Entry[i].Author.InnerXML = "" for i := range fix.Entry {
fix.Entry[i].Author.InnerXML = ""
}
} }
}
if err != nil { if err != nil {
if test.UnmarshalError == "" { if test.UnmarshalError == "" {
t.Errorf("#%d: unmarshal(%#v): %s", i, test.ExpectXML, err) t.Errorf("unmarshal(%#v): %s", test.ExpectXML, err)
continue return
}
if !strings.Contains(err.Error(), test.UnmarshalError) {
t.Errorf("unmarshal(%#v): %s, want %q", test.ExpectXML, err, test.UnmarshalError)
}
return
} }
if !strings.Contains(err.Error(), test.UnmarshalError) { if got, want := dest, test.Value; !reflect.DeepEqual(got, want) {
t.Errorf("#%d: unmarshal(%#v): %s, want %q", i, test.ExpectXML, err, test.UnmarshalError) t.Errorf("unmarshal(%q):\nhave %#v\nwant %#v", test.ExpectXML, got, want)
} }
continue })
}
if got, want := dest, test.Value; !reflect.DeepEqual(got, want) {
t.Errorf("#%d: unmarshal(%q):\nhave %#v\nwant %#v", i, test.ExpectXML, got, want)
}
} }
} }
......
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