From f4bf6854001adad0a30878ff90d15e0659fca2e4 Mon Sep 17 00:00:00 2001 From: Jon Zeolla Date: Mon, 9 Mar 2026 05:37:10 -0400 Subject: [PATCH] test: add coverage for sh: vars with included Taskfiles Add TestShVarWithIncludes to ensure sh: dynamic variables are correctly resolved when a Taskfile also has includes. This guards against regressions like the one fixed in v3.49.1 (#2720, #2721). Co-Authored-By: Claude Opus 4.6 --- executor_test.go | 26 +++++++++++++++++++ testdata/var_sh_with_includes/Included.yml | 6 +++++ testdata/var_sh_with_includes/Taskfile.yml | 18 +++++++++++++ ...es-sh_var_not_clobbered_by_includes.golden | 2 ++ 4 files changed, 52 insertions(+) create mode 100644 testdata/var_sh_with_includes/Included.yml create mode 100644 testdata/var_sh_with_includes/Taskfile.yml create mode 100644 testdata/var_sh_with_includes/testdata/TestShVarWithIncludes-sh_var_not_clobbered_by_includes.golden diff --git a/executor_test.go b/executor_test.go index 6e3ff3e1ec..9e9bfe2c52 100644 --- a/executor_test.go +++ b/executor_test.go @@ -942,6 +942,32 @@ func TestReference(t *testing.T) { } } +func TestShVarWithIncludes(t *testing.T) { + t.Parallel() + + tests := []struct { + name string + call string + }{ + { + name: "sh var not clobbered by includes", + call: "default", + }, + } + + for _, test := range tests { + NewExecutorTest(t, + WithName(test.name), + WithExecutorOptions( + task.WithDir("testdata/var_sh_with_includes"), + task.WithSilent(true), + task.WithForce(true), + ), + WithTask(cmp.Or(test.call, "default")), + ) + } +} + func TestVarInheritance(t *testing.T) { enableExperimentForTest(t, &experiments.EnvPrecedence, 1) tests := []struct { diff --git a/testdata/var_sh_with_includes/Included.yml b/testdata/var_sh_with_includes/Included.yml new file mode 100644 index 0000000000..9c0f4e437a --- /dev/null +++ b/testdata/var_sh_with_includes/Included.yml @@ -0,0 +1,6 @@ +version: '3' + +tasks: + noop: + cmds: + - "true" diff --git a/testdata/var_sh_with_includes/Taskfile.yml b/testdata/var_sh_with_includes/Taskfile.yml new file mode 100644 index 0000000000..7e3bf197dc --- /dev/null +++ b/testdata/var_sh_with_includes/Taskfile.yml @@ -0,0 +1,18 @@ +version: '3' + +includes: + other: + taskfile: ./Included.yml + internal: true + +vars: + DYNAMIC_VAR: + sh: echo "hello" + DERIVED_VAR: "{{.DYNAMIC_VAR}} world" + +tasks: + default: + cmds: + - echo "DYNAMIC_VAR={{.DYNAMIC_VAR}}" + - echo "DERIVED_VAR={{.DERIVED_VAR}}" + silent: true diff --git a/testdata/var_sh_with_includes/testdata/TestShVarWithIncludes-sh_var_not_clobbered_by_includes.golden b/testdata/var_sh_with_includes/testdata/TestShVarWithIncludes-sh_var_not_clobbered_by_includes.golden new file mode 100644 index 0000000000..066c073193 --- /dev/null +++ b/testdata/var_sh_with_includes/testdata/TestShVarWithIncludes-sh_var_not_clobbered_by_includes.golden @@ -0,0 +1,2 @@ +DYNAMIC_VAR=hello +DERIVED_VAR=hello world