Skip to content

Commit b9760a0

Browse files
unhappychoiceclaude
andcommitted
fix(install/rc): handle CRLF in source_line trim for Windows CI
Windows CI checks the snippet file out with git autocrlf, so `include_str!` returns `^splashboard\r\n` rather than `^splashboard\n`. `trim_end_matches('\n')` then left a stray `\r` between the snippet and the close marker. Trim both characters, and rewrite the assertion in terms of `str::lines()` so it doesn't care which line ending the checkout produced. Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
1 parent c7a8051 commit b9760a0

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

‎src/install/rc.rs‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,15 @@ fn find_block(contents: &str) -> Option<(usize, usize)> {
154154
}
155155

156156
fn format_block(shell: Shell) -> String {
157-
// `trim_end_matches('\n')` keeps spacing consistent for shells whose source_line is
158-
// a single inline command (no trailing newline) and the Nushell case where it's the
159-
// full snippet from `include_str!` (always terminated with `\n`) — without trimming
160-
// the latter would leave a blank line before the close marker.
157+
// Trim both `\n` and `\r` so the spacing stays consistent for shells whose source_line
158+
// is a single inline command (no trailing newline) and the Nushell case where it's the
159+
// full snippet from `include_str!` (always terminated with `\n`, plus a `\r` on Windows
160+
// CI where git autocrlf converts the snippet file). Without this the close marker ends
161+
// up on its own line below a blank one.
161162
format!(
162163
"{open}\n# Added by `splashboard install`. Safe to remove.\n{line}\n{close}\n",
163164
open = MARKER_OPEN,
164-
line = shell::source_line(shell).trim_end_matches('\n'),
165+
line = shell::source_line(shell).trim_end_matches(['\n', '\r']),
165166
close = MARKER_CLOSE,
166167
)
167168
}
@@ -268,9 +269,16 @@ trailing\n"
268269
assert!(contents.contains("env_change.PWD"));
269270
assert!(contents.contains("^splashboard"));
270271
assert_eq!(contents.matches(MARKER_OPEN).count(), 1);
271-
// No blank line between the last snippet line and the close marker — the snippet
272-
// is sourced from a file that always ends in `\n`, so format_block must trim it.
273-
assert!(contents.contains(&format!("^splashboard\n{MARKER_CLOSE}")));
272+
// No blank line between the last snippet line and the close marker. Uses
273+
// `str::lines()` so the assertion works regardless of `\n` vs `\r\n` (Windows CI
274+
// under git autocrlf converts the snippet file).
275+
let lines: Vec<&str> = contents.lines().collect();
276+
let close_idx = lines.iter().position(|l| l == &MARKER_CLOSE).unwrap();
277+
assert_eq!(
278+
lines[close_idx - 1],
279+
"^splashboard",
280+
"expected `^splashboard` immediately before close marker, lines: {lines:?}"
281+
);
274282

275283
let up_to_date = wire_shell_rc(Shell::Nushell, Some(rc.clone())).unwrap();
276284
assert_eq!(up_to_date.action, RcAction::UpToDate);

0 commit comments

Comments
 (0)