The test proved that normalizing only in tests is not sufficient.
The production code must use forward slashes to:
1. Prevent escape sequence issues (\a, \t interpreted as bell, tab)
2. Ensure consistent behavior across platforms
3. Allow portable Taskfiles that work on all OSes
- Rename normalizeLineEndings to normalizeOutput (clearer name)
- Add normalizePathSeparators helper for string path normalization
- Replace inline strings.ReplaceAll patterns with helper function
- Add unit tests for both normalization functions
- TestUserWorkingDirectoryWithIncluded: normalize actual output instead
of just expected, since task outputs backslashes on Windows
- TestDynamicVariablesRunOnTheNewCreatedDir: take first line only, as
Windows may output additional corrupted path info
- Disable fail-fast in CI to see all test failures at once
On Windows, paths returned by pwd or filepath operations use
backslashes which get interpreted as escape sequences when
printed. This caused tests to fail with corrupted path output.
Fix by normalizing path separators before comparison:
- TestWhenNoDirAttributeItRunsInSameDirAsTaskfile
- TestWhenDirAttributeAndDirExistsItRunsInThatDir
- TestWhenDirAttributeItCreatesMissingAndRunsInThatDir
- TestDynamicVariablesRunOnTheNewCreatedDir
- TestUserWorkingDirectory
- TestUserWorkingDirectoryWithIncluded
Use filepath.ToSlash() for ROOT_DIR, ROOT_TASKFILE, USER_WORKING_DIR,
TASK_DIR, TASKFILE, and TASKFILE_DIR to ensure consistent forward
slashes across platforms.
This fixes an issue on Windows where backslashes in paths were being
interpreted as escape sequences when used in shell commands like
`echo {{.ROOT_DIR}}`.
Instead of manually handling template substitution, normalize the output
before passing it to AssertWithTemplate. This keeps goldie's features
(diff, -update flag) intact while ensuring cross-platform compatibility.
goldie's AssertWithTemplate doesn't respect the EqualFn option, so we
manually handle template substitution and use NormalizedEqual directly
for cross-platform comparison.
- Extend normalizeLineEndings to convert backslashes to forward slashes
- Normalize TEST_DIR with filepath.ToSlash() for template data
- Fix TestIncludedTaskfileVarMerging assertion to use filepath.ToSlash()
This fixes golden file tests on Windows where paths contain backslashes.
Use filepath.ToSlash() in test assertions to handle Windows backslashes:
- TestIncludesOptionalImplicitFalse
- TestIncludesOptionalExplicitFalse
- TestIncludesRelativePath
- Normalize paths to forward slashes in glob.go for consistent sorting
- Use filepath.ToSlash in error messages to avoid double-escaped backslashes
- Add goldie.WithEqualFn for cross-platform line ending normalization
- Simplify CI workflow (go run ./cmd/task test)
Move the prompt for required variables AFTER the if condition check.
This avoids asking the user for input when the task won't run anyway.
The order in RunTask() is now:
1. FastCompiledTask
2. Check required vars early (non-interactive mode only)
3. CompiledTask (resolve dynamic vars)
4. Check if condition → exit early if false
5. Prompt for missing vars (only if task will run)
6. Validate required vars