forked from sachenna/go-junit-report
-
Notifications
You must be signed in to change notification settings - Fork 0
/
go-junit-report.go
52 lines (43 loc) · 1.22 KB
/
go-junit-report.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package main
import (
"flag"
"fmt"
"os"
"github.com/jbeshay/go-junit-report/formatter"
"github.com/jbeshay/go-junit-report/parser"
)
var (
noXMLHeader bool
packageName string
goVersionFlag 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.StringVar(&goVersionFlag, "go-version", "", "specify the value to use for the go.version property in the generated XML")
flag.BoolVar(&setExitCode, "set-exit-code", false, "set exit code to 1 if tests failed")
}
func main() {
flag.Parse()
if flag.NArg() != 0 {
fmt.Println("go-junit-report does not accept positional arguments")
os.Exit(1)
}
// Read input
report, err := parser.Parse(os.Stdin, packageName)
if err != nil {
fmt.Printf("Error reading input: %s\n", err)
os.Exit(1)
}
//fmt.Println("Package name: ", report.Packages[0].Name)
// Write xml
err = formatter.JUnitReportXML(report, noXMLHeader, goVersionFlag, os.Stdout)
if err != nil {
fmt.Printf("Error writing XML: %s\n", err)
os.Exit(1)
}
if setExitCode && report.Failures() > 0 {
os.Exit(1)
}
}