mirror of
https://github.com/go-task/task.git
synced 2025-03-17 21:08:01 +02:00
fix: included variable merging (#1649)
This commit is contained in:
parent
8266b28b48
commit
725f929778
28
task_test.go
28
task_test.go
@ -1237,6 +1237,34 @@ func TestIncludesInterpolation(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestIncludedTaskfileVarMerging(t *testing.T) {
|
||||
const dir = "testdata/included_taskfile_var_merging"
|
||||
tests := []struct {
|
||||
name string
|
||||
task string
|
||||
expectedOutput string
|
||||
}{
|
||||
{"foo", "foo:pwd", "included_taskfile_var_merging/foo\n"},
|
||||
{"bar", "bar:pwd", "included_taskfile_var_merging/bar\n"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
Silent: true,
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
err := e.Run(context.Background(), &ast.Call{Task: test.task})
|
||||
require.NoError(t, err)
|
||||
assert.Contains(t, buff.String(), test.expectedOutput)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestInternalTask(t *testing.T) {
|
||||
const dir = "testdata/internal_task"
|
||||
tests := []struct {
|
||||
|
@ -90,7 +90,7 @@ func (t1 *Tasks) Merge(t2 Tasks, include *Include, includedTaskfileVars *Vars) {
|
||||
task.IncludeVars = &Vars{}
|
||||
}
|
||||
task.IncludeVars.Merge(include.Vars, nil)
|
||||
task.IncludedTaskfileVars = includedTaskfileVars
|
||||
task.IncludedTaskfileVars = includedTaskfileVars.DeepCopy()
|
||||
}
|
||||
|
||||
// Add the task to the merged taskfile
|
||||
|
12
testdata/included_taskfile_var_merging/Taskfile.yaml
vendored
Normal file
12
testdata/included_taskfile_var_merging/Taskfile.yaml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
version: "3"
|
||||
|
||||
includes:
|
||||
foo:
|
||||
taskfile: ./foo/Taskfile.yaml
|
||||
bar:
|
||||
taskfile: ./bar/Taskfile.yaml
|
||||
|
||||
tasks:
|
||||
stub:
|
||||
cmds:
|
||||
- echo 0
|
11
testdata/included_taskfile_var_merging/bar/Taskfile.yaml
vendored
Normal file
11
testdata/included_taskfile_var_merging/bar/Taskfile.yaml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
DIR: bar
|
||||
|
||||
tasks:
|
||||
pwd:
|
||||
dir: ./{{ .DIR }}
|
||||
cmds:
|
||||
- echo "{{ .DIR }}"
|
||||
- pwd
|
11
testdata/included_taskfile_var_merging/foo/Taskfile.yaml
vendored
Normal file
11
testdata/included_taskfile_var_merging/foo/Taskfile.yaml
vendored
Normal file
@ -0,0 +1,11 @@
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
DIR: foo
|
||||
|
||||
tasks:
|
||||
pwd:
|
||||
dir: ./{{ .DIR }}
|
||||
cmds:
|
||||
- echo "{{ .DIR }}"
|
||||
- pwd
|
Loading…
x
Reference in New Issue
Block a user