mirror of
https://github.com/jmcorgan/fips.git
synced 2026-07-22 07:48:26 +00:00
Fix snapshot-test CRLF mismatch on Windows runners
The control-query snapshot tests panicked on the Windows GitHub runner because git's default core.autocrlf=true converted fixture files (src/control/snapshots/*.json) to CRLF on checkout, while the in-memory JSON output is LF. trim_end() only strips trailing newlines, not interior \r, so every snapshot comparison mismatched. Two defenses: 1. .gitattributes: pin src/control/snapshots/*.json to text eol=lf so future Windows checkouts keep the fixtures LF-only regardless of local git config. 2. src/control/queries.rs (assert_snapshot): replace \r\n with \n in the expected text before comparison, so any future re-introduction of CRLF (a contributor with non-LF editor settings, a different runner, etc.) doesn't surface as a snapshot mismatch.
This commit is contained in:
5
.gitattributes
vendored
Normal file
5
.gitattributes
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Keep snapshot test fixtures LF-only across all platforms so that
|
||||||
|
# Windows checkouts with core.autocrlf=true don't convert them to CRLF
|
||||||
|
# (which would mismatch the actual JSON serialization output during
|
||||||
|
# snapshot comparison).
|
||||||
|
src/control/snapshots/*.json text eol=lf
|
||||||
@@ -1272,6 +1272,9 @@ mod tests {
|
|||||||
}
|
}
|
||||||
let expected = std::fs::read_to_string(&path)
|
let expected = std::fs::read_to_string(&path)
|
||||||
.unwrap_or_else(|e| panic!("failed to read snapshot {}: {e}", path.display()));
|
.unwrap_or_else(|e| panic!("failed to read snapshot {}: {e}", path.display()));
|
||||||
|
// Normalize line endings: Windows checkouts with core.autocrlf=true
|
||||||
|
// convert fixture files to CRLF; the in-memory JSON output is LF.
|
||||||
|
let expected = expected.replace("\r\n", "\n");
|
||||||
// Tolerate trailing newline differences from editors.
|
// Tolerate trailing newline differences from editors.
|
||||||
if expected.trim_end() != actual.trim_end() {
|
if expected.trim_end() != actual.trim_end() {
|
||||||
panic!(
|
panic!(
|
||||||
|
|||||||
Reference in New Issue
Block a user