Skip to content

Commit d78f78b

Browse files
Fix panic for empty tasks
Closes #338 Closes #362 Co-authored-by: Bharath Kumar <[email protected]>
1 parent ce4ac97 commit d78f78b

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Unreleased
4+
5+
- Fix panic when you have empty tasks in your Taskfile
6+
([#338](https://github.com/go-task/task/issues/338), [#362](https://github.com/go-task/task/pull/362)).
7+
38
## v3.0.0
49

510
- On `v3`, all CLI variables will be considered global variables

task_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ func (fct fileContentTest) Run(t *testing.T) {
5656
}
5757
}
5858

59+
func TestEmptyTask(t *testing.T) {
60+
e := &task.Executor{
61+
Dir: "testdata/empty_task",
62+
Stdout: ioutil.Discard,
63+
Stderr: ioutil.Discard,
64+
}
65+
assert.NoError(t, e.Setup(), "e.Setup()")
66+
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
67+
}
68+
5969
func TestEnv(t *testing.T) {
6070
tt := fileContentTest{
6171
Dir: "testdata/env",

taskfile/read/taskfile.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ func Taskfile(dir string, entrypoint string) (*taskfile.Taskfile, error) {
119119
}
120120

121121
for name, task := range t.Tasks {
122+
if task == nil {
123+
task = &taskfile.Task{}
124+
t.Tasks[name] = task
125+
}
122126
task.Task = name
123127
}
124128

testdata/empty_task/Taskfile.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
version: '3'
2+
3+
tasks:
4+
default:

0 commit comments

Comments
 (0)