mirror of
https://github.com/go-task/task.git
synced 2024-12-04 10:24:45 +02:00
Run "set -e" automatically for every command
Without this, multiline command strings won't always exit when they fail. Closes #403
This commit is contained in:
parent
16fad60833
commit
ac8e344173
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## Unreleased
|
||||
|
||||
- `set -e` is now automatically set on every command. This was done to fix an
|
||||
issue where multiline string commands wouldn't really fail unless the
|
||||
sentence was in the last line
|
||||
([#403](https://github.com/go-task/task/issues/403)).
|
||||
|
||||
## v3.0.1
|
||||
|
||||
- Do not error if a specified dotenv file does not exist
|
||||
|
@ -27,8 +27,18 @@ type RunCommandOptions struct {
|
||||
var (
|
||||
// ErrNilOptions is returned when a nil options is given
|
||||
ErrNilOptions = errors.New("execext: nil options given")
|
||||
|
||||
setMinusE *syntax.File
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
setMinusE, err = syntax.NewParser().Parse(strings.NewReader("set -e"), "")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
// RunCommand runs a shell command
|
||||
func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
|
||||
if opts == nil {
|
||||
@ -54,6 +64,9 @@ func RunCommand(ctx context.Context, opts *RunCommandOptions) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if err = r.Run(ctx, setMinusE); err != nil {
|
||||
return err
|
||||
}
|
||||
return r.Run(ctx, p)
|
||||
}
|
||||
|
||||
|
16
task_test.go
16
task_test.go
@ -868,3 +868,19 @@ func TestDotenvShouldAllowMissingEnv(t *testing.T) {
|
||||
}
|
||||
tt.Run(t)
|
||||
}
|
||||
|
||||
func TestExitImmediately(t *testing.T) {
|
||||
const dir = "testdata/exit_immediately"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
|
||||
assert.Error(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
|
||||
assert.Contains(t, buff.String(), `"this_should_fail": executable file not found in $PATH`)
|
||||
}
|
||||
|
6
testdata/exit_immediately/Taskfile.yml
vendored
Normal file
6
testdata/exit_immediately/Taskfile.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
default: |
|
||||
this_should_fail
|
||||
echo "This shoudn't be print"
|
Loading…
Reference in New Issue
Block a user