1
0
mirror of https://github.com/go-task/task.git synced 2025-08-08 22:36:57 +02:00
This commit is contained in:
Valentin Maerten
2025-01-05 13:46:24 +01:00
parent d3e0fc9eea
commit 596fd29cb2
6 changed files with 65 additions and 2 deletions

View File

@ -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()

View File

@ -0,0 +1,9 @@
version: '3'
preconditions:
- sh: "[ 1 = 0 ]"
msg: "1 != 0 obviously!"
tasks:
impossible:
cmd: echo "won't run"

View 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
View File