Skip to content

Commit

Permalink
feat: add ability to use different Unix shells
Browse files Browse the repository at this point in the history
  • Loading branch information
zcapitalz committed Jun 25, 2024
1 parent e272b67 commit e6f235e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

CLI tool that runs `go test`(or another command from `--test-command-name`) with arguments from `--test-args`, parses test results from output and retries failed tests according to `--retries-per-test` and `--total-reries` limits. If `--total-retries` is 0, then no global limit is applied.

Testing commands are run using provided `--shell`(default "/bin/bash") with -c option.

**Usage of go-test-retryer**:
- --test-args string
  test arguments
Expand All @@ -14,7 +16,9 @@ CLI tool that runs `go test`(or another command from `--test-command-name`) with
- --json bool
  parse go test output as json
- --verbose bool
  verbose mode
  verbose mode
- --shell string
  path to shell (default "/bin/bash")

**Return values**:
- `0`: if all tests that failed during any run are successfuly retried
Expand Down
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Config struct {
testCommandName string
testArgs string
verbose bool
shellPath string
}

func NewConfigFromArgs(args []string) (Config, error) {
Expand All @@ -20,6 +21,7 @@ func NewConfigFromArgs(args []string) (Config, error) {
flag.BoolVar(&cfg.verbose, "verbose", false, "verbose mode")
flag.StringVar(&cfg.testCommandName, "test-command-name", "go test", `test command name`)
flag.StringVar(&cfg.testArgs, "test-args", "", "test arguments")
flag.StringVar(&cfg.shellPath, "shell", "/bin/bash", "path to shell")
flag.Parse()

if cfg.maxTotalRetries < 0 || cfg.maxRetriesPerTest < 0 {
Expand Down
2 changes: 1 addition & 1 deletion retryer.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (r *Retryer) testAndUpdateState(testArgs string) error {
}

func (r *Retryer) test(testArgs string, stdout, stderr io.Writer) error {
command := exec.Command("/bin/bash", "-c", r.cfg.testCommandName+" "+testArgs)
command := exec.Command(r.cfg.shellPath, "-c", r.cfg.testCommandName+" "+testArgs)
r.log("Running command:", strings.Join(command.Args, " "))
command.Stdout = stdout
command.Stderr = stderr
Expand Down

0 comments on commit e6f235e

Please sign in to comment.