From 81baf808c9a7bd8bb68ecbec9742c37615acb43c Mon Sep 17 00:00:00 2001 From: Marco Molteni Date: Tue, 4 Jun 2019 09:45:11 +0200 Subject: [PATCH] Task directory: test default case (no "dir:" attribute) --- task_test.go | 19 +++++++++++++++++++ testdata/dir/Taskfile.yml | 7 +++++++ 2 files changed, 26 insertions(+) create mode 100644 testdata/dir/Taskfile.yml diff --git a/task_test.go b/task_test.go index 0006b674..3e98802c 100644 --- a/task_test.go +++ b/task_test.go @@ -575,3 +575,22 @@ func readTestFixture(t *testing.T, dir string, file string) string { assert.NoError(t, err, "error reading text fixture") return string(b) } + +func TestWhenNoDirAttributeItRunsInSameDirAsTaskfile(t *testing.T) { + const expected = "dir" + const dir = "testdata/" + expected + var out bytes.Buffer + e := &task.Executor{ + Dir: dir, + Stdout: &out, + Stderr: &out, + } + + assert.NoError(t, e.Setup()) + assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "whereami"})) + + // got should be the "dir" part of "testdata/dir" + got := strings.TrimSuffix(filepath.Base(out.String()), "\n") + assert.Equal(t, expected, got, "Mismatch in the working directory") +} + diff --git a/testdata/dir/Taskfile.yml b/testdata/dir/Taskfile.yml new file mode 100644 index 00000000..f17dd9fe --- /dev/null +++ b/testdata/dir/Taskfile.yml @@ -0,0 +1,7 @@ +version: '2' + +tasks: + whereami: + cmds: + - pwd + silent: true