outbuf := bytes.NewBuffer(nil)
err := run(path.Join(ZSDIR, cmd[0]), cmd[1:], vars, outbuf)
if err != nil {
- log.Println(err)
+ if _, ok := err.(*exec.ExitError); ok {
+ return "", err
+ }
outbuf = bytes.NewBuffer(nil)
err := run(cmd[0], cmd[1:], vars, outbuf)
- if err != nil {
+ // Return exit errors, but ignore if the command was not found
+ if _, ok := err.(*exec.ExitError); ok {
return "", err
}
}
"fmt"
"log"
"os"
+ "os/exec"
"strings"
"testing"
)
}
}
+func TestEvalCommand(t *testing.T) {
+ s, err := eval([]string{"echo", "hello"}, map[string]string{})
+ if err != nil {
+ t.Error(err)
+ }
+ if s != "hello\n" {
+ t.Error(s)
+ }
+ _, err = eval([]string{"cat", "bogus/file"}, map[string]string{})
+ if _, ok := err.(*exec.ExitError); !ok {
+ t.Error("expected ExitError")
+ }
+ _, err = eval([]string{"missing command"}, map[string]string{})
+ if err != nil {
+ t.Error("missing command should be ignored")
+ }
+}
+
func TestHelperProcess(*testing.T) {
if os.Getenv("ZS_HELPER") != "1" {
return