Skip to content

Commit

Permalink
Allow gotestsum to rerun tests that panic
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelnano committed Dec 7, 2022
1 parent f9eefe9 commit 8c70ff0
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ func run(opts *options) error {
if exitErr == nil || opts.rerunFailsMaxAttempts == 0 {
return finishRun(opts, exec, exitErr)
}
if err := hasErrors(exitErr, exec); err != nil {
fmt.Printf("Executor has %#v", exec.FullPackages())

This comment has been minimized.

Copy link
@ddelnano

ddelnano Dec 7, 2022

Author Owner

This was part of my debugging to as I tested this change.

if err := hasErrors(exitErr, exec, true); err != nil {
return finishRun(opts, exec, err)
}

Expand Down
7 changes: 5 additions & 2 deletions cmd/rerunfails.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
if exitErr != nil {
nextRec.lastErr = exitErr
}
if err := hasErrors(exitErr, scanConfig.Execution); err != nil {
if err := hasErrors(exitErr, scanConfig.Execution, true); err != nil {
return err
}
}
Expand All @@ -93,14 +93,17 @@ func rerunFailed(ctx context.Context, opts *options, scanConfig testjson.ScanCon
// startGoTestFn is a shim for testing
var startGoTestFn = startGoTest

func hasErrors(err error, exec *testjson.Execution) error {
func hasErrors(err error, exec *testjson.Execution, ignorePanic bool) 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)
case exec.HasPanic():
if ignorePanic {
return nil
}
return fmt.Errorf("rerun aborted because previous run had a suspected panic and some test may not have run")
default:
return nil
Expand Down
15 changes: 15 additions & 0 deletions testjson/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,21 @@ func (e *Execution) HasPanic() bool {
return false
}

func (e *Execution) FullPackages() []Package {

This comment has been minimized.

Copy link
@ddelnano

ddelnano Dec 7, 2022

Author Owner

This is more debugging code and not related to making panic'ed tests rerun.

ps := []Package{}
for _, p := range e.packages {
ps = append(ps, *p)
}
return ps
}

func (e *Execution) PrintPackages() {
fmt.Println("Print packages")
for k, p := range e.packages {
fmt.Printf("Package '%s' has content %v\n", k, *p)
}
}

func (e *Execution) end() []TestEvent {
e.done = true
var result []TestEvent // nolint: prealloc
Expand Down

0 comments on commit 8c70ff0

Please sign in to comment.