Skip to content

Commit

Permalink
Add integration test for old inline format (#598)
Browse files Browse the repository at this point in the history
Moving some unambiguous code from #563 into a new PR so we can keep
moving
  • Loading branch information
max-sixty authored Sep 17, 2024
1 parent 59568b7 commit a9b46fa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 11 deletions.
47 changes: 47 additions & 0 deletions cargo-insta/tests/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,53 @@ fn test_virtual_manifest_single_crate() {
"### );
}

/// Test the old format of inline YAML snapshots with a leading `---` still passes
#[test]
fn test_old_yaml_format() {
let test_project = TestFiles::new()
.add_file(
"Cargo.toml",
r#"
[package]
name = "old-yaml-format"
version = "0.1.0"
edition = "2021"
[lib]
doctest = false
[dependencies]
insta = { path = '$PROJECT_PATH', features = ["yaml"] }
"#
.to_string(),
)
.add_file(
"src/lib.rs",
r#####"
#[test]
fn test_old_yaml_format() {
insta::assert_yaml_snapshot!("foo", @r####"
---
foo
"####);
}
"#####
.to_string(),
)
.create_project();

// Run the test with --force-update-snapshots and --accept
let output = test_project
.cmd()
.args(["test", "--accept", "--", "--nocapture"])
.output()
.unwrap();

assert_success(&output);

assert_snapshot!(test_project.diff("src/lib.rs"), @"");
}

#[test]
fn test_force_update_snapshots() {
fn create_test_force_update_project(name: &str, insta_dependency: &str) -> TestProject {
Expand Down
11 changes: 0 additions & 11 deletions insta/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,4 @@ fn test_yaml_serialization() {
- my-tool
- run
"###);

// Old approach with leading `---`:
crate::assert_snapshot!(&inline_yaml, @r###"
---
env:
- ENVIRONMENT
- production
cmdline:
- my-tool
- run
"###);
}

0 comments on commit a9b46fa

Please sign in to comment.