mirror of
https://github.com/golang/go
synced 2024-11-18 06:34:53 -07:00
encoding/xml: format test output using subtests
Change-Id: I2d155c838935cd8427abd142a462ff4c56829715 Reviewed-on: https://go-review.googlesource.com/37948 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
0d3cd51c9c
commit
ec51234014
@ -1652,28 +1652,31 @@ func TestMarshal(t *testing.T) {
|
||||
if test.UnmarshalOnly {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(fmt.Sprintf("%d", idx), func(t *testing.T) {
|
||||
data, err := Marshal(test.Value)
|
||||
if err != nil {
|
||||
if test.MarshalError == "" {
|
||||
t.Errorf("#%d: marshal(%#v): %s", idx, test.Value, err)
|
||||
continue
|
||||
t.Errorf("marshal(%#v): %s", test.Value, err)
|
||||
return
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.MarshalError) {
|
||||
t.Errorf("#%d: marshal(%#v): %s, want %q", idx, test.Value, err, test.MarshalError)
|
||||
t.Errorf("marshal(%#v): %s, want %q", test.Value, err, test.MarshalError)
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
if test.MarshalError != "" {
|
||||
t.Errorf("#%d: Marshal succeeded, want error %q", idx, test.MarshalError)
|
||||
continue
|
||||
t.Errorf("Marshal succeeded, want error %q", test.MarshalError)
|
||||
return
|
||||
}
|
||||
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)
|
||||
t.Errorf("marshal(%#v):\nHAVE:\n%s\nWANT:\n%s", test.Value, got, want)
|
||||
} else {
|
||||
t.Errorf("#%d: marshal(%#v):\nhave %#q\nwant %#q", idx, test.Value, got, want)
|
||||
t.Errorf("marshal(%#v):\nhave %#q\nwant %#q", test.Value, got, want)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -1781,6 +1784,7 @@ func TestUnmarshal(t *testing.T) {
|
||||
dest := reflect.New(vt.Elem()).Interface()
|
||||
err := Unmarshal([]byte(test.ExpectXML), dest)
|
||||
|
||||
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
|
||||
switch fix := dest.(type) {
|
||||
case *Feed:
|
||||
fix.Author.InnerXML = ""
|
||||
@ -1791,17 +1795,18 @@ func TestUnmarshal(t *testing.T) {
|
||||
|
||||
if err != nil {
|
||||
if test.UnmarshalError == "" {
|
||||
t.Errorf("#%d: unmarshal(%#v): %s", i, test.ExpectXML, err)
|
||||
continue
|
||||
t.Errorf("unmarshal(%#v): %s", test.ExpectXML, err)
|
||||
return
|
||||
}
|
||||
if !strings.Contains(err.Error(), test.UnmarshalError) {
|
||||
t.Errorf("#%d: unmarshal(%#v): %s, want %q", i, test.ExpectXML, err, test.UnmarshalError)
|
||||
t.Errorf("unmarshal(%#v): %s, want %q", test.ExpectXML, err, test.UnmarshalError)
|
||||
}
|
||||
continue
|
||||
return
|
||||
}
|
||||
if got, want := dest, test.Value; !reflect.DeepEqual(got, want) {
|
||||
t.Errorf("#%d: unmarshal(%q):\nhave %#v\nwant %#v", i, test.ExpectXML, got, want)
|
||||
t.Errorf("unmarshal(%q):\nhave %#v\nwant %#v", test.ExpectXML, got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user