Skip to content

Commit

Permalink
Merge pull request #275 from gotestyourself/rerun-root-cases
Browse files Browse the repository at this point in the history
Add a flag for running the entire root test case when any of its subtests fail
  • Loading branch information
dnephin committed Sep 3, 2022
2 parents 77c5a23 + 4ce5ec4 commit e5943e1
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 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
8 changes: 6 additions & 2 deletions internal/text/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@ import (
"bufio"
"io"
"strings"
"testing"

"gotest.tools/v3/assert"
)

type TestingT interface {
Helper()
assert.TestingT
}

// ProcessLines from the Reader by passing each one to ops. The output of each
// op is passed to the next. Returns the string created by joining all the
// processed lines.
func ProcessLines(t *testing.T, r io.Reader, ops ...func(string) string) string {
func ProcessLines(t TestingT, r io.Reader, ops ...func(string) string) string {
t.Helper()
out := new(strings.Builder)
scan := bufio.NewScanner(r)
Expand Down

0 comments on commit e5943e1

Please sign in to comment.