mirror of
https://github.com/go-task/task.git
synced 2025-08-10 22:42:19 +02:00
Run Taskfiles from sub/child directories (#920)
This commit is contained in:
49
task_test.go
49
task_test.go
@@ -1703,3 +1703,52 @@ Hello, World!
|
||||
err = os.RemoveAll(filepathext.SmartJoin(dir, "src"))
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestTaskfileWalk(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
dir string
|
||||
expected string
|
||||
}{
|
||||
{
|
||||
name: "walk from root directory",
|
||||
dir: "testdata/taskfile_walk",
|
||||
expected: "foo\n",
|
||||
}, {
|
||||
name: "walk from sub directory",
|
||||
dir: "testdata/taskfile_walk/foo",
|
||||
expected: "foo\n",
|
||||
}, {
|
||||
name: "walk from sub sub directory",
|
||||
dir: "testdata/taskfile_walk/foo/bar",
|
||||
expected: "foo\n",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: test.dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
|
||||
assert.Equal(t, test.expected, buff.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserWorkingDirectory(t *testing.T) {
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: "testdata/user_working_dir",
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
wd, err := os.Getwd()
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, e.Setup())
|
||||
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
|
||||
assert.Equal(t, fmt.Sprintf("%s\n", wd), buff.String())
|
||||
}
|
||||
|
Reference in New Issue
Block a user