diff --git a/CHANGELOG.md b/CHANGELOG.md index 31dec425..4d987c0b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Unreleased + +- Fix panic when you have empty tasks in your Taskfile + ([#338](https://github.com/go-task/task/issues/338), [#362](https://github.com/go-task/task/pull/362)). + ## v3.0.0 - On `v3`, all CLI variables will be considered global variables diff --git a/task_test.go b/task_test.go index c757fa54..f991f163 100644 --- a/task_test.go +++ b/task_test.go @@ -56,6 +56,16 @@ func (fct fileContentTest) Run(t *testing.T) { } } +func TestEmptyTask(t *testing.T) { + e := &task.Executor{ + Dir: "testdata/empty_task", + Stdout: ioutil.Discard, + Stderr: ioutil.Discard, + } + assert.NoError(t, e.Setup(), "e.Setup()") + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"})) +} + func TestEnv(t *testing.T) { tt := fileContentTest{ Dir: "testdata/env", diff --git a/taskfile/read/taskfile.go b/taskfile/read/taskfile.go index d999e7fd..e333feb7 100644 --- a/taskfile/read/taskfile.go +++ b/taskfile/read/taskfile.go @@ -119,6 +119,10 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) { } for name, task := range t.Tasks { + if task == nil { + task = &taskfile.Task{} + t.Tasks[name] = task + } task.Task = name } diff --git a/testdata/empty_task/Taskfile.yml b/testdata/empty_task/Taskfile.yml new file mode 100644 index 00000000..797a62ce --- /dev/null +++ b/testdata/empty_task/Taskfile.yml @@ -0,0 +1,4 @@ +version: '3' + +tasks: + default: