add flag -no-xml-header

This commit is contained in:
Tachikoma 2014-12-22 20:59:04 +08:00
parent 6982e7a3a3
commit 8cd3db55e5
2 changed files with 14 additions and 3 deletions

View File

@ -1,11 +1,20 @@
package main
import (
"flag"
"fmt"
"os"
)
var noXmlHeader bool
func init() {
flag.BoolVar(&noXmlHeader, "no-xml-header", false, "do not print xml header")
}
func main() {
flag.Parse()
// Read input
report, err := Parse(os.Stdin)
if err != nil {
@ -14,7 +23,7 @@ func main() {
}
// Write xml
err = JUnitReportXML(report, os.Stdout)
err = JUnitReportXML(report, noXmlHeader, os.Stdout)
if err != nil {
fmt.Printf("Error writing XML: %s\n", err)
os.Exit(1)

View File

@ -52,7 +52,7 @@ func NewJUnitProperty(name, value string) JUnitProperty {
// JUnitReportXML writes a junit xml representation of the given report to w
// in the format described at http://windyroad.org/dl/Open%20Source/JUnit.xsd
func JUnitReportXML(report *Report, w io.Writer) error {
func JUnitReportXML(report *Report, noXmlHeader bool, w io.Writer) error {
suites := []JUnitTestSuite{}
// convert Report to JUnit test suites
@ -111,7 +111,9 @@ func JUnitReportXML(report *Report, w io.Writer) error {
writer := bufio.NewWriter(w)
writer.WriteString(xml.Header)
if !noXmlHeader {
writer.WriteString(xml.Header)
}
writer.Write(bytes)
writer.WriteByte('\n')
writer.Flush()