From 5a285601770ae5f0471800db822602727b811c79 Mon Sep 17 00:00:00 2001 From: Andrey Nering Date: Sat, 13 Oct 2018 16:56:51 -0300 Subject: [PATCH] Write first test for including a Taskfile --- internal/taskfile/read/taskfile.go | 1 + task_test.go | 13 +++++++++++++ testdata/includes/.gitignore | 1 + testdata/includes/Taskfile.yml | 14 ++++++++++++++ testdata/includes/included/Taskfile.yml | 6 ++++++ 5 files changed, 35 insertions(+) create mode 100644 testdata/includes/.gitignore create mode 100644 testdata/includes/Taskfile.yml create mode 100644 testdata/includes/included/Taskfile.yml diff --git a/internal/taskfile/read/taskfile.go b/internal/taskfile/read/taskfile.go index dab897b9..a96e4a9e 100644 --- a/internal/taskfile/read/taskfile.go +++ b/internal/taskfile/read/taskfile.go @@ -23,6 +23,7 @@ func Taskfile(dir string) (*taskfile.Taskfile, error) { } for namespace, path := range t.Includes { + path = filepath.Join(dir, path) info, err := os.Stat(path) if err != nil { return nil, err diff --git a/task_test.go b/task_test.go index 58687cab..fef7302c 100644 --- a/task_test.go +++ b/task_test.go @@ -470,3 +470,16 @@ func TestDry(t *testing.T) { t.Errorf("File should not exist %s", file) } } + +func TestIncludes(t *testing.T) { + tt := fileContentTest{ + Dir: "testdata/includes", + Target: "default", + TrimSpace: true, + Files: map[string]string{ + "main.txt": "main", + "included.txt": "included", + }, + } + tt.Run(t) +} diff --git a/testdata/includes/.gitignore b/testdata/includes/.gitignore new file mode 100644 index 00000000..2211df63 --- /dev/null +++ b/testdata/includes/.gitignore @@ -0,0 +1 @@ +*.txt diff --git a/testdata/includes/Taskfile.yml b/testdata/includes/Taskfile.yml new file mode 100644 index 00000000..d4b44e51 --- /dev/null +++ b/testdata/includes/Taskfile.yml @@ -0,0 +1,14 @@ +version: '2' + +includes: + included: ./included + +tasks: + default: + cmds: + - task: gen + - task: included:gen + + gen: + cmds: + - echo main > main.txt diff --git a/testdata/includes/included/Taskfile.yml b/testdata/includes/included/Taskfile.yml new file mode 100644 index 00000000..f0d19639 --- /dev/null +++ b/testdata/includes/included/Taskfile.yml @@ -0,0 +1,6 @@ +version: '2' + +tasks: + gen: + cmds: + - echo included > included.txt