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:
parent
a790fb7afe
commit
58c7cc5d05
19
task_test.go
19
task_test.go
@ -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
6
testdata/error_code/Taskfile.yml
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
test-exit-code:
|
||||
cmds:
|
||||
- exit 42
|
Loading…
x
Reference in New Issue
Block a user