Skip to content

Commit

Permalink
Exit rerun if exit status > 1
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Jun 20, 2020
1 parent b2e1ee6 commit 18ce2af
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 6 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,13 @@ func run(opts *options) error {
return err
}
goTestExitErr := goTestProc.cmd.Wait()

if goTestExitErr != nil && opts.rerunFailsMaxAttempts > 0 {
cfg := testjson.ScanConfig{Execution: exec, Handler: handler}
goTestExitErr = rerunFailed(ctx, opts, cfg)
goTestExitErr = hasErrors(goTestExitErr, exec)
if goTestExitErr == nil {
cfg := testjson.ScanConfig{Execution: exec, Handler: handler}
goTestExitErr = rerunFailed(ctx, opts, cfg)
}
}

testjson.PrintSummary(opts.stdout, exec, opts.noSummary.value)
Expand Down
22 changes: 9 additions & 13 deletions rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"strings"

"github.com/pkg/errors"
"gotest.tools/gotestsum/log"
"gotest.tools/gotestsum/testjson"
)

Expand All @@ -33,9 +32,6 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
"number of test failures (%d) exceeds maximum (%d) set by --rerun-fails-max-failures",
failed, opts.rerunFailsMaxInitialFailures)
}
if err := hasErrors(scanConfig.Execution); err != nil {
return err
}

rec := newFailureRecorderFromExecution(scanConfig.Execution)
var lastErr error
Expand Down Expand Up @@ -64,12 +60,7 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
return err
}
lastErr = goTestProc.cmd.Wait()
// 0 and 1 are expected.
if ExitCodeWithDefault(lastErr) > 1 {
log.Warnf("unexpected go test exit code: %v", lastErr)
// TODO: will 'go test' exit with 2 if it panics? maybe return err here.
}
if err := hasErrors(scanConfig.Execution); err != nil {
if err := hasErrors(lastErr, scanConfig.Execution); err != nil {
return err
}
rec = nextRec
Expand All @@ -78,11 +69,16 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
return lastErr
}

func hasErrors(exec *testjson.Execution) error {
if len(exec.Errors()) > 0 {
func hasErrors(err error, exec *testjson.Execution) error {
switch {
case len(exec.Errors()) > 0:
return fmt.Errorf("rerun aborted because previous run had errors")
// Exit code 0 and 1 are expected.
case ExitCodeWithDefault(err) > 1:
return fmt.Errorf("unexpected go test exit code: %v", err)
default:
return nil
}
return nil
}

type failureRecorder struct {
Expand Down

0 comments on commit 18ce2af

Please sign in to comment.