diff --git a/task_test.go b/task_test.go index d8117eeefc..11c9ceef09 100644 --- a/task_test.go +++ b/task_test.go @@ -2548,3 +2548,12 @@ func TestReference(t *testing.T) { }) } } + +func TestRequires(t *testing.T) { + e := task.Executor{ + Dir: "testdata/requires", + } + require.NoError(t, e.Setup()) + require.NoError(t, e.Run(context.Background(), &ast.Call{Task: "requires-set"})) + require.Error(t, e.Run(context.Background(), &ast.Call{Task: "requires-not-set"})) +} diff --git a/testdata/requires/Taskfile.yml b/testdata/requires/Taskfile.yml new file mode 100644 index 0000000000..25ec79852a --- /dev/null +++ b/testdata/requires/Taskfile.yml @@ -0,0 +1,16 @@ +version: '3' + +vars: + FILE_VAR: 'file_var' + +tasks: + requires-set: + vars: + TASK_VAR: 'task_var' + requires: + vars: [FILE_VAR, TASK_VAR] + requires-not-set: + vars: + TASK_VAR: 'task_var' + requires: + vars: [FILE_VAR, TASK_VAR, NOT_SET_VAR] \ No newline at end of file diff --git a/variables.go b/variables.go index db2a3fc4da..2d29cc642f 100644 --- a/variables.go +++ b/variables.go @@ -56,7 +56,7 @@ func (e *Executor) compiledTask(call *ast.Call, evaluateShVars bool) (*ast.Task, Dir: templater.Replace(origTask.Dir, cache), Set: origTask.Set, Shopt: origTask.Shopt, - Vars: nil, + Vars: vars, Env: nil, Dotenv: templater.Replace(origTask.Dotenv, cache), Silent: origTask.Silent,