Skip to content

Commit 16363f4

Browse files
max-sixtyClaude
andauthored
Enforce starting newlines (#563)
This is an example of what I've been suggesting at #506 (+ some linked issues): - ~Stacked on #528 so that would need to merge first~ - Enforces the correct number of newlines at the start of snapshots. The start is easier because we don't need to worry about editor issues in trailing newlines (and don't need to worry about how `Lines` deals ambiguously with trailing new lines) - Works for both inline & file snapshots - Adds a `matches_legacy` method on snapshot contents — this encapsulates the older formats we still support and warns about them ~It'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.~ --------- Co-authored-by: Claude <no-reply@anthropic.com>
1 parent 0d79fa9 commit 16363f4

File tree

9 files changed

+619
-153
lines changed

9 files changed

+619
-153
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ All notable changes to insta and cargo-insta are documented here.
88
nextest. Shows a deprecation warning when nextest is used with doctests without this flag, to prepare `cargo insta` to no longer run
99
a separate doctest process when using nextest in the future. #803
1010

11+
- We no longer trim starting newlines during assertions, which allows asserting
12+
the number of leading newlines match. Existing assertions with different
13+
leading newlines will pass and print a warning suggesting running with
14+
`--force-update-snapshots`. They may fail in the future. (Note that we still
15+
currently allow differing _trailing_ newlines, though may adjust this in the
16+
future). #563
17+
18+
1119
## 1.43.2
1220

1321
- Fix panics when `cargo metadata` fails to execute or parse (e.g., when cargo is not in PATH or returns invalid output). Now falls back to using the manifest directory as the workspace root. #798 (@adriangb)

cargo-insta/tests/functional/binary.rs

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ fn test_binary_snapshot() {
2626
assert_snapshot!(test_project.file_tree_diff(), @r"
2727
--- Original file tree
2828
+++ Updated file tree
29-
@@ -1,4 +1,8 @@
30-
29+
@@ -1,3 +1,7 @@
3130
+ Cargo.lock
3231
Cargo.toml
3332
src
@@ -66,8 +65,7 @@ fn test_binary_snapshot() {
6665
assert_snapshot!(test_project.file_tree_diff(), @r"
6766
--- Original file tree
6867
+++ Updated file tree
69-
@@ -1,4 +1,8 @@
70-
68+
@@ -1,3 +1,7 @@
7169
+ Cargo.lock
7270
Cargo.toml
7371
src
@@ -123,8 +121,7 @@ fn test_binary_snapshot() {
123121
assert_snapshot!(test_project.file_tree_diff(), @r"
124122
--- Original file tree
125123
+++ Updated file tree
126-
@@ -1,4 +1,10 @@
127-
124+
@@ -1,3 +1,9 @@
128125
+ Cargo.lock
129126
Cargo.toml
130127
src
@@ -147,8 +144,7 @@ fn test_binary_snapshot() {
147144
assert_snapshot!(test_project.file_tree_diff(), @r"
148145
--- Original file tree
149146
+++ Updated file tree
150-
@@ -1,4 +1,8 @@
151-
147+
@@ -1,3 +1,7 @@
152148
+ Cargo.lock
153149
Cargo.toml
154150
src
@@ -199,8 +195,7 @@ fn test_binary_snapshot() {
199195
assert_snapshot!(test_project.file_tree_diff(), @r"
200196
--- Original file tree
201197
+++ Updated file tree
202-
@@ -1,4 +1,6 @@
203-
198+
@@ -1,3 +1,5 @@
204199
+ Cargo.lock
205200
Cargo.toml
206201
src
@@ -237,8 +232,7 @@ fn test() {
237232
assert_snapshot!(test_project.file_tree_diff(), @r"
238233
--- Original file tree
239234
+++ Updated file tree
240-
@@ -1,4 +1,7 @@
241-
235+
@@ -1,3 +1,6 @@
242236
+ Cargo.lock
243237
Cargo.toml
244238
src
@@ -268,8 +262,7 @@ fn test() {
268262
assert_snapshot!(test_project.file_tree_diff(), @r"
269263
--- Original file tree
270264
+++ Updated file tree
271-
@@ -1,4 +1,8 @@
272-
265+
@@ -1,3 +1,7 @@
273266
+ Cargo.lock
274267
Cargo.toml
275268
src
@@ -308,8 +301,7 @@ fn test() {
308301
assert_snapshot!(test_project.file_tree_diff(), @r"
309302
--- Original file tree
310303
+++ Updated file tree
311-
@@ -1,4 +1,8 @@
312-
304+
@@ -1,3 +1,7 @@
313305
+ Cargo.lock
314306
Cargo.toml
315307
src
@@ -340,8 +332,7 @@ fn test() {
340332
assert_snapshot!(test_project.file_tree_diff(), @r"
341333
--- Original file tree
342334
+++ Updated file tree
343-
@@ -1,4 +1,7 @@
344-
335+
@@ -1,3 +1,6 @@
345336
+ Cargo.lock
346337
Cargo.toml
347338
src
@@ -381,8 +372,7 @@ fn test_snapshot() {
381372
assert_snapshot!(test_project.file_tree_diff(), @r"
382373
--- Original file tree
383374
+++ Updated file tree
384-
@@ -1,4 +1,8 @@
385-
375+
@@ -1,3 +1,7 @@
386376
+ Cargo.lock
387377
Cargo.toml
388378
src
@@ -411,8 +401,7 @@ fn test_snapshot() {
411401
assert_snapshot!(test_project.file_tree_diff(), @r"
412402
--- Original file tree
413403
+++ Updated file tree
414-
@@ -1,4 +1,6 @@
415-
404+
@@ -1,3 +1,5 @@
416405
+ Cargo.lock
417406
Cargo.toml
418407
src

cargo-insta/tests/functional/delete_pending.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ fn test_snapshot_file() {
4545
assert_snapshot!(test_project.file_tree_diff(), @r"
4646
--- Original file tree
4747
+++ Updated file tree
48-
@@ -1,4 +1,7 @@
49-
48+
@@ -1,3 +1,6 @@
5049
+ Cargo.lock
5150
Cargo.toml
5251
src
@@ -70,8 +69,7 @@ fn test_snapshot_file() {
7069
assert_snapshot!(test_project.file_tree_diff(), @r"
7170
--- Original file tree
7271
+++ Updated file tree
73-
@@ -1,4 +1,6 @@
74-
72+
@@ -1,3 +1,5 @@
7573
+ Cargo.lock
7674
Cargo.toml
7775
src
@@ -116,8 +114,7 @@ fn test_file_snapshot() {
116114
assert_snapshot!(test_project.file_tree_diff(), @r"
117115
--- Original file tree
118116
+++ Updated file tree
119-
@@ -1,4 +1,7 @@
120-
117+
@@ -1,3 +1,6 @@
121118
+ Cargo.lock
122119
Cargo.toml
123120
src
@@ -158,8 +155,7 @@ fn test_file_snapshot() {
158155
assert_snapshot!(test_project.file_tree_diff(), @r"
159156
--- Original file tree
160157
+++ Updated file tree
161-
@@ -1,4 +1,9 @@
162-
158+
@@ -1,3 +1,8 @@
163159
+ Cargo.lock
164160
Cargo.toml
165161
src
@@ -183,8 +179,7 @@ fn test_file_snapshot() {
183179
assert_snapshot!(test_project.file_tree_diff(), @r"
184180
--- Original file tree
185181
+++ Updated file tree
186-
@@ -1,4 +1,7 @@
187-
182+
@@ -1,3 +1,6 @@
188183
+ Cargo.lock
189184
Cargo.toml
190185
src
@@ -206,8 +201,7 @@ fn test_file_snapshot() {
206201
assert_snapshot!(test_project.file_tree_diff(), @r"
207202
--- Original file tree
208203
+++ Updated file tree
209-
@@ -1,4 +1,9 @@
210-
204+
@@ -1,3 +1,8 @@
211205
+ Cargo.lock
212206
Cargo.toml
213207
src
@@ -250,8 +244,7 @@ fn test_file_snapshot() {
250244
assert_snapshot!(test_project.file_tree_diff(), @r"
251245
--- Original file tree
252246
+++ Updated file tree
253-
@@ -1,4 +1,7 @@
254-
247+
@@ -1,3 +1,6 @@
255248
+ Cargo.lock
256249
Cargo.toml
257250
src

0 commit comments

Comments
 (0)