From 05755f3a52c248cb4f0647c7152adcb1c8f5cd8a Mon Sep 17 00:00:00 2001 From: Juan Ignacio Donoso Date: Sat, 7 Oct 2023 18:57:14 -0300 Subject: [PATCH] fix: templates on task descriptions (#1343) --- task.go | 5 +++-- task_test.go | 18 ++++++++++++++++++ testdata/list_desc_interpolation/Taskfile.yml | 8 ++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 testdata/list_desc_interpolation/Taskfile.yml diff --git a/task.go b/task.go index c8f5d79f..efed681e 100644 --- a/task.go +++ b/task.go @@ -469,13 +469,14 @@ func (e *Executor) GetTaskList(filters ...FilterFunc) ([]*taskfile.Task, error) // Compile the list of tasks for i := range tasks { - task := tasks[i] + idx := i + task := tasks[idx] g.Go(func() error { compiledTask, err := e.FastCompiledTask(taskfile.Call{Task: task.Task}) if err == nil { task = compiledTask } - task = compiledTask + tasks[idx] = compiledTask return nil }) } diff --git a/task_test.go b/task_test.go index c926adb1..43df8bf2 100644 --- a/task_test.go +++ b/task_test.go @@ -828,6 +828,24 @@ func TestListCanListDescOnly(t *testing.T) { } } +func TestListDescInterpolation(t *testing.T) { + const dir = "testdata/list_desc_interpolation" + + var buff bytes.Buffer + e := task.Executor{ + Dir: dir, + Stdout: &buff, + Stderr: &buff, + } + + require.NoError(t, e.Setup()) + if _, err := e.ListTasks(task.ListOptions{ListOnlyTasksWithDescriptions: true}); err != nil { + t.Error(err) + } + + assert.Contains(t, buff.String(), "bar") +} + func TestStatusVariables(t *testing.T) { const dir = "testdata/status_vars" diff --git a/testdata/list_desc_interpolation/Taskfile.yml b/testdata/list_desc_interpolation/Taskfile.yml new file mode 100644 index 00000000..71aaafe1 --- /dev/null +++ b/testdata/list_desc_interpolation/Taskfile.yml @@ -0,0 +1,8 @@ +version: '3' + +vars: + foo: bar + +tasks: + foo: + desc: "task has desc with {{ .foo }} var"