Skip to content

Commit d322a58

Browse files
committed
Use set -e to fail bash commands immediately
1 parent e044e3b commit d322a58

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77
)
88

99
func runCommand(command string) (out []byte, err error) {
10-
out, err = exec.Command("bash", "-c", command).CombinedOutput()
10+
out, err = exec.Command("bash", "-ce", command).CombinedOutput()
1111

1212
if err != nil {
1313
return out, errors.Wrap(err, string(out))

command_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ echo baz
1919
Assert(string(out), "foo\nbar\nbaz\n", t)
2020
}
2121

22+
func TestBashSetE(t *testing.T) {
23+
command := `
24+
echo "first"
25+
BOOM
26+
echo "second"
27+
`
28+
out, err := runCommand(command)
29+
30+
if err == nil {
31+
t.Error("expected an error but received none")
32+
}
33+
Assert(string(out), "first\nbash: line 2: BOOM: command not found\n", t)
34+
}
35+
2236
func TestFailingCommand(t *testing.T) {
2337
out, err := runCommand("echo 'BOOM!' && exit 1")
2438

0 commit comments

Comments
 (0)