1
0
mirror of https://github.com/go-task/task.git synced 2025-06-13 00:07:29 +02:00

Task directory: test default case (no "dir:" attribute)

This commit is contained in:
Marco Molteni 2019-06-04 09:45:11 +02:00
parent 74537689dc
commit 81baf808c9
2 changed files with 26 additions and 0 deletions

View File

@ -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")
}

7
testdata/dir/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,7 @@
version: '2'
tasks:
whereami:
cmds:
- pwd
silent: true