1
0
mirror of https://github.com/go-task/task.git synced 2024-12-04 10:24:45 +02:00

test include variables

This commit is contained in:
Dan Ballweg 2022-02-24 13:17:20 -06:00
parent 292cf75836
commit 2f18f7927d
3 changed files with 60 additions and 0 deletions

View File

@ -1218,3 +1218,32 @@ Bye!
t.Log(buff.String())
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
}
func TestIncludedVars(t *testing.T) {
const dir = "testdata/include_with_vars"
var buff bytes.Buffer
e := task.Executor{
Dir: dir,
Stdout: &buff,
Stderr: &buff,
}
assert.NoError(t, e.Setup())
expectedOutputOrder := strings.TrimSpace(`
task: [included1:task1] echo "VAR_1 is included1-var1"
VAR_1 is included1-var1
task: [included1:task1] echo "VAR_2 is incldued-default-var2"
VAR_2 is incldued-default-var2
task: [included2:task1] echo "VAR_1 is included2-var1"
VAR_1 is included2-var1
task: [included2:task1] echo "VAR_2 is incldued-default-var2"
VAR_2 is incldued-default-var2
task: [included3:task1] echo "VAR_1 is included-default-var1"
VAR_1 is included-default-var1
task: [included3:task1] echo "VAR_2 is incldued-default-var2"
VAR_2 is incldued-default-var2
`)
assert.NoError(t, e.Run(context.Background(), taskfile.Call{Task: "task1"}))
t.Log(buff.String())
assert.Equal(t, strings.TrimSpace(buff.String()), expectedOutputOrder)
}

20
testdata/include_with_vars/Taskfile.yml vendored Normal file
View File

@ -0,0 +1,20 @@
version: "3"
includes:
included1:
taskfile: include/Taskfile.include.yml
vars:
VAR_1: included1-var1
included2:
taskfile: include/Taskfile.include.yml
vars:
VAR_1: included2-var1
included3:
taskfile: include/Taskfile.include.yml
tasks:
task1:
cmds:
- task: included1:task1
- task: included2:task1
- task: included3:task1

View File

@ -0,0 +1,11 @@
version: "3"
vars:
VAR_1: included-default-var1
VAR_2: incldued-default-var2
tasks:
task1:
cmds:
- echo "VAR_1 is {{.VAR_1}}"
- echo "VAR_2 is {{.VAR_2}}"