Skip to content

Commit

Permalink
normalize slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
osterman committed Feb 3, 2025
1 parent ea9cbe3 commit 9c27344
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions tests/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,19 +178,26 @@ func isCIEnvironment() bool {
return os.Getenv("CI") != ""
}

// sanitizeOutput replaces the absolute repository root path in the provided output
// with the placeholder "/absolute/path/to/repo".
// It returns an error if the repository root cannot be determined.
// sanitizeOutput replaces occurrences of the repository's absolute path in the output
// with the placeholder "/absolute/path/to/repo". It first normalizes both the repository root
// and the output to use forward slashes, ensuring that the replacement works reliably.
// An error is returned if the repository root cannot be determined.
func sanitizeOutput(output string) (string, error) {
repoRoot, err := findGitRepoRoot(startingDir)
repoRoot, err := findGitRepoRoot()

Check failure on line 186 in tests/cli_test.go

View workflow job for this annotation

GitHub Actions / Acceptance Tests (ubuntu-latest, linux)

not enough arguments in call to findGitRepoRoot

Check failure on line 186 in tests/cli_test.go

View workflow job for this annotation

GitHub Actions / Acceptance Tests (windows-latest, windows)

not enough arguments in call to findGitRepoRoot

Check failure on line 186 in tests/cli_test.go

View workflow job for this annotation

GitHub Actions / Acceptance Tests (macos-latest, macos)

not enough arguments in call to findGitRepoRoot
if err != nil {
return "", err
}

if repoRoot == "" {
return "", errors.New("failed to determine repository root")
}
// Replace all instances of the repo root with the placeholder.
return strings.ReplaceAll(output, repoRoot, "/absolute/path/to/repo"), nil
// Normalize the repository root and output to use forward slashes.
normalizedRepoRoot := filepath.ToSlash(repoRoot)
normalizedOutput := filepath.ToSlash(output)

// Replace all occurrences of the normalized repository root with the placeholder.
sanitized := strings.ReplaceAll(normalizedOutput, normalizedRepoRoot, "/absolute/path/to/repo")
return sanitized, nil
}

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

0 comments on commit 9c27344

Please sign in to comment.