mirror of
https://github.com/jstemmer/go-junit-report.git
synced 2025-04-04 20:50:14 -05:00
Update go-junit-report to use new parser
This commit is contained in:
parent
7bc0f1a86b
commit
72cd8b3697
@ -1,12 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/xml"
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/jstemmer/go-junit-report/formatter"
|
||||
"github.com/jstemmer/go-junit-report/parser"
|
||||
"github.com/jstemmer/go-junit-report/v2/pkg/gtr"
|
||||
"github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -21,6 +22,9 @@ var (
|
||||
goVersionFlag = flag.String("go-version", "", "specify the value to use for the go.version property in the generated XML")
|
||||
setExitCode = flag.Bool("set-exit-code", false, "set exit code to 1 if tests failed")
|
||||
version = flag.Bool("version", false, "print version")
|
||||
|
||||
// debug flags
|
||||
printEvents = flag.Bool("debug.print-events", false, "print events generated by the go test parser")
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -38,20 +42,36 @@ func main() {
|
||||
}
|
||||
|
||||
// Read input
|
||||
report, err := parser.Parse(os.Stdin, *packageName)
|
||||
events, err := gotest.Parse(os.Stdin)
|
||||
if err != nil {
|
||||
fmt.Printf("Error reading input: %s\n", err)
|
||||
fmt.Fprintf(os.Stderr, "Error reading input: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
// 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 *printEvents {
|
||||
for i, ev := range events {
|
||||
fmt.Printf("%02d: %#v\n", i, ev)
|
||||
}
|
||||
}
|
||||
report := gtr.FromEvents(events)
|
||||
|
||||
if !*noXMLHeader {
|
||||
fmt.Fprintf(os.Stdout, xml.Header)
|
||||
}
|
||||
|
||||
if *setExitCode && report.Failures() > 0 {
|
||||
enc := xml.NewEncoder(os.Stdout)
|
||||
enc.Indent("", "\t")
|
||||
if err := enc.Encode(gtr.JUnit(report)); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error writing XML: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if err := enc.Flush(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, "Error flusing XML: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
fmt.Fprintf(os.Stdout, "\n")
|
||||
|
||||
if *setExitCode && report.HasFailures() {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
@ -1560,13 +1560,27 @@ var testCases = []TestCase{
|
||||
},
|
||||
}
|
||||
|
||||
/*
|
||||
func TestNewOutput(t *testing.T) {
|
||||
matchRegex := compileMatch(t)
|
||||
for _, testCase := range testCases {
|
||||
if !matchRegex.MatchString(testCase.name) {
|
||||
continue
|
||||
}
|
||||
|
||||
t.Run(testCase.name, func(t *testing.T) {
|
||||
|
||||
})
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
func TestParser(t *testing.T) {
|
||||
matchRegex := compileMatch(t)
|
||||
for _, testCase := range testCases {
|
||||
if !matchRegex.MatchString(testCase.name) {
|
||||
continue
|
||||
}
|
||||
t.Logf("Test %s", testCase.name)
|
||||
|
||||
file, err := os.Open("testdata/" + testCase.name)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user