go-junit-report/go-junit-report.go
itamarb a34e6b2365 adding 'set-exit-code' flag
Defaults to false. When true, sets the exit-code to 1 if any tests
failed. This is useful for automation.
2015-05-08 13:56:18 +03:00

42 lines
799 B
Go

package main
import (
"flag"
"fmt"
"os"
)
var (
noXMLHeader bool
packageName string
setExitCode bool
)
func init() {
flag.BoolVar(&noXMLHeader, "no-xml-header", false, "do not print xml header")
flag.StringVar(&packageName, "package-name", "", "specify a package name (compiled test have no package name in output)")
flag.BoolVar(&setExitCode, "set-exit-code", false, "set exit code to 1 if tests failed")
}
func main() {
flag.Parse()
// Read input
report, err := Parse(os.Stdin, packageName)
if err != nil {
fmt.Printf("Error reading input: %s\n", err)
os.Exit(1)
}
// Write xml
err = JUnitReportXML(report, noXMLHeader, os.Stdout)
if err != nil {
fmt.Printf("Error writing XML: %s\n", err)
os.Exit(1)
}
if setExitCode && report.Failures() > 0 {
os.Exit(1)
}
}