junit: Output SystemOut and SystemErr contents as CDATA

This commit is contained in:
Joël Stemmer
2022-02-27 23:26:11 +00:00
parent 7d75448298
commit 76f68922a2
3 changed files with 16 additions and 8 deletions

View File

@ -50,8 +50,8 @@ type Testsuite struct {
Properties []Property `xml:"properties>property,omitempty"`
Testcases []Testcase `xml:"testcase,omitempty"`
SystemOut string `xml:"system-out,omitempty"`
SystemErr string `xml:"system-err,omitempty"`
SystemOut *Output `xml:"system-out,omitempty"`
SystemErr *Output `xml:"system-err,omitempty"`
}
func (t *Testsuite) AddProperty(name, value string) {
@ -92,8 +92,8 @@ type Testcase struct {
Skipped *Result `xml:"skipped,omitempty"`
Error *Result `xml:"error,omitempty"`
Failure *Result `xml:"failure,omitempty"`
SystemOut string `xml:"system-out,omitempty"`
SystemErr string `xml:"system-err,omitempty"`
SystemOut *Output `xml:"system-out,omitempty"`
SystemErr *Output `xml:"system-err,omitempty"`
}
// Property represents a key/value pair.
@ -109,6 +109,11 @@ type Result struct {
Data string `xml:",cdata"`
}
// Output represents output written to stdout or sderr.
type Output struct {
Data string `xml:",cdata"`
}
// FormatDuration returns the JUnit string representation of the given
// duration.
func FormatDuration(d time.Duration) string {

View File

@ -37,12 +37,12 @@ func TestMarshalUnmarshal(t *testing.T) {
Skipped: &Result{Message: "skipped", Type: "type", Data: "data"},
Error: &Result{Message: "error", Type: "type", Data: "data"},
Failure: &Result{Message: "failure", Type: "type", Data: "data"},
SystemOut: "system-out",
SystemErr: "system-err",
SystemOut: &Output{"system-out"},
SystemErr: &Output{"system-err"},
},
},
SystemOut: "system-out",
SystemErr: "system-err",
SystemOut: &Output{"system-out"},
SystemErr: &Output{"system-err"},
},
},
}