Skip to content

Commit fd64eb2

Browse files
committed
fix(ci): fix Windows test failures
- 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)
1 parent e129ae2 commit fd64eb2

File tree

6 files changed

+32
-17
lines changed

6 files changed

+32
-17
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,5 @@ jobs:
3131
env:
3232
GOPROXY: https://proxy.golang.org
3333

34-
- name: Build
35-
run: go build -o ./bin/task -v ./cmd/task
36-
3734
- name: Test
38-
run: ./bin/task test --output=group --output-group-begin='::group::{{.TASK}}' --output-group-end='::endgroup::'
35+
run: go run ./cmd/task test

errors/errors_taskfile.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package errors
33
import (
44
"fmt"
55
"net/http"
6+
"path/filepath"
67
"time"
78

89
"github.com/Masterminds/semver/v3"
@@ -24,7 +25,7 @@ func (err TaskfileNotFoundError) Error() string {
2425
if err.AskInit {
2526
walkText += " Run `task --init` to create a new Taskfile."
2627
}
27-
return fmt.Sprintf(`task: No Taskfile found at %q%s`, err.URI, walkText)
28+
return fmt.Sprintf(`task: No Taskfile found at %q%s`, filepath.ToSlash(err.URI), walkText)
2829
}
2930

3031
func (err TaskfileNotFoundError) Code() int {
@@ -51,7 +52,7 @@ type TaskfileInvalidError struct {
5152
}
5253

5354
func (err TaskfileInvalidError) Error() string {
54-
return fmt.Sprintf("task: Failed to parse %s:\n%v", err.URI, err.Err)
55+
return fmt.Sprintf("task: Failed to parse %s:\n%v", filepath.ToSlash(err.URI), err.Err)
5556
}
5657

5758
func (err TaskfileInvalidError) Code() int {
@@ -70,7 +71,7 @@ func (err TaskfileFetchFailedError) Error() string {
7071
if err.HTTPStatusCode != 0 {
7172
statusText = fmt.Sprintf(" with status code %d (%s)", err.HTTPStatusCode, http.StatusText(err.HTTPStatusCode))
7273
}
73-
return fmt.Sprintf(`task: Download of %q failed%s`, err.URI, statusText)
74+
return fmt.Sprintf(`task: Download of %q failed%s`, filepath.ToSlash(err.URI), statusText)
7475
}
7576

7677
func (err TaskfileFetchFailedError) Code() int {
@@ -86,7 +87,7 @@ type TaskfileNotTrustedError struct {
8687
func (err *TaskfileNotTrustedError) Error() string {
8788
return fmt.Sprintf(
8889
`task: Taskfile %q not trusted by user`,
89-
err.URI,
90+
filepath.ToSlash(err.URI),
9091
)
9192
}
9293

@@ -103,7 +104,7 @@ type TaskfileNotSecureError struct {
103104
func (err *TaskfileNotSecureError) Error() string {
104105
return fmt.Sprintf(
105106
`task: Taskfile %q cannot be downloaded over an insecure connection. You can override this by using the --insecure flag`,
106-
err.URI,
107+
filepath.ToSlash(err.URI),
107108
)
108109
}
109110

@@ -120,7 +121,7 @@ type TaskfileCacheNotFoundError struct {
120121
func (err *TaskfileCacheNotFoundError) Error() string {
121122
return fmt.Sprintf(
122123
`task: Taskfile %q was not found in the cache. Remove the --offline flag to use a remote copy or download it using the --download flag`,
123-
err.URI,
124+
filepath.ToSlash(err.URI),
124125
)
125126
}
126127

@@ -141,12 +142,12 @@ func (err *TaskfileVersionCheckError) Error() string {
141142
if err.SchemaVersion == nil {
142143
return fmt.Sprintf(
143144
`task: Missing schema version in Taskfile %q`,
144-
err.URI,
145+
filepath.ToSlash(err.URI),
145146
)
146147
}
147148
return fmt.Sprintf(
148149
"task: Invalid schema version in Taskfile %q:\nSchema version (%s) %s",
149-
err.URI,
150+
filepath.ToSlash(err.URI),
150151
err.SchemaVersion.String(),
151152
err.Message,
152153
)
@@ -166,7 +167,7 @@ type TaskfileNetworkTimeoutError struct {
166167
func (err *TaskfileNetworkTimeoutError) Error() string {
167168
return fmt.Sprintf(
168169
`task: Network connection timed out after %s while attempting to download Taskfile %q`,
169-
err.Timeout, err.URI,
170+
err.Timeout, filepath.ToSlash(err.URI),
170171
)
171172
}
172173

@@ -183,8 +184,8 @@ type TaskfileCycleError struct {
183184

184185
func (err TaskfileCycleError) Error() string {
185186
return fmt.Sprintf("task: include cycle detected between %s <--> %s",
186-
err.Source,
187-
err.Destination,
187+
filepath.ToSlash(err.Source),
188+
filepath.ToSlash(err.Destination),
188189
)
189190
}
190191

@@ -203,7 +204,7 @@ type TaskfileDoesNotMatchChecksum struct {
203204
func (err *TaskfileDoesNotMatchChecksum) Error() string {
204205
return fmt.Sprintf(
205206
"task: The checksum of the Taskfile at %q does not match!\ngot: %q\nwant: %q",
206-
err.URI,
207+
filepath.ToSlash(err.URI),
207208
err.ActualChecksum,
208209
err.ExpectedChecksum,
209210
)

executor_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ func (tt *ExecutorTest) run(t *testing.T) {
165165
// Create a golden fixture file for the output
166166
g := goldie.New(t,
167167
goldie.WithFixtureDir(filepath.Join(e.Dir, "testdata")),
168+
goldie.WithEqualFn(NormalizedEqual),
168169
)
169170

170171
// Call setup and check for errors

formatter_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ func (tt *FormatterTest) run(t *testing.T) {
127127
// Create a golden fixture file for the output
128128
g := goldie.New(t,
129129
goldie.WithFixtureDir(filepath.Join(e.Dir, "testdata")),
130+
goldie.WithEqualFn(NormalizedEqual),
130131
)
131132

132133
// Call setup and check for errors

internal/fingerprint/glob.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package fingerprint
22

33
import (
44
"os"
5+
"path/filepath"
56
"sort"
67

78
"github.com/go-task/task/v3/internal/execext"
@@ -50,7 +51,8 @@ func collectKeys(m map[string]bool) []string {
5051
keys := make([]string, 0, len(m))
5152
for k, v := range m {
5253
if v {
53-
keys = append(keys, k)
54+
// Normalize path separators for consistent sorting across platforms
55+
keys = append(keys, filepath.ToSlash(k))
5456
}
5557
}
5658
sort.Strings(keys)

task_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,19 @@ func PPSortedLines(t *testing.T, b []byte) []byte {
308308
return []byte(strings.Join(lines, "\n") + "\n")
309309
}
310310

311+
// normalizeLineEndings converts CRLF and CR to LF for cross-platform comparison
312+
func normalizeLineEndings(b []byte) []byte {
313+
b = bytes.ReplaceAll(b, []byte("\r\n"), []byte("\n"))
314+
b = bytes.ReplaceAll(b, []byte("\r"), []byte("\n"))
315+
return b
316+
}
317+
318+
// NormalizedEqual compares two byte slices after normalizing line endings.
319+
// This is used as a custom goldie.EqualFn for cross-platform golden file tests.
320+
func NormalizedEqual(actual, expected []byte) bool {
321+
return bytes.Equal(normalizeLineEndings(actual), normalizeLineEndings(expected))
322+
}
323+
311324
// SyncBuffer is a threadsafe buffer for testing.
312325
// Some times replace stdout/stderr with a buffer to capture output.
313326
// stdout and stderr are threadsafe, but a regular bytes.Buffer is not.

0 commit comments

Comments
 (0)