mirror of
https://github.com/go-task/task.git
synced 2025-02-07 13:41:53 +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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !call.Direct {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
return &errors.TaskRunError{TaskName: t.Task, Err: err}
|
return &errors.TaskRunError{TaskName: t.Task, Err: err}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
26
task_test.go
26
task_test.go
@ -1823,7 +1823,23 @@ Hello bar
|
|||||||
|
|
||||||
func TestErrorCode(t *testing.T) {
|
func TestErrorCode(t *testing.T) {
|
||||||
const dir = "testdata/error_code"
|
const dir = "testdata/error_code"
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
task string
|
||||||
|
expected int
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "direct task",
|
||||||
|
task: "direct",
|
||||||
|
expected: 42,
|
||||||
|
}, {
|
||||||
|
name: "indirect task",
|
||||||
|
task: "indirect",
|
||||||
|
expected: 42,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, test := range tests {
|
||||||
|
t.Run(test.name, func(t *testing.T) {
|
||||||
var buff bytes.Buffer
|
var buff bytes.Buffer
|
||||||
e := &task.Executor{
|
e := &task.Executor{
|
||||||
Dir: dir,
|
Dir: dir,
|
||||||
@ -1833,11 +1849,13 @@ func TestErrorCode(t *testing.T) {
|
|||||||
}
|
}
|
||||||
require.NoError(t, e.Setup())
|
require.NoError(t, e.Setup())
|
||||||
|
|
||||||
err := e.Run(context.Background(), taskfile.Call{Task: "test-exit-code"})
|
err := e.Run(context.Background(), taskfile.Call{Task: test.task, Direct: true})
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
casted, ok := err.(*errors.TaskRunError)
|
taskRunErr, ok := err.(*errors.TaskRunError)
|
||||||
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
|
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
|
||||||
assert.Equal(t, 42, casted.TaskExitCode(), "unexpected exit code from task")
|
assert.Equal(t, test.expected, taskRunErr.TaskExitCode(), "unexpected exit code from task")
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestEvaluateSymlinksInPaths(t *testing.T) {
|
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'
|
version: '3'
|
||||||
|
|
||||||
tasks:
|
tasks:
|
||||||
test-exit-code:
|
direct:
|
||||||
cmds:
|
cmds:
|
||||||
- exit 42
|
- exit 42
|
||||||
|
|
||||||
|
indirect:
|
||||||
|
cmds:
|
||||||
|
- task: direct
|
||||||
|
Loading…
x
Reference in New Issue
Block a user