fix: Windows CI test failures and path normalization by vmaerten · Pull Request #2670 · go-task/task
vmaerten
changed the title
fix(ci): simplify test workflow to fix Windows execution
fix: Windows CI test failures and path normalization
vmaerten
marked this pull request as ready for review
- 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)
Use filepath.ToSlash() in test assertions to handle Windows backslashes: - TestIncludesOptionalImplicitFalse - TestIncludesOptionalExplicitFalse - TestIncludesRelativePath
- 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.
Add .gitattributes rule to ensure testdata files use LF line endings on all platforms, preventing checksum mismatches on Windows.
goldie's AssertWithTemplate doesn't respect the EqualFn option, so we manually handle template substitution and use NormalizedEqual directly for cross-platform comparison.
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.
Replace escaped backslashes (\\) before single backslashes to avoid creating double forward slashes (D://a//task//) in normalized output.
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}}`.
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
- 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
- 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
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters