pointfreeco / swift-snapshot-testing

📸 Delightful Swift snapshot testing.

Home Page:https://www.pointfree.co/episodes/ep41-a-tour-of-snapshot-testing

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

brianmichel opened this issue · comments

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

  • swift-snapshot-testing: 1.8.1
  • Xcode N/A
  • Swift: 5.11-dev
  • OS: Windows 11 Pro

Additional context
Add any more context about the problem here.

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

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 supabase/supabase-swift#184 which works, but is a bit annoying to keep in sync.