From c96e32cdd27e96db06855acf8cbb4dc7acb4e3d5 Mon Sep 17 00:00:00 2001 From: Valentin Maerten Date: Sat, 31 Jan 2026 10:24:16 +0100 Subject: [PATCH] fix(tests): normalize path separators in golden file 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. --- task_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/task_test.go b/task_test.go index 71a0182e..a98d781c 100644 --- a/task_test.go +++ b/task_test.go @@ -88,7 +88,7 @@ func (tt *TaskTest) writeFixture( if tt.fixtureTemplatingEnabled { fixtureTemplateData := map[string]any{ "TEST_NAME": t.Name(), - "TEST_DIR": wd, + "TEST_DIR": filepath.ToSlash(wd), } // If the test has additional template data, copy it into the map if tt.fixtureTemplateData != nil { @@ -308,10 +308,13 @@ func PPSortedLines(t *testing.T, b []byte) []byte { return []byte(strings.Join(lines, "\n") + "\n") } -// normalizeLineEndings converts CRLF and CR to LF for cross-platform comparison +// normalizeLineEndings normalizes cross-platform differences for comparison: +// - Converts CRLF and CR to LF +// - Converts backslashes to forward slashes (Windows paths) func normalizeLineEndings(b []byte) []byte { b = bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n")) b = bytes.ReplaceAll(b, []byte("\r"), []byte("\n")) + b = bytes.ReplaceAll(b, []byte("\\"), []byte("/")) return b } @@ -1341,7 +1344,7 @@ func TestIncludedTaskfileVarMerging(t *testing.T) { err := e.Run(t.Context(), &task.Call{Task: test.task}) require.NoError(t, err) - assert.Contains(t, buff.String(), test.expectedOutput) + assert.Contains(t, filepath.ToSlash(buff.String()), test.expectedOutput) }) } }