-
-
Notifications
You must be signed in to change notification settings - Fork 101
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
Enforce starting newlines #563
base: master
Are you sure you want to change the base?
Conversation
This will make diffs in mitsuhiko#563 more reasonable (Though it was good to have some snapshots that _weren't_ updated, as meta-tests that un-updated snapshots still worked -- possibly we try and add an integration test in that direction...)
This will make diffs in #563 more reasonable (Though it was good to have some snapshots that _weren't_ updated, as meta-tests that un-updated snapshots still worked -- possibly we try and add an integration test in that direction...)
We previously excluded these. But it's somewhat required for mitsuhiko#563, and I don't think there's a big downside -- we only generate pending files when a snapshot doesn't match of `--force-update-snapshots` is passed.
Moving some unambiguous code from mitsuhiko#563 into a new PR so we can keep moving
Another PR taking some unambiguous code from mitsuhiko#563
Moving some unambiguous code from #563 into a new PR so we can keep moving
Another PR taking some unambiguous code from #563
#581) This solves the issue in #573 for the moment: - When `--force-update-snapshots` in passed, we only update inline snapshots when there's some difference _within_ the string, such as an additional linebreak at the start or the end - We no longer update the surrounding hashes. In the existing code, this happened because we were writing too many inline snapshots, not because we were actually checking the number of hashes - Checking the number of hashes isn't easy to do — reason outlined at #573 (comment) - The main change in the code is that we store the unnormalized snapshot and then normalize when we need to. The existing code stored the normalized version, which meant we couldn't evaluate whether the unnormalized versions were different It's a decent number of changes, but will integrate nicely with #563. ~(FYI we currently don't look at the indentation, but we could adjust this)~ Now indentation works too
One downside (but balanced against lots of upsides!) is that because we insert a newline at the start of a multiline string, a literal string can look a bit odd: assert_snapshot!("
foo
bar
", @r"
foo
bar
"); Notice that because the original literal has a newline after its This is mostly only noticeable in examples: very few generated values start with a newline! |
This is an example of what I've been suggesting at #506 (+ some linked issues):
Stacked on Unify handling of file & inline snapshots (compat) #528 so that would need to merge firstLines
deals ambiguously with trailing new lines)matches_legacy
method on snapshot contents — this encapsulates the older formats we still support and warns about themIt's not ready to merge yet, because we don't seem to actually support--force-update-snapshots
on inline values, which is somewhat required. But I'm publishing for feedback & to put some weight on #528 in case we don't want to pursue.