Skip to content

Commit

Permalink
tests: insert insta::allow_duplicates! { .. } per snapshot
Browse files Browse the repository at this point in the history
This might be a bug of insta, but new snapshots were associated with wrong
assertion blocks if allow_duplicates! { .. } contained multiple assertions.
  • Loading branch information
yuja committed Jan 10, 2025
1 parent 84e619c commit ce6119a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
8 changes: 5 additions & 3 deletions cli/tests/test_git_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@ fn test_git_init_external_import_trunk(bare: bool) {
);
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @"");
}
insta::allow_duplicates! {
insta::assert_snapshot!(stderr, @r###"
Done importing changes from the underlying Git repo.
Setting the revset alias "trunk()" to "trunk@origin"
Expand All @@ -239,9 +241,9 @@ fn test_git_init_external_import_trunk(bare: bool) {
&["config", "list", "--repo", "revset-aliases.\"trunk()\""],
);
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @r###"
revset-aliases."trunk()" = "trunk@origin"
"###);
insta::assert_snapshot!(stdout, @r###"
revset-aliases."trunk()" = "trunk@origin"
"###);
}
}

Expand Down
42 changes: 22 additions & 20 deletions cli/tests/test_simplify_parents_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,35 @@ fn test_simplify_parents_redundant_parent(args: &[&str]) {
create_commit(&test_env, &repo_path, "c", &["a", "b"]);
let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]);
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @r###"
@ c
├─╮
│ ○ b
├─╯
○ a
"###);
insta::assert_snapshot!(stdout, @r###"
@ c
├─╮
│ ○ b
├─╯
○ a
"###);
}
let (stdout, stderr) = test_env.jj_cmd_ok(&repo_path, args);
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Removed 1 edges from 1 out of 3 commits.
Working copy now at: royxmykx 0ac2063b c | c
Parent commit : zsuskuln 1394f625 b | b
"###);
insta::assert_snapshot!(stdout, @"");
}
insta::allow_duplicates! {
insta::assert_snapshot!(stderr, @r###"
Removed 1 edges from 1 out of 3 commits.
Working copy now at: royxmykx 0ac2063b c | c
Parent commit : zsuskuln 1394f625 b | b
"###);
}

let stdout = test_env.jj_cmd_success(&repo_path, &["log", "-r", "all()", "-T", "description"]);
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @r###"
@ c
○ b
○ a
"###);
insta::assert_snapshot!(stdout, @r###"
@ c
○ b
○ a
"###);
}
}

Expand Down
6 changes: 6 additions & 0 deletions cli/tests/test_workspaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -815,6 +815,8 @@ fn test_workspaces_current_op_discarded_by_other(automatic: bool) {
let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["st"]);
insta::allow_duplicates! {
insta::assert_snapshot!(stderr, @"");
}
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @r###"
Working copy changes:
A added
Expand All @@ -823,6 +825,8 @@ fn test_workspaces_current_op_discarded_by_other(automatic: bool) {
Working copy : kmkuslsw 15df8cb5 RECOVERY COMMIT FROM `jj workspace update-stale`
Parent commit: rzvqmyuk 96b31daf (empty) (no description set)
"###);
}
insta::allow_duplicates! {
// The modified file should have the same contents it had before (not reset to
// the base contents)
insta::assert_snapshot!(std::fs::read_to_string(secondary_path.join("modified")).unwrap(), @r###"
Expand All @@ -833,6 +837,8 @@ fn test_workspaces_current_op_discarded_by_other(automatic: bool) {
let (stdout, stderr) = test_env.jj_cmd_ok(&secondary_path, &["evolog"]);
insta::allow_duplicates! {
insta::assert_snapshot!(stderr, @"");
}
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @r###"
@ kmkuslsw [email protected] 2001-02-03 08:05:18 secondary@ 15df8cb5
│ RECOVERY COMMIT FROM `jj workspace update-stale`
Expand Down

0 comments on commit ce6119a

Please sign in to comment.