1
0
mirror of https://github.com/go-task/task.git synced 2025-02-09 13:47:06 +02:00

Adds test TestErrorCode

This commit is contained in:
Bruno Delor 2022-06-02 16:39:28 +02:00
parent a790fb7afe
commit 58c7cc5d05
2 changed files with 25 additions and 0 deletions

View File

@ -1275,3 +1275,22 @@ VAR_2 is included-default-var2
t.Log(buff.String())
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
}
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,
}
assert.NoError(t, e.Setup())
err := e.Run(context.Background(), taskfile.Call{Task: "test-exit-code"})
assert.Error(t, err)
casted, ok := err.(*task.TaskRunError)
assert.True(t, ok, "cannot cast returned error to *task.TaskRunError")
assert.Equal(t, 42, casted.ExitCode(), "unexpected exit code from task")
}

6
testdata/error_code/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,6 @@
version: '3'
tasks:
test-exit-code:
cmds:
- exit 42