diff --git a/errors_test.go b/errors_test.go index fdebb52..247a4d2 100644 --- a/errors_test.go +++ b/errors_test.go @@ -11,6 +11,7 @@ import ( func TestErrors(t *testing.T) { var errors runn.Errors errors.Add(fmt.Errorf("error1")) + errors.Add(nil) errors.Add(fmt.Errorf("error2")) errors.Add(fmt.Errorf("error3")) diff --git a/executor.go b/executor.go index c6f767b..c289a9e 100644 --- a/executor.go +++ b/executor.go @@ -1,11 +1,5 @@ package runn -import ( - "bytes" - "fmt" - "os/exec" -) - // Executor do the code statement execution type Executor struct { StopWhenError bool @@ -31,20 +25,6 @@ func (e Executor) Execute(stmts ...interface{}) (err error) { } errs.Add(runErr) } - case *exec.Cmd: - execCmd := stmt.(*exec.Cmd) - buf := bytes.Buffer{} - execCmd.Stdout = &buf - execCmd.Stderr = &buf - - runErr := execCmd.Run() - if err != nil { - runErr = fmt.Errorf("%s: %s", err.Error(), buf.String()) - if e.StopWhenError { - return runErr - } - errs.Add(runErr) - } } } if len(errs) > 0 { diff --git a/executor_test.go b/executor_test.go index dcdb57f..fc0bbc1 100644 --- a/executor_test.go +++ b/executor_test.go @@ -12,7 +12,7 @@ import ( type RunnerImplementationWithError struct{} -func (i RunnerImplementationWithError) Run() error { return errors.New("some-error") } +func (i RunnerImplementationWithError) Run() error { return errors.New("some-runner-error") } type RunnerImplementationNoError struct{} @@ -27,12 +27,12 @@ func TestExecutor_All(t *testing.T) { { false, []interface{}{ - RunnerImplementationWithError{}, errors.New("error1"), + RunnerImplementationWithError{}, errors.New("error2"), exec.Command("wrong-command", "bad-argument"), }, - errors.New("some-error; error1; error2; exec: \"wrong-command\": executable file not found in $PATH"), + errors.New("error1; some-runner-error; error2; exec: \"wrong-command\": executable file not found in $PATH"), }, { true, @@ -43,15 +43,27 @@ func TestExecutor_All(t *testing.T) { errors.New("error1"), }, { - false, - []interface{}{}, - nil, + true, + []interface{}{ + RunnerImplementationWithError{}, + errors.New("unreachable-error"), + }, + errors.New("some-runner-error"), }, { true, + []interface{}{ + exec.Command("wrong-command", "bad-argument"), + errors.New("unreachable-error"), + }, + errors.New("exec: \"wrong-command\": executable file not found in $PATH"), + }, + { + false, []interface{}{}, nil, }, + { false, []interface{}{ diff --git a/runner.go b/runner.go index f13854a..2a24e9c 100644 --- a/runner.go +++ b/runner.go @@ -1,5 +1,6 @@ package runn +// Runner contain run function type Runner interface { Run() error }