Skip to content
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
19 changes: 19 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1082,6 +1082,25 @@ func TestIncludesIncorrect(t *testing.T) {
assert.Contains(t, err.Error(), "Failed to parse testdata/includes_incorrect/incomplete.yml:", err.Error())
}

func TestIncludesMissingTaskfile(t *testing.T) {
t.Parallel()

const dir = "testdata/includes_missing_taskfile"

var buff bytes.Buffer
e := task.NewExecutor(
task.WithDir(dir),
task.WithStdout(&buff),
task.WithStderr(&buff),
task.WithSilent(true),
)

err := e.Setup()
require.Error(t, err)
assert.Contains(t, err.Error(), "include must specify taskfile or dir")
assert.NotContains(t, err.Error(), "include cycle detected")
}

func TestIncludesEmptyMain(t *testing.T) {
t.Parallel()

Expand Down
4 changes: 4 additions & 0 deletions taskfile/ast/include.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ast

import (
"iter"
"strings"
"sync"

"github.com/elliotchance/orderedmap/v3"
Expand Down Expand Up @@ -171,6 +172,9 @@ func (include *Include) UnmarshalYAML(node *yaml.Node) error {
if err := node.Decode(&includedTaskfile); err != nil {
return errors.NewTaskfileDecodeError(err, node)
}
if strings.TrimSpace(includedTaskfile.Taskfile) == "" && strings.TrimSpace(includedTaskfile.Dir) == "" {
return errors.NewTaskfileDecodeError(nil, node).WithMessage("include must specify taskfile or dir")
}
include.Taskfile = includedTaskfile.Taskfile
include.Dir = includedTaskfile.Dir
include.Optional = includedTaskfile.Optional
Expand Down
5 changes: 5 additions & 0 deletions testdata/includes_missing_taskfile/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: '3'

includes:
GOBIN:
sh: echo $(go env GOPATH)/bin