pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.
https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing
MIT License
3.68k stars 556 forks source link

Text-based snapshots break across platforms due to line ending differences #815

Open brianmichel opened 7 months ago

brianmichel commented 7 months ago

Describe the bug When generating snapshots for text-based snapshots they are encoded with whatever the recording platform's line ending format is. When attempting to reuse these snapshots on a different platform that uses a different line-ending format the snapshots will fail to validate.

To Reproduce Zip up a project that reproduces the behavior and attach it by dragging it here.

// And/or enter code that reproduces the behavior here.

Expected behavior I would expect to have these line endings somehow ignored across platforms, or otherwise adaptable across multiple platforms in which Swift run on.

Screenshots If applicable, add screenshots to help explain your problem.

Environment

Additional context Add any more context about the problem here.

brianmichel commented 7 months ago

Actually, this looks like text snapshots are written with LF endings even on Windows so I think my issue is elsewhere!

brianmichel commented 7 months ago

Looking into this more, this does seem like an actual problem. Here's a sample repo with a basic text snapshot that I generated on macOS and I have CI running on Windows & macOS. You can see that the Windows run fails by saying the whole file is different when the text looks the same, this is due to different line endings. https://github.com/brianmichel/swift-snapshot-line-endings/actions/runs/7241742160/job/19726194879

I believe this is he correct toolchain behavior (using crlf on Windows), I wonder if some kind of additional ignoreLineEndings flag could be useful to allow some slack in comparing these tests.

This will mean that projects which use this snapshot testing tool in their cross platform library/app will have to have two complete sets of saved snapshots; one set with lf line endings, one set with crlf line endings. Which is the approach I've taken here https://github.com/supabase-community/supabase-swift/pull/184 which works, but is a bit annoying to keep in sync.