From 10a3d81c7be96f075c9c69c2af7b3903dd516e94 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sat, 15 Jun 2024 15:14:21 -0700 Subject: [PATCH 1/2] Add `---` to the end of snapshots (requires some thought / discussion) This would allow us te handle ending newlines. We'd need to do some work - to check newlines - to handle the transition when some files won't have these ending items, to only check those that do (...possibly work we should do before we merge this?) --- insta/src/snapshot.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/insta/src/snapshot.rs b/insta/src/snapshot.rs index 70c2f8d8..18b316c4 100644 --- a/insta/src/snapshot.rs +++ b/insta/src/snapshot.rs @@ -325,13 +325,18 @@ impl Snapshot { buf.push_str(&line); } + // We add a closing `---` in recent versions of insta, so we can + // eventually handle ending newlines (which we currently discard) + let snapshot = buf.trim_end_matches('\n'); + let snapshot = snapshot.strip_suffix(r#"---"#).unwrap_or(snapshot); + let (snapshot_name, module_name) = names_of_path(p); Ok(Snapshot::from_components( module_name, Some(snapshot_name), metadata, - buf.into(), + snapshot.into(), )) } @@ -438,6 +443,7 @@ impl Snapshot { buf.push_str("---\n"); buf.push_str(self.contents_str()); buf.push('\n'); + buf.push_str("---\n"); buf } From 335b81520d7910c237b084cef4aee1f07ff3c524 Mon Sep 17 00:00:00 2001 From: Maximilian Roos Date: Sun, 15 Sep 2024 15:57:53 -0700 Subject: [PATCH 2/2] --- cargo-insta/tests/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/cargo-insta/tests/main.rs b/cargo-insta/tests/main.rs index 0511cfba..9852264f 100644 --- a/cargo-insta/tests/main.rs +++ b/cargo-insta/tests/main.rs @@ -829,7 +829,7 @@ Hello, world! assert_snapshot!(test_current_insta.diff("src/snapshots/test_force_update_current__force_update.snap"), @r#" --- Original: src/snapshots/test_force_update_current__force_update.snap +++ Updated: src/snapshots/test_force_update_current__force_update.snap - @@ -1,8 +1,5 @@ + @@ -1,8 +1,6 @@ - --- source: src/lib.rs @@ -839,12 +839,13 @@ Hello, world! Hello, world! - - + +--- "#); assert_snapshot!(test_insta_1_40_0.diff("src/snapshots/test_force_update_1_40_0__force_update.snap"), @r#" --- Original: src/snapshots/test_force_update_1_40_0__force_update.snap +++ Updated: src/snapshots/test_force_update_1_40_0__force_update.snap - @@ -1,8 +1,5 @@ + @@ -1,8 +1,6 @@ - --- source: src/lib.rs @@ -854,6 +855,7 @@ Hello, world! Hello, world! - - + +--- "#); }