diff --git a/go-junit-report.go b/go-junit-report.go index fc44ad4..3121552 100644 --- a/go-junit-report.go +++ b/go-junit-report.go @@ -9,6 +9,7 @@ import ( "os" "strings" + "github.com/jstemmer/go-junit-report/v2/pkg/gtr" "github.com/jstemmer/go-junit-report/v2/pkg/junit" "github.com/jstemmer/go-junit-report/v2/pkg/parser/gotest" ) @@ -28,6 +29,7 @@ var ( output = flag.String("out", "", "write XML report to `file`") iocopy = flag.Bool("iocopy", false, "copy input to stdout; can only be used in conjunction with -out") properties = make(keyValueFlag) + inputParser = flag.String("parser", "gotest", "set input parser: gotest, gojson") // debug flags printEvents = flag.Bool("debug.print-events", false, "print events generated by the go test parser") @@ -75,7 +77,17 @@ func main() { in = io.TeeReader(in, os.Stdout) } - parser := gotest.New(gotest.PackageName(*packageName)) + var parser Parser + switch *inputParser { + case "gotest": + parser = gotest.New(gotest.PackageName(*packageName)) + case "gojson": + parser = gotest.NewJSON(gotest.PackageName(*packageName)) + default: + fmt.Fprintf(os.Stderr, "invalid parser: %s\n", *inputParser) + flag.Usage() + os.Exit(1) + } report, err := parser.Parse(in) if err != nil { @@ -166,3 +178,8 @@ func (f *keyValueFlag) Set(value string) error { (*f)[k] = v return nil } + +type Parser interface { + Parse(r io.Reader) (gtr.Report, error) + Events() []gotest.Event +}