mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-04 20:50:14 -05:00
Move XML writing into separate function
This commit is contained in:
parent
733873e344
commit
9c3fda9259
@ -108,25 +108,35 @@ func main() {
|
||||
defer f.Close()
|
||||
out = f
|
||||
}
|
||||
if !*noXMLHeader {
|
||||
fmt.Fprintf(out, xml.Header)
|
||||
}
|
||||
|
||||
enc := xml.NewEncoder(out)
|
||||
enc.Indent("", "\t")
|
||||
if err := enc.Encode(testsuites); err != nil {
|
||||
if err := writeXML(out, testsuites, *noXMLHeader); err != nil {
|
||||
exitf("error writing XML: %v", err)
|
||||
}
|
||||
if err := enc.Flush(); err != nil {
|
||||
exitf("error flusing XML: %v", err)
|
||||
}
|
||||
fmt.Fprintf(out, "\n")
|
||||
|
||||
if *setExitCode && !report.IsSuccessful() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func writeXML(w io.Writer, testsuites junit.Testsuites, skipHeader bool) error {
|
||||
if !skipHeader {
|
||||
_, err := fmt.Fprintf(w, xml.Header)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
enc := xml.NewEncoder(w)
|
||||
enc.Indent("", "\t")
|
||||
if err := enc.Encode(testsuites); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := enc.Flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
_, err := fmt.Fprintf(w, "\n")
|
||||
return err
|
||||
}
|
||||
|
||||
func exitf(msg string, args ...interface{}) {
|
||||
if msg != "" {
|
||||
fmt.Fprintf(os.Stderr, msg+"\n", args...)
|
||||
|
Loading…
x
Reference in New Issue
Block a user