mirror of
https://github.com/go-task/task.git
synced 2025-01-20 04:59:37 +02:00
fix: propagate include vars in multi-level includes (#1256)
This commit is contained in:
parent
2a0c99b5d8
commit
8a0689328b
23
task_test.go
23
task_test.go
@ -1798,6 +1798,29 @@ VAR_2 is included-default-var2
|
||||
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
|
||||
}
|
||||
|
||||
func TestIncludedVarsMultiLevel(t *testing.T) {
|
||||
const dir = "testdata/include_with_vars_multi_level"
|
||||
var buff bytes.Buffer
|
||||
e := task.Executor{
|
||||
Dir: dir,
|
||||
Stdout: &buff,
|
||||
Stderr: &buff,
|
||||
}
|
||||
require.NoError(t, e.Setup())
|
||||
|
||||
expectedOutputOrder := strings.TrimSpace(`
|
||||
task: [lib:greet] echo 'Hello world'
|
||||
Hello world
|
||||
task: [foo:lib:greet] echo 'Hello foo'
|
||||
Hello foo
|
||||
task: [bar:lib:greet] echo 'Hello bar'
|
||||
Hello bar
|
||||
`)
|
||||
require.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "default"}))
|
||||
t.Log(buff.String())
|
||||
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
|
||||
}
|
||||
|
||||
func TestErrorCode(t *testing.T) {
|
||||
const dir = "testdata/error_code"
|
||||
|
||||
|
@ -149,7 +149,10 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, string, error) {
|
||||
|
||||
for _, task := range includedTaskfile.Tasks.Values() {
|
||||
task.Dir = filepathext.SmartJoin(dir, task.Dir)
|
||||
task.IncludeVars = includedTask.Vars
|
||||
if task.IncludeVars == nil {
|
||||
task.IncludeVars = &taskfile.Vars{}
|
||||
}
|
||||
task.IncludeVars.Merge(includedTask.Vars)
|
||||
task.IncludedTaskfileVars = includedTaskfile.Vars
|
||||
task.IncludedTaskfile = &includedTask
|
||||
}
|
||||
|
17
testdata/include_with_vars_multi_level/Taskfile.yml
vendored
Normal file
17
testdata/include_with_vars_multi_level/Taskfile.yml
vendored
Normal file
@ -0,0 +1,17 @@
|
||||
version: "3"
|
||||
|
||||
includes:
|
||||
lib:
|
||||
taskfile: lib/Taskfile.yml
|
||||
internal: true
|
||||
foo:
|
||||
taskfile: foo/Taskfile.yml
|
||||
bar:
|
||||
taskfile: bar/Taskfile.yml
|
||||
|
||||
tasks:
|
||||
default:
|
||||
cmds:
|
||||
- task: lib:greet
|
||||
- task: foo:lib:greet
|
||||
- task: bar:lib:greet
|
7
testdata/include_with_vars_multi_level/bar/Taskfile.yml
vendored
Normal file
7
testdata/include_with_vars_multi_level/bar/Taskfile.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: "3"
|
||||
|
||||
includes:
|
||||
lib:
|
||||
taskfile: ../lib/Taskfile.yml
|
||||
vars:
|
||||
RECEIVER: "bar"
|
7
testdata/include_with_vars_multi_level/foo/Taskfile.yml
vendored
Normal file
7
testdata/include_with_vars_multi_level/foo/Taskfile.yml
vendored
Normal file
@ -0,0 +1,7 @@
|
||||
version: "3"
|
||||
|
||||
includes:
|
||||
lib:
|
||||
taskfile: ../lib/Taskfile.yml
|
||||
vars:
|
||||
RECEIVER: "foo"
|
9
testdata/include_with_vars_multi_level/lib/Taskfile.yml
vendored
Normal file
9
testdata/include_with_vars_multi_level/lib/Taskfile.yml
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
version: "3"
|
||||
|
||||
vars:
|
||||
RECEIVER: "world"
|
||||
|
||||
tasks:
|
||||
greet:
|
||||
cmds:
|
||||
- echo 'Hello {{.RECEIVER}}'
|
Loading…
x
Reference in New Issue
Block a user