Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty committed Oct 5, 2024
1 parent 606aa20 commit 6484646
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 48 deletions.
77 changes: 30 additions & 47 deletions cargo-insta/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ impl TestProject {
let path_str = path.to_str().map(|s| s.replace('\\', "/")).unwrap();
format!("{}{}", " ".repeat(entry.depth()), path_str)
})
.filter(|line| !line.is_empty())
.chain(std::iter::once(String::new()))
.collect::<Vec<_>>()
.join("\n")
Expand Down Expand Up @@ -570,11 +571,10 @@ fn test_root_crate_workspace_accept() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,8 +1,13 @@
@@ -1,7 +1,12 @@
+ Cargo.lock
Cargo.toml
member
Expand All @@ -587,7 +587,7 @@ fn test_root_crate_workspace_accept() {
src/main.rs
+ src/snapshots
+ src/snapshots/root_crate_workspace_accept__root.snap
"### );
" );
}

/// Check that in a workspace with a default root crate, running `cargo insta
Expand Down Expand Up @@ -627,22 +627,21 @@ fn test_root_crate_no_all() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,5 @@
@@ -1,3 +1,4 @@
+ Cargo.lock
Cargo.toml
member
member/Cargo.toml
@@ -6,3 +7,5 @@
@@ -5,3 +6,5 @@
member/src/lib.rs
src
src/main.rs
+ src/snapshots
+ src/snapshots/root_crate_no_all__root.snap
"### );
" );
}

fn workspace_with_virtual_manifest(name: String) -> TestFiles {
Expand Down Expand Up @@ -729,11 +728,10 @@ fn test_virtual_manifest_all() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,10 +1,15 @@
@@ -1,9 +1,14 @@
+ Cargo.lock
Cargo.toml
member-1
Expand All @@ -748,7 +746,7 @@ fn test_virtual_manifest_all() {
member-2/src/lib.rs
+ member-2/src/snapshots
+ member-2/src/snapshots/virtual_manifest_all_member_2__member_2.snap
"### );
" );
}

/// Check that in a workspace with a virtual manifest, running `cargo insta test
Expand All @@ -766,11 +764,10 @@ fn test_virtual_manifest_default() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,10 +1,15 @@
@@ -1,9 +1,14 @@
+ Cargo.lock
Cargo.toml
member-1
Expand All @@ -785,7 +782,7 @@ fn test_virtual_manifest_default() {
member-2/src/lib.rs
+ member-2/src/snapshots
+ member-2/src/snapshots/virtual_manifest_default_member_2__member_2.snap
"### );
" );
}

/// Check that in a workspace with a virtual manifest, running `cargo insta test
Expand All @@ -803,11 +800,10 @@ fn test_virtual_manifest_single_crate() {

assert!(&output.status.success());

assert_snapshot!(test_project.file_tree_diff(), @r###"
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,9 +1,12 @@
@@ -1,8 +1,11 @@
+ Cargo.lock
Cargo.toml
member-1
Expand All @@ -819,7 +815,7 @@ fn test_virtual_manifest_single_crate() {
member-2
member-2/Cargo.toml
member-2/src
"### );
" );
}

/// Test the old format of inline YAML snapshots with a leading `---` still passes
Expand Down Expand Up @@ -1259,8 +1255,7 @@ fn test_binary_snapshot() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1311,8 +1306,7 @@ fn test_binary_snapshot() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1380,8 +1374,7 @@ fn test_binary_snapshot() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,10 @@
@@ -1,3 +1,9 @@
+ Cargo.lock
Cargo.toml
src
Expand All @@ -1404,8 +1397,7 @@ fn test_binary_snapshot() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1459,8 +1451,7 @@ fn test_binary_snapshot() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,6 @@
@@ -1,3 +1,5 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1509,8 +1500,7 @@ fn test() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,7 @@
@@ -1,3 +1,6 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1540,8 +1530,7 @@ fn test() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1592,8 +1581,7 @@ fn test() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1624,8 +1612,7 @@ fn test() {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,7 @@
@@ -1,3 +1,6 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1943,8 +1930,7 @@ Unused snapshot
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -1973,8 +1959,7 @@ Unused snapshot
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,7 @@
@@ -1,3 +1,6 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -2032,8 +2017,7 @@ mod tests {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,8 @@
@@ -1,3 +1,7 @@
+ Cargo.lock
Cargo.toml
src
Expand Down Expand Up @@ -2062,8 +2046,7 @@ mod tests {
assert_snapshot!(test_project.file_tree_diff(), @r"
--- Original file tree
+++ Updated file tree
@@ -1,4 +1,6 @@
@@ -1,3 +1,5 @@
+ Cargo.lock
Cargo.toml
src
Expand Down
7 changes: 6 additions & 1 deletion insta/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ impl Snapshot {
pub fn matches_fully(&self, other: &Self) -> bool {
match (self.contents(), other.contents()) {
(SnapshotContents::Text(self_contents), SnapshotContents::Text(other_contents)) => {
let contents_match_exact = self_contents == other_contents;
let contents_match_exact = self_contents.matches_fully(other_contents);
match self_contents.kind {
TextSnapshotKind::File => {
self.metadata.trim_for_persistence()
Expand Down Expand Up @@ -654,6 +654,11 @@ impl TextSnapshotContents {
TextSnapshotContents { contents, kind }
}

/// Matches another snapshot without any normalization
pub fn matches_fully(&self, other: &TextSnapshotContents) -> bool {
self.contents == other.contents
}

/// Snapshot matches based on the latest format.
pub fn matches_latest(&self, other: &Self) -> bool {
self.to_string() == other.to_string()
Expand Down

0 comments on commit 6484646

Please sign in to comment.