diff --git a/task_test.go b/task_test.go index e391a48e..27cc6aab 100644 --- a/task_test.go +++ b/task_test.go @@ -1059,6 +1059,40 @@ func TestIncludesInternal(t *testing.T) { } } +func TestIncludesInterpolation(t *testing.T) { + const dir = "testdata/includes_interpolation" + tests := []struct { + name string + task string + expectedErr bool + expectedOutput string + }{ + {"include", "include", false, "includes_interpolation\n"}, + {"include with dir", "include-with-dir", false, "included\n"}, + } + + for _, test := range tests { + t.Run(test.name, func(t *testing.T) { + 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.task}) + if test.expectedErr { + assert.Error(t, err) + } else { + assert.NoError(t, err) + } + assert.Equal(t, test.expectedOutput, buff.String()) + }) + } +} + func TestInternalTask(t *testing.T) { const dir = "testdata/internal_task" tests := []struct { diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index fd567916..4553e542 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -73,7 +73,7 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, error) { err = t.Includes.Range(func(namespace string, includedTask taskfile.IncludedTaskfile) error { if v >= 3.0 { - tr := templater.Templater{Vars: &taskfile.Vars{}, RemoveNoValue: true} + tr := templater.Templater{Vars: t.Vars, RemoveNoValue: true} includedTask = taskfile.IncludedTaskfile{ Taskfile: tr.Replace(includedTask.Taskfile), Dir: tr.Replace(includedTask.Dir), diff --git a/testdata/includes_interpolation/Taskfile.yml b/testdata/includes_interpolation/Taskfile.yml new file mode 100644 index 00000000..3c4bfe9d --- /dev/null +++ b/testdata/includes_interpolation/Taskfile.yml @@ -0,0 +1,10 @@ +version: "3" + +vars: + MODULE_NAME: included + +includes: + include: './{{.MODULE_NAME}}/Taskfile.yml' + include-with-dir: + taskfile: './{{.MODULE_NAME}}/Taskfile.yml' + dir: '{{.MODULE_NAME}}' diff --git a/testdata/includes_interpolation/included/Taskfile.yml b/testdata/includes_interpolation/included/Taskfile.yml new file mode 100644 index 00000000..b6c24075 --- /dev/null +++ b/testdata/includes_interpolation/included/Taskfile.yml @@ -0,0 +1,6 @@ +version: "3" + +tasks: + default: + cmds: + - basename $(pwd)