mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
fix: exit codes for indirect tasks
This commit is contained in:
parent
659ba317c1
commit
6059ce2ac4
4
task.go
4
task.go
@ -239,6 +239,10 @@ func (e *Executor) RunTask(ctx context.Context, call taskfile.Call) error {
|
||||
continue
|
||||
}
|
||||
|
||||
if !call.Direct {
|
||||
return err
|
||||
}
|
||||
|
||||
return &errors.TaskRunError{TaskName: t.Task, Err: err}
|
||||
}
|
||||
}
|
||||
|
44
task_test.go
44
task_test.go
@ -1823,21 +1823,39 @@ Hello bar
|
||||
|
||||
func TestErrorCode(t *testing.T) {
|
||||
const dir = "testdata/error_code"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := &task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
tests := []struct {
|
||||
name string
|
||||
task string
|
||||
expected int
|
||||
}{
|
||||
{
|
||||
name: "direct task",
|
||||
task: "direct",
|
||||
expected: 42,
|
||||
}, {
|
||||
name: "indirect task",
|
||||
task: "indirect",
|
||||
expected: 42,
|
||||
},
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var buff bytes.Buffer
|
||||
e := &task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
err := e.Run(context.Background(), taskfile.Call{Task: "test-exit-code"})
|
||||
require.Error(t, err)
|
||||
casted, ok := err.(*errors.TaskRunError)
|
||||
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
|
||||
assert.Equal(t, 42, casted.TaskExitCode(), "unexpected exit code from task")
|
||||
err := e.Run(context.Background(), taskfile.Call{Task: test.task, Direct: true})
|
||||
require.Error(t, err)
|
||||
taskRunErr, ok := err.(*errors.TaskRunError)
|
||||
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
|
||||
assert.Equal(t, test.expected, taskRunErr.TaskExitCode(), "unexpected exit code from task")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEvaluateSymlinksInPaths(t *testing.T) {
|
||||
|
6
testdata/error_code/Taskfile.yml
vendored
6
testdata/error_code/Taskfile.yml
vendored
@ -1,6 +1,10 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
test-exit-code:
|
||||
direct:
|
||||
cmds:
|
||||
- exit 42
|
||||
|
||||
indirect:
|
||||
cmds:
|
||||
- task: direct
|
||||
|
Loading…
x
Reference in New Issue
Block a user