Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the taskfile in include required #1902

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,35 @@ func TestIncludesInterpolation(t *testing.T) {
}
}

func TestIncludesMissingTaskfile(t *testing.T) {
const dir = "testdata/includes_missing_taskfile"
const error = "no taskfile is specified for include \"included\""

tests := []struct {
name string
task string
}{
{"inlined_taskfile_empty", "empty inline taskfile"},
{"inlined_taskfile_null", "null inline taskfile"},
{"taskfile_empty", "empty taskfile"},
{"taskfile_null", "null taskfile"},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
var buff bytes.Buffer
e := task.Executor{
Dir: filepath.Join(dir, test.name),
Stdout: &buff,
Stderr: &buff,
Silent: true,
}
err := e.Setup()
assert.ErrorContains(t, err, error)
})
}
}

func TestIncludedTaskfileVarMerging(t *testing.T) {
const dir = "testdata/included_taskfile_var_merging"
tests := []struct {
Expand Down
4 changes: 4 additions & 0 deletions taskfile/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (r *Reader) include(node Node) error {
return err
}

if include.Taskfile == "" {
return errors.New(fmt.Sprintf("no taskfile is specified for include %q", include.Namespace))
}

entrypoint, err := node.ResolveEntrypoint(include.Taskfile)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3'

includes:
included: ''

tasks:
task-1:
cmds:
- task: included:default
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
version: '3'

includes:
included:

tasks:
task-1:
cmds:
- task: included:default
10 changes: 10 additions & 0 deletions testdata/includes_missing_taskfile/taskfile_empty/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

includes:
included:
taskfile: ''

tasks:
task-1:
cmds:
- task: included:default
10 changes: 10 additions & 0 deletions testdata/includes_missing_taskfile/taskfile_null/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: '3'

includes:
included:
taskfile:

tasks:
task-1:
cmds:
- task: included:default
Loading