Skip to content

Commit

Permalink
Replace complicated name clash test with simple integration test (#609)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Oct 6, 2024
1 parent 5320d5c commit ca70fd0
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 55 deletions.
13 changes: 11 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 57 additions & 0 deletions cargo-insta/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,6 +1262,63 @@ fn test_hashtag_escape() {
"####);
}

#[test]
fn test_snapshot_name_clash() {
let test_project = TestFiles::new()
.add_file(
"Cargo.toml",
r#"
[package]
name = "snapshot_name_clash_test"
version = "0.1.0"
edition = "2021"
[lib]
doctest = false
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/lib.rs",
r#"
#[cfg(test)]
mod tests {
use insta::assert_debug_snapshot;
#[test]
fn test_foo_always_missing() {
assert_debug_snapshot!(42);
}
#[test]
fn foo_always_missing() {
assert_debug_snapshot!(42);
}
}
"#
.to_string(),
)
.create_project();

let output = test_project
.insta_cmd()
.args(["test", "--accept", "--", "--nocapture"])
.stderr(Stdio::piped())
.output()
.unwrap();

// The test should fail due to the name clash
assert!(!output.status.success());

let error_output = String::from_utf8_lossy(&output.stderr);

// Check for the name clash error message
assert!(error_output.contains("Insta snapshot name clash detected between 'foo_always_missing' and 'test_foo_always_missing' in 'snapshot_name_clash_test::tests'. Rename one function."));
}

/// A pending binary snapshot should have a binary file with the passed extension alongside it.
#[test]
fn test_binary_pending() {
Expand Down
53 changes: 0 additions & 53 deletions insta/tests/test_clash_detection.rs

This file was deleted.

0 comments on commit ca70fd0

Please sign in to comment.