-
-
Notifications
You must be signed in to change notification settings - Fork 782
fix: Windows CI test failures and path normalization #2670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
vmaerten
wants to merge
17
commits into
main
Choose a base branch
from
fix/ci-windows-tests
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+129
−46
Conversation
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
44f9c32 to
fd64eb2
Compare
- 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
5953b76 to
b8c5c89
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Fix Windows CI test failures that were previously undetected.
Context: Windows tests were somehow not running or being skipped, hiding multiple path-related issues.
Problems discovered:
D:\a\task\taskwere interpreted as escape sequences (\a→ bell,\t→ tab) when used in shell commandsSolution:
filepath.ToSlash()for all special variables (ROOT_DIR,TASK_DIR,USER_WORKING_DIR, etc.) to ensure consistent forward slashes on all platformsnormalizeOutput,normalizePathSeparators).gitattributesfor consistent checksumsTest plan
/)