mirror of
https://github.com/go-task/task.git
synced 2025-08-08 22:36:57 +02:00
add test
This commit is contained in:
46
task_test.go
46
task_test.go
@ -456,10 +456,10 @@ func TestStatus(t *testing.T) {
|
||||
buff.Reset()
|
||||
}
|
||||
|
||||
func TestPrecondition(t *testing.T) {
|
||||
func TestPreconditionLocal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
const dir = "testdata/precondition"
|
||||
const dir = "testdata/precondition/local"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := &task.Executor{
|
||||
@ -499,6 +499,48 @@ func TestPrecondition(t *testing.T) {
|
||||
buff.Reset()
|
||||
}
|
||||
|
||||
func TestPreconditionGlobal(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := &task.Executor{
|
||||
Dir: "testdata/precondition/global",
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
// A global precondition that was not met
|
||||
require.Error(t, e.Run(context.Background(), &ast.Call{Task: "impossible"}))
|
||||
|
||||
if buff.String() != "task: 1 != 0 obviously!\n" {
|
||||
t.Errorf("Wrong output message: %s", buff.String())
|
||||
}
|
||||
buff.Reset()
|
||||
|
||||
e = &task.Executor{
|
||||
Dir: "testdata/precondition/global/with_local",
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
// A global precondition that was met
|
||||
require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "foo"}))
|
||||
if buff.String() != "" {
|
||||
t.Errorf("Got Output when none was expected: %s", buff.String())
|
||||
}
|
||||
|
||||
// A local precondition that was not met
|
||||
require.Error(t, e.Run(context.Background(), &ast.Call{Task: "impossible"}))
|
||||
|
||||
if buff.String() != "task: 1 != 0 obviously!\n" {
|
||||
t.Errorf("Wrong output message: %s", buff.String())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGenerates(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
|
9
testdata/precondition/global/Taskfile.yml
vendored
Normal file
9
testdata/precondition/global/Taskfile.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
version: '3'
|
||||
|
||||
preconditions:
|
||||
- sh: "[ 1 = 0 ]"
|
||||
msg: "1 != 0 obviously!"
|
||||
|
||||
tasks:
|
||||
impossible:
|
||||
cmd: echo "won't run"
|
12
testdata/precondition/global/with_local/Taskfile.yml
vendored
Normal file
12
testdata/precondition/global/with_local/Taskfile.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
version: '3'
|
||||
|
||||
preconditions:
|
||||
- test -f foo.txt
|
||||
|
||||
tasks:
|
||||
foo:
|
||||
|
||||
impossible:
|
||||
preconditions:
|
||||
- sh: "[ 1 = 0 ]"
|
||||
msg: "1 != 0 obviously!"
|
0
testdata/precondition/local/foo.txt
vendored
Normal file
0
testdata/precondition/local/foo.txt
vendored
Normal file
Reference in New Issue
Block a user