Skip to content

Commit 9c27344

Browse files
committed
normalize slashes
1 parent ea9cbe3 commit 9c27344

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

tests/cli_test.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,26 @@ func isCIEnvironment() bool {
178178
return os.Getenv("CI") != ""
179179
}
180180

181-
// sanitizeOutput replaces the absolute repository root path in the provided output
182-
// with the placeholder "/absolute/path/to/repo".
183-
// It returns an error if the repository root cannot be determined.
181+
// sanitizeOutput replaces occurrences of the repository's absolute path in the output
182+
// with the placeholder "/absolute/path/to/repo". It first normalizes both the repository root
183+
// and the output to use forward slashes, ensuring that the replacement works reliably.
184+
// An error is returned if the repository root cannot be determined.
184185
func sanitizeOutput(output string) (string, error) {
185-
repoRoot, err := findGitRepoRoot(startingDir)
186+
repoRoot, err := findGitRepoRoot()
186187
if err != nil {
187188
return "", err
188189
}
190+
189191
if repoRoot == "" {
190192
return "", errors.New("failed to determine repository root")
191193
}
192-
// Replace all instances of the repo root with the placeholder.
193-
return strings.ReplaceAll(output, repoRoot, "/absolute/path/to/repo"), nil
194+
// Normalize the repository root and output to use forward slashes.
195+
normalizedRepoRoot := filepath.ToSlash(repoRoot)
196+
normalizedOutput := filepath.ToSlash(output)
197+
198+
// Replace all occurrences of the normalized repository root with the placeholder.
199+
sanitized := strings.ReplaceAll(normalizedOutput, normalizedRepoRoot, "/absolute/path/to/repo")
200+
return sanitized, nil
194201
}
195202

196203
// sanitizeTestName converts t.Name() into a valid filename.

0 commit comments

Comments
 (0)