From 9ad16898a8044f83800984add0907d4e1c070ecb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Stemmer?= Date: Sun, 22 May 2022 00:34:05 +0100 Subject: [PATCH] Add -subtest-mode flag to configure SubtestMode --- README.md | 1 + internal/gojunitreport/go-junit-report.go | 2 ++ main.go | 11 +++++++++++ 3 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 462bedd..1152ca7 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,7 @@ Run `go-junit-report -help` for a list of all supported flags. | `-parser parser` | specify the parser to use, available parsers are: `gotest` (default), `gojson` | | `-p key=value` | add property to generated report; properties should be specified as `key=value` | | `-set-exit-code` | set exit code to 1 if tests failed | +| `-subtest-mode` | set subtest `mode`, modes are: `ignore-parent-results`, `exclude-parents` | | `-version` | print version and exit | ## Contributing diff --git a/internal/gojunitreport/go-junit-report.go b/internal/gojunitreport/go-junit-report.go index a3b6970..748b138 100644 --- a/internal/gojunitreport/go-junit-report.go +++ b/internal/gojunitreport/go-junit-report.go @@ -24,6 +24,7 @@ type Config struct { Hostname string PackageName string SkipXMLHeader bool + SubtestMode gotest.SubtestMode Properties map[string]string // For debugging @@ -96,6 +97,7 @@ func (c Config) writeXML(w io.Writer, report gtr.Report) error { func (c Config) gotestOptions() []gotest.Option { return []gotest.Option{ gotest.PackageName(c.PackageName), + gotest.SetSubtestMode(c.SubtestMode), gotest.TimestampFunc(c.timestampFunc), } } diff --git a/main.go b/main.go index 3080a30..fc601a3 100644 --- a/main.go +++ b/main.go @@ -8,6 +8,7 @@ import ( "strings" "github.com/jstemmer/go-junit-report/v2/internal/gojunitreport" + "github.com/jstemmer/go-junit-report/v2/parser/gotest" ) var ( @@ -26,6 +27,7 @@ var ( iocopy = flag.Bool("iocopy", false, "copy input to stdout; can only be used in conjunction with -out") properties = make(keyValueFlag) parser = flag.String("parser", "gotest", "set input parser: gotest, gojson") + mode = flag.String("subtest-mode", "", "set subtest `mode`: ignore-parent-results (subtest parents always pass), exclude-parents (subtest parents are excluded from the report)") // debug flags printEvents = flag.Bool("debug.print-events", false, "print events generated by the go test parser") @@ -52,6 +54,14 @@ func main() { properties["go.version"] = *goVersionFlag } + subtestMode := gotest.SubtestModeDefault + if *mode != "" { + var err error + if subtestMode, err = gotest.ParseSubtestMode(*mode); err != nil { + exitf("invalid value for -subtest-mode: %s\n", err) + } + } + if flag.NArg() != 0 { fmt.Fprintf(os.Stderr, "invalid argument(s): %s\n", strings.Join(flag.Args(), " ")) fmt.Fprintf(os.Stderr, "%s does not accept positional arguments\n", os.Args[0]) @@ -90,6 +100,7 @@ func main() { Hostname: hostname, PackageName: *packageName, SkipXMLHeader: *noXMLHeader, + SubtestMode: subtestMode, Properties: properties, PrintEvents: *printEvents, }