1
0
mirror of https://github.com/go-task/task.git synced 2025-04-21 12:17:07 +02:00

Merge pull request #943 from go-task/fix-interpolation-in-includes

fix: interpolate includes taskfile and dir
This commit is contained in:
Andrey Nering 2022-12-05 20:54:04 -03:00 committed by GitHub
commit 4b4962e8c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 51 additions and 1 deletions

View File

@ -1059,6 +1059,40 @@ func TestIncludesInternal(t *testing.T) {
} }
} }
func TestIncludesInterpolation(t *testing.T) {
const dir = "testdata/includes_interpolation"
tests := []struct {
name string
task string
expectedErr bool
expectedOutput string
}{
{"include", "include", false, "includes_interpolation\n"},
{"include with dir", "include-with-dir", false, "included\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,
}
assert.NoError(t, e.Setup())
err := e.Run(context.Background(), taskfile.Call{Task: test.task})
if test.expectedErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.Equal(t, test.expectedOutput, buff.String())
})
}
}
func TestInternalTask(t *testing.T) { func TestInternalTask(t *testing.T) {
const dir = "testdata/internal_task" const dir = "testdata/internal_task"
tests := []struct { tests := []struct {

View File

@ -73,7 +73,7 @@ func Taskfile(readerNode *ReaderNode) (*taskfile.Taskfile, error) {
err = t.Includes.Range(func(namespace string, includedTask taskfile.IncludedTaskfile) error { err = t.Includes.Range(func(namespace string, includedTask taskfile.IncludedTaskfile) error {
if v >= 3.0 { if v >= 3.0 {
tr := templater.Templater{Vars: &taskfile.Vars{}, RemoveNoValue: true} tr := templater.Templater{Vars: t.Vars, RemoveNoValue: true}
includedTask = taskfile.IncludedTaskfile{ includedTask = taskfile.IncludedTaskfile{
Taskfile: tr.Replace(includedTask.Taskfile), Taskfile: tr.Replace(includedTask.Taskfile),
Dir: tr.Replace(includedTask.Dir), Dir: tr.Replace(includedTask.Dir),

View File

@ -0,0 +1,10 @@
version: "3"
vars:
MODULE_NAME: included
includes:
include: './{{.MODULE_NAME}}/Taskfile.yml'
include-with-dir:
taskfile: './{{.MODULE_NAME}}/Taskfile.yml'
dir: '{{.MODULE_NAME}}'

View File

@ -0,0 +1,6 @@
version: "3"
tasks:
default:
cmds:
- basename $(pwd)