test(dotenv): add regression test for CLI_ARGS with root-level dotenv#2763
test(dotenv): add regression test for CLI_ARGS with root-level dotenv#2763pawciobiel wants to merge 1 commit intogo-task:mainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Adds a regression test ensuring CLI_ARGS remains available for templating when a Taskfile declares a root-level dotenv.
Changes:
- Added a new test fixture Taskfile that declares
dotenv: ['.env']and echoes{{.CLI_ARGS}}. - Added a corresponding
.envfixture file for the root-level dotenv declaration. - Added
TestDotenvWithCLIArgsintask_test.goto validate output whenCLI_ARGSis set.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| testdata/dotenv/cli_args/Taskfile.yml | New fixture Taskfile enabling root-level dotenv and exercising {{.CLI_ARGS}} templating. |
| testdata/dotenv/cli_args/.env | New fixture dotenv file used by the Taskfile. |
| task_test.go | New regression test that runs the fixture and asserts the rendered CLI_ARGS output. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| 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()) |
There was a problem hiding this comment.
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.
No description provided.