From 34c4963d455f56502275daeeed18a86c570fd737 Mon Sep 17 00:00:00 2001 From: pawciobiel Date: Tue, 24 Mar 2026 19:12:49 +0100 Subject: [PATCH] test(dotenv): add regression test for CLI_ARGS with root-level dotenv --- task_test.go | 21 +++++++++++++++++++++ testdata/dotenv/cli_args/.env | 1 + testdata/dotenv/cli_args/Taskfile.yml | 8 ++++++++ 3 files changed, 30 insertions(+) create mode 100644 testdata/dotenv/cli_args/.env create mode 100644 testdata/dotenv/cli_args/Taskfile.yml diff --git a/task_test.go b/task_test.go index 9d54af9740..92e5e99e02 100644 --- a/task_test.go +++ b/task_test.go @@ -1802,6 +1802,27 @@ func TestTaskDotenvWithVarName(t *testing.T) { }) } +func TestDotenvWithCLIArgs(t *testing.T) { + t.Parallel() + + var buff bytes.Buffer + e := task.NewExecutor( + task.WithDir("testdata/dotenv/cli_args"), + task.WithStdout(&buff), + task.WithStderr(&buff), + task.WithSilent(true), + ) + require.NoError(t, e.Setup()) + + specialVars := ast.NewVars() + specialVars.Set("CLI_ARGS", ast.Var{Value: "hello world"}) + e.Taskfile.Vars.ReverseMerge(specialVars, nil) + + err := e.Run(t.Context(), &task.Call{Task: "default"}) + require.NoError(t, err) + assert.Equal(t, "args=hello world\n", buff.String()) +} + func TestExitImmediately(t *testing.T) { t.Parallel() diff --git a/testdata/dotenv/cli_args/.env b/testdata/dotenv/cli_args/.env new file mode 100644 index 0000000000..c075a74be9 --- /dev/null +++ b/testdata/dotenv/cli_args/.env @@ -0,0 +1 @@ +FOO=bar diff --git a/testdata/dotenv/cli_args/Taskfile.yml b/testdata/dotenv/cli_args/Taskfile.yml new file mode 100644 index 0000000000..58cd7b5828 --- /dev/null +++ b/testdata/dotenv/cli_args/Taskfile.yml @@ -0,0 +1,8 @@ +version: '3' + +dotenv: ['.env'] + +tasks: + default: + cmds: + - echo "args={{.CLI_ARGS}}"