Skip to content

Commit

Permalink
Consolidate Cargo.toml creation in functional tests (#662)
Browse files Browse the repository at this point in the history
  • Loading branch information
max-sixty authored Oct 12, 2024
1 parent 10db5b0 commit 2b8fce7
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 276 deletions.
139 changes: 26 additions & 113 deletions cargo-insta/tests/functional/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,9 @@ use crate::TestFiles;
#[test]
fn test_binary_pending() {
let test_project = TestFiles::new()
.add_cargo_toml("test_binary_pending")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_binary_pending"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test_binary_snapshot() {
Expand All @@ -43,7 +31,7 @@ fn test_binary_snapshot() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_binary_pending__binary_snapshot.snap.new
+ src/snapshots/test_binary_pending__binary_snapshot.snap.new.txt
Expand All @@ -54,21 +42,9 @@ fn test_binary_snapshot() {
#[test]
fn test_binary_accept() {
let test_project = TestFiles::new()
.add_cargo_toml("test_binary_accept")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_binary_accept"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test_binary_snapshot() {
Expand All @@ -95,7 +71,7 @@ fn test_binary_snapshot() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_binary_accept__binary_snapshot.snap
+ src/snapshots/test_binary_accept__binary_snapshot.snap.txt
Expand All @@ -108,21 +84,9 @@ fn test_binary_snapshot() {
#[test]
fn test_binary_change_extension() {
let test_project = TestFiles::new()
.add_cargo_toml("test_binary_change_extension")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_binary_change_extension"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test_binary_snapshot() {
Expand All @@ -142,7 +106,7 @@ fn test_binary_snapshot() {
assert!(&output.status.success());

test_project.update_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test_binary_snapshot() {
Expand All @@ -164,7 +128,7 @@ fn test_binary_snapshot() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_binary_change_extension__binary_snapshot.snap
+ src/snapshots/test_binary_change_extension__binary_snapshot.snap.new
Expand All @@ -188,7 +152,7 @@ fn test_binary_snapshot() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_binary_change_extension__binary_snapshot.snap
+ src/snapshots/test_binary_change_extension__binary_snapshot.snap.json
Expand All @@ -200,21 +164,9 @@ fn test_binary_snapshot() {
#[test]
fn test_binary_pending_snapshot_removal() {
let test_project = TestFiles::new()
.add_cargo_toml("test_binary_pending_snapshot_removal")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_binary_pending_snapshot_removal"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test_binary_snapshot() {
Expand All @@ -229,7 +181,7 @@ fn test_binary_snapshot() {

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

test_project.update_file("src/main.rs", "".to_string());
test_project.update_file("src/lib.rs", "".to_string());

let output = test_project.insta_cmd().args(["test"]).output().unwrap();

Expand All @@ -243,7 +195,7 @@ fn test_binary_snapshot() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
");
}
Expand All @@ -253,21 +205,9 @@ fn test_binary_snapshot() {
#[test]
fn test_change_text_to_binary() {
let test_project = TestFiles::new()
.add_cargo_toml("test_change_text_to_binary")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_change_text_to_binary"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test() {
Expand All @@ -293,13 +233,13 @@ fn test() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_change_text_to_binary__test.snap
");

test_project.update_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test() {
Expand All @@ -324,7 +264,7 @@ fn test() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_change_text_to_binary__test.snap
+ src/snapshots/test_change_text_to_binary__test.snap.txt
Expand All @@ -336,21 +276,9 @@ fn test() {
#[test]
fn test_change_binary_to_text() {
let test_project = TestFiles::new()
.add_cargo_toml("test_change_binary_to_text")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_change_binary_to_text"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test() {
Expand All @@ -376,14 +304,14 @@ fn test() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_change_binary_to_text__some_name.snap
+ src/snapshots/test_change_binary_to_text__some_name.snap.json
");

test_project.update_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test() {
Expand All @@ -408,7 +336,7 @@ fn test() {
+ Cargo.lock
Cargo.toml
src
src/main.rs
src/lib.rs
+ src/snapshots
+ src/snapshots/test_change_binary_to_text__some_name.snap
");
Expand All @@ -417,22 +345,7 @@ fn test() {
#[test]
fn test_binary_unreferenced_delete() {
let test_project = TestFiles::new()
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_binary_unreferenced_delete"
version = "0.1.0"
edition = "2021"
[lib]
doctest = false
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_cargo_toml("test_binary_unreferenced_delete")
.add_file(
"src/lib.rs",
r#"
Expand Down
60 changes: 18 additions & 42 deletions cargo-insta/tests/functional/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ serde = { version = "1.0", features = ["derive"] }
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
use serde::Serialize;
Expand Down Expand Up @@ -53,9 +53,9 @@ fn test_json_snapshot() {

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

assert_snapshot!(test_project.diff("src/main.rs"), @r##"
--- Original: src/main.rs
+++ Updated: src/main.rs
assert_snapshot!(test_project.diff("src/lib.rs"), @r##"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -15,5 +15,10 @@
};
insta::assert_json_snapshot!(&user, {
Expand Down Expand Up @@ -89,7 +89,7 @@ serde = { version = "1.0", features = ["derive"] }
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
use serde::Serialize;
Expand Down Expand Up @@ -122,9 +122,9 @@ fn test_yaml_snapshot() {

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

assert_snapshot!(test_project.diff("src/main.rs"), @r###"
--- Original: src/main.rs
+++ Updated: src/main.rs
assert_snapshot!(test_project.diff("src/lib.rs"), @r###"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -15,5 +15,8 @@
};
insta::assert_yaml_snapshot!(&user, {
Expand All @@ -141,21 +141,9 @@ fn test_yaml_snapshot() {
#[test]
fn test_utf8_inline() {
let test_project = TestFiles::new()
.add_cargo_toml("test_utf8_inline")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_utf8_inline"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#"
#[test]
fn test_non_basic_plane() {
Expand Down Expand Up @@ -197,9 +185,9 @@ fn test_trailing_comma_in_inline_snapshot() {

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

assert_snapshot!(test_project.diff("src/main.rs"), @r##"
--- Original: src/main.rs
+++ Updated: src/main.rs
assert_snapshot!(test_project.diff("src/lib.rs"), @r##"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -1,21 +1,19 @@
#[test]
Expand Down Expand Up @@ -310,21 +298,9 @@ fn test_old_yaml_format() {
#[test]
fn test_hashtag_escape_in_inline_snapshot() {
let test_project = TestFiles::new()
.add_cargo_toml("test_hashtag_escape")
.add_file(
"Cargo.toml",
r#"
[package]
name = "test_hashtag_escape"
version = "0.1.0"
edition = "2021"
[dependencies]
insta = { path = '$PROJECT_PATH' }
"#
.to_string(),
)
.add_file(
"src/main.rs",
"src/lib.rs",
r#####"
#[test]
fn test_hashtag_escape() {
Expand All @@ -344,9 +320,9 @@ fn test_hashtag_escape() {

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

assert_snapshot!(test_project.diff("src/main.rs"), @r####"
--- Original: src/main.rs
+++ Updated: src/main.rs
assert_snapshot!(test_project.diff("src/lib.rs"), @r####"
--- Original: src/lib.rs
+++ Updated: src/lib.rs
@@ -2,5 +2,8 @@
#[test]
fn test_hashtag_escape() {
Expand Down
Loading

0 comments on commit 2b8fce7

Please sign in to comment.