Skip to content

Commit

Permalink
rerun-fails: Fix a bug that would result in a passed run
Browse files Browse the repository at this point in the history
When some tests in the package have failed, but the last test of the
package passes.
  • Loading branch information
dnephin committed Sep 1, 2020
1 parent e1d4f60 commit 0ba6504
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
}

rec := newFailureRecorderFromExecution(scanConfig.Execution)
var lastErr error
for attempts := 0; rec.count() > 0 && attempts < opts.rerunFailsMaxAttempts; attempts++ {
testjson.PrintSummary(opts.stdout, scanConfig.Execution, testjson.SummarizeNone)
opts.stdout.Write([]byte("\n")) // nolint: errcheck
Expand All @@ -75,14 +74,17 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
if _, err := testjson.ScanTestOutput(cfg); err != nil {
return err
}
lastErr = goTestProc.cmd.Wait()
if err := hasErrors(lastErr, scanConfig.Execution); err != nil {
exitErr := goTestProc.cmd.Wait()
if exitErr != nil {
nextRec.lastErr = exitErr
}
if err := hasErrors(exitErr, scanConfig.Execution); err != nil {
return err
}
}
rec = nextRec
}
return lastErr
return rec.lastErr
}

// startGoTestFn is a shim for testing
Expand All @@ -103,6 +105,7 @@ func hasErrors(err error, exec *testjson.Execution) error {
type failureRecorder struct {
testjson.EventHandler
failures []testjson.TestCase
lastErr error
}

func newFailureRecorder(handler testjson.EventHandler) *failureRecorder {
Expand Down

0 comments on commit 0ba6504

Please sign in to comment.