Skip to content

Commit 8c0d6ea

Browse files
committed
not allow undeclared or empty taskfile in include
1 parent c4f708b commit 8c0d6ea

File tree

6 files changed

+71
-0
lines changed

6 files changed

+71
-0
lines changed

task_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1527,6 +1527,35 @@ func TestIncludesInterpolation(t *testing.T) {
15271527
}
15281528
}
15291529

1530+
func TestIncludesMissingTaskfile(t *testing.T) {
1531+
const dir = "testdata/includes_missing_taskfile"
1532+
const error = "no taskfile is specified for include \"included\""
1533+
1534+
tests := []struct {
1535+
name string
1536+
task string
1537+
}{
1538+
{"inlined_taskfile_empty", "empty inline taskfile"},
1539+
{"inlined_taskfile_null", "null inline taskfile"},
1540+
{"taskfile_empty", "empty taskfile"},
1541+
{"taskfile_null", "null taskfile"},
1542+
}
1543+
1544+
for _, test := range tests {
1545+
t.Run(test.name, func(t *testing.T) {
1546+
var buff bytes.Buffer
1547+
e := task.Executor{
1548+
Dir: filepath.Join(dir, test.name),
1549+
Stdout: &buff,
1550+
Stderr: &buff,
1551+
Silent: true,
1552+
}
1553+
err := e.Setup()
1554+
assert.ErrorContains(t, err, error)
1555+
})
1556+
}
1557+
}
1558+
15301559
func TestIncludedTaskfileVarMerging(t *testing.T) {
15311560
const dir = "testdata/included_taskfile_var_merging"
15321561
tests := []struct {

taskfile/reader.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ func (r *Reader) include(node Node) error {
121121
return err
122122
}
123123

124+
if include.Taskfile == "" {
125+
return errors.New(fmt.Sprintf("no taskfile is specified for include %q", include.Namespace))
126+
}
127+
124128
entrypoint, err := node.ResolveEntrypoint(include.Taskfile)
125129
if err != nil {
126130
return err
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3'
2+
3+
includes:
4+
included: ''
5+
6+
tasks:
7+
task-1:
8+
cmds:
9+
- task: included:default
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3'
2+
3+
includes:
4+
included:
5+
6+
tasks:
7+
task-1:
8+
cmds:
9+
- task: included:default
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
3+
includes:
4+
included:
5+
taskfile: ''
6+
7+
tasks:
8+
task-1:
9+
cmds:
10+
- task: included:default
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: '3'
2+
3+
includes:
4+
included:
5+
taskfile:
6+
7+
tasks:
8+
task-1:
9+
cmds:
10+
- task: included:default

0 commit comments

Comments
 (0)