diff --git a/task_test.go b/task_test.go index 3e98802c..85887265 100644 --- a/task_test.go +++ b/task_test.go @@ -594,3 +594,20 @@ func TestWhenNoDirAttributeItRunsInSameDirAsTaskfile(t *testing.T) { assert.Equal(t, expected, got, "Mismatch in the working directory") } +func TestWhenDirAttributeAndDirExistsItRunsInThatDir(t *testing.T) { + const expected = "exists" + const dir = "testdata/dir/explicit_exists" + 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 := strings.TrimSuffix(filepath.Base(out.String()), "\n") + assert.Equal(t, expected, got, "Mismatch in the working directory") +} + diff --git a/testdata/dir/explicit_exists/Taskfile.yml b/testdata/dir/explicit_exists/Taskfile.yml new file mode 100644 index 00000000..0ab53b26 --- /dev/null +++ b/testdata/dir/explicit_exists/Taskfile.yml @@ -0,0 +1,8 @@ +version: '2' + +tasks: + whereami: + dir: exists + cmds: + - pwd + silent: true diff --git a/testdata/dir/explicit_exists/exists/.keepme b/testdata/dir/explicit_exists/exists/.keepme new file mode 100644 index 00000000..e69de29b