Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Comment on lines +1808 to +1823
Copy link

Copilot AI Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test doesn’t currently assert that the root-level dotenv file was actually loaded/applied (the .env contents aren’t used anywhere), so it could pass even if readDotEnvFiles/root dotenv behavior regresses. Consider asserting a value sourced from the .env file (ideally with a unique var name unlikely to exist in the process environment) alongside CLI_ARGS, and update the expected output accordingly.

Copilot uses AI. Check for mistakes.
}

func TestExitImmediately(t *testing.T) {
t.Parallel()

Expand Down
1 change: 1 addition & 0 deletions testdata/dotenv/cli_args/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
FOO=bar
8 changes: 8 additions & 0 deletions testdata/dotenv/cli_args/Taskfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

dotenv: ['.env']

tasks:
default:
cmds:
- echo "args={{.CLI_ARGS}}"
Loading