Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
brianmichel opened this issue Dec 10, 2023 · 2 comments

Comments

@brianmichel
Copy link

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.

@brianmichel
Copy link
Author

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

@brianmichel
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant