From ce6119a024ccb050b44f70af6d12132d31751b9d Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sun, 29 Dec 2024 18:28:07 +0900 Subject: [PATCH] tests: insert insta::allow_duplicates! { .. } per snapshot This might be a bug of insta, but new snapshots were associated with wrong assertion blocks if allow_duplicates! { .. } contained multiple assertions. --- cli/tests/test_git_init.rs | 8 +++-- cli/tests/test_simplify_parents_command.rs | 42 +++++++++++----------- cli/tests/test_workspaces.rs | 6 ++++ 3 files changed, 33 insertions(+), 23 deletions(-) diff --git a/cli/tests/test_git_init.rs b/cli/tests/test_git_init.rs index 6f0db28a3e..6d069a85bd 100644 --- a/cli/tests/test_git_init.rs +++ b/cli/tests/test_git_init.rs @@ -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" @@ -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" + "###); } } diff --git a/cli/tests/test_simplify_parents_command.rs b/cli/tests/test_simplify_parents_command.rs index ba192de3db..2c9099194e 100644 --- a/cli/tests/test_simplify_parents_command.rs +++ b/cli/tests/test_simplify_parents_command.rs @@ -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 + ◆ + "###); } } diff --git a/cli/tests/test_workspaces.rs b/cli/tests/test_workspaces.rs index 9db6cc09a3..85ab5858f1 100644 --- a/cli/tests/test_workspaces.rs +++ b/cli/tests/test_workspaces.rs @@ -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 @@ -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###" @@ -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 test.user@example.com 2001-02-03 08:05:18 secondary@ 15df8cb5 │ RECOVERY COMMIT FROM `jj workspace update-stale`