From 4ce5ec4baecffc6b0ac754f145bf7b845aef65ce Mon Sep 17 00:00:00 2001 From: Daniel Nephin Date: Sun, 28 Aug 2022 17:50:55 -0400 Subject: [PATCH] Expose a flag for reruning the entire root test case --- cmd/main.go | 7 +++---- cmd/rerunfails.go | 10 ++++++++-- cmd/testdata/gotestsum-help-text | 1 + 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/cmd/main.go b/cmd/main.go index 553cad5c..303d823e 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -101,9 +101,8 @@ func setupFlags(name string) (*pflag.FlagSet, *options) { "space separated list of package to test") flags.StringVar(&opts.rerunFailsReportFile, "rerun-fails-report", "", "write a report to the file, of the tests that were rerun") - flags.BoolVar(&opts.rerunFailsOnlyRootCases, "rerun-fails-only-root-testcases", false, - "rerun only root testcaes, instead of only subtests") - flags.Lookup("rerun-fails-only-root-testcases").Hidden = true + flags.BoolVar(&opts.rerunFailsRunRootCases, "rerun-fails-run-root-test", false, + "rerun the entire root testcase when any of its subtests fail, instead of only the failed subtest") flags.BoolVar(&opts.debug, "debug", false, "enabled debug logging") flags.BoolVar(&opts.version, "version", false, "show version and exit") @@ -159,7 +158,7 @@ type options struct { rerunFailsMaxAttempts int rerunFailsMaxInitialFailures int rerunFailsReportFile string - rerunFailsOnlyRootCases bool + rerunFailsRunRootCases bool packages []string watch bool maxFails int diff --git a/cmd/rerunfails.go b/cmd/rerunfails.go index 4676301c..aadaf428 100644 --- a/cmd/rerunfails.go +++ b/cmd/rerunfails.go @@ -35,9 +35,15 @@ func newRerunOptsFromTestCase(tc testjson.TestCase) rerunOpts { type testCaseFilter func([]testjson.TestCase) []testjson.TestCase func rerunFailsFilter(o *options) testCaseFilter { - if o.rerunFailsOnlyRootCases { + if o.rerunFailsRunRootCases { return func(tcs []testjson.TestCase) []testjson.TestCase { - return tcs + var result []testjson.TestCase + for _, tc := range tcs { + if !tc.Test.IsSubTest() { + result = append(result, tc) + } + } + return result } } return testjson.FilterFailedUnique diff --git a/cmd/testdata/gotestsum-help-text b/cmd/testdata/gotestsum-help-text index 9e468823..a3827824 100644 --- a/cmd/testdata/gotestsum-help-text +++ b/cmd/testdata/gotestsum-help-text @@ -19,6 +19,7 @@ Flags: --rerun-fails int[=2] rerun failed tests until they all pass, or attempts exceeds maximum. Defaults to max 2 reruns when enabled. --rerun-fails-max-failures int do not rerun any tests if the initial run has more than this number of failures (default 10) --rerun-fails-report string write a report to the file, of the tests that were rerun + --rerun-fails-run-root-test rerun the entire root testcase when any of its subtests fail, instead of only the failed subtest --version show version and exit --watch watch go files, and run tests when a file is modified