go-junit-report/go-junit-report.go
Eyal Posener 3c05bc8cb6 Fail package in case of build error
In case of build error, the unittest fail, but the junit-report
with the set-exit-code flag on returns status code 0.
This commit will make it return the right status code.
2017-01-22 10:13:01 +02:00

44 lines
847 B
Go

package main
import (
"flag"
"fmt"
"os"
"github.com/jstemmer/go-junit-report/parser"
)
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 := parser.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.Failed() {
os.Exit(1)
}
}