Skip to content

Commit

Permalink
Expose a flag for reruning the entire root test case
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Aug 28, 2022
1 parent 7b7f7dc commit 4ce5ec4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
7 changes: 3 additions & 4 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -159,7 +158,7 @@ type options struct {
rerunFailsMaxAttempts int
rerunFailsMaxInitialFailures int
rerunFailsReportFile string
rerunFailsOnlyRootCases bool
rerunFailsRunRootCases bool
packages []string
watch bool
maxFails int
Expand Down
10 changes: 8 additions & 2 deletions cmd/rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions cmd/testdata/gotestsum-help-text
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 4ce5ec4

Please sign in to comment.