mirror of
https://github.com/go-task/task.git
synced 2025-02-03 13:22:11 +02:00
fix: getSpecialVars
This commit is contained in:
parent
e734e29009
commit
d2522a6d9d
55
task_test.go
55
task_test.go
@ -108,37 +108,42 @@ func TestVars(t *testing.T) {
|
||||
|
||||
func TestSpecialVars(t *testing.T) {
|
||||
const dir = "testdata/special_vars"
|
||||
const target = "default"
|
||||
|
||||
var buff bytes.Buffer
|
||||
e := &task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
require.NoError(t, e.Run(context.Background(), ast.Call{Task: target}))
|
||||
|
||||
toAbs := func(rel string) string {
|
||||
abs, err := filepath.Abs(rel)
|
||||
require.NoError(t, err)
|
||||
assert.NoError(t, err)
|
||||
return abs
|
||||
}
|
||||
|
||||
output := buff.String()
|
||||
tests := []struct {
|
||||
target string
|
||||
expected string
|
||||
}{
|
||||
// Root
|
||||
{target: "print-task", expected: "print-task"},
|
||||
{target: "print-root-dir", expected: toAbs(dir)},
|
||||
{target: "print-taskfile-dir", expected: toAbs(dir)},
|
||||
{target: "print-task-version", expected: "unknown"},
|
||||
// Included
|
||||
{target: "included:print-task", expected: "included:print-task"},
|
||||
{target: "included:print-root-dir", expected: toAbs(dir)},
|
||||
{target: "included:print-taskfile-dir", expected: toAbs(dir) + "/included"},
|
||||
{target: "included:print-task-version", expected: "unknown"},
|
||||
}
|
||||
|
||||
// Root Taskfile
|
||||
assert.Contains(t, output, "root/TASK=print")
|
||||
assert.Contains(t, output, "root/ROOT_DIR="+toAbs("testdata/special_vars"))
|
||||
assert.Contains(t, output, "root/TASKFILE_DIR="+toAbs("testdata/special_vars"))
|
||||
assert.Contains(t, output, "root/TASK_VERSION=unknown")
|
||||
|
||||
// Included Taskfile
|
||||
assert.Contains(t, output, "included/TASK=included:print")
|
||||
assert.Contains(t, output, "included/ROOT_DIR="+toAbs("testdata/special_vars"))
|
||||
assert.Contains(t, output, "included/TASKFILE_DIR="+toAbs("testdata/special_vars/included"))
|
||||
assert.Contains(t, output, "included/TASK_VERSION=unknown")
|
||||
for _, test := range tests {
|
||||
t.Run(test.target, func(t *testing.T) {
|
||||
var buff bytes.Buffer
|
||||
e := &task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
require.NoError(t, e.Run(context.Background(), ast.Call{Task: test.target}))
|
||||
assert.Equal(t, test.expected+"\n", buff.String())
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestConcurrency(t *testing.T) {
|
||||
|
15
testdata/special_vars/Taskfile.yml
vendored
15
testdata/special_vars/Taskfile.yml
vendored
@ -6,14 +6,7 @@ includes:
|
||||
dir: ./included
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- task: print
|
||||
- task: included:print
|
||||
|
||||
print:
|
||||
cmds:
|
||||
- echo root/TASK={{.TASK}}
|
||||
- echo root/ROOT_DIR={{.ROOT_DIR}}
|
||||
- echo root/TASKFILE_DIR={{.TASKFILE_DIR}}
|
||||
- echo root/TASK_VERSION={{.TASK_VERSION}}
|
||||
print-task: echo {{.TASK}}
|
||||
print-root-dir: echo {{.ROOT_DIR}}
|
||||
print-taskfile-dir: echo {{.TASKFILE_DIR}}
|
||||
print-task-version: echo {{.TASK_VERSION}}
|
||||
|
10
testdata/special_vars/included/Taskfile.yml
vendored
10
testdata/special_vars/included/Taskfile.yml
vendored
@ -1,9 +1,7 @@
|
||||
version: '3'
|
||||
|
||||
tasks:
|
||||
print:
|
||||
cmds:
|
||||
- echo included/TASK={{.TASK}}
|
||||
- echo included/ROOT_DIR={{.ROOT_DIR}}
|
||||
- echo included/TASKFILE_DIR={{.TASKFILE_DIR}}
|
||||
- echo included/TASK_VERSION={{.TASK_VERSION}}
|
||||
print-task: echo {{.TASK}}
|
||||
print-root-dir: echo {{.ROOT_DIR}}
|
||||
print-taskfile-dir: echo {{.TASKFILE_DIR}}
|
||||
print-task-version: echo {{.TASK_VERSION}}
|
||||
|
Loading…
x
Reference in New Issue
Block a user