From 909d05e11442892835782aaca76448a1e8835507 Mon Sep 17 00:00:00 2001 From: Bryan Lai Date: Sun, 13 Oct 2024 17:42:11 +0800 Subject: [PATCH 1/2] fix(tests): ignore no-op checkouts in some tests The patch makes use of insta's `filters` feature. --- Cargo.lock | 1 + git-branchless/Cargo.toml | 1 + git-branchless/tests/test_amend.rs | 9 +++++++++ 3 files changed, 11 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index 6642a3c50..14e2ecfbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1935,6 +1935,7 @@ dependencies = [ "console", "lazy_static", "linked-hash-map", + "regex", "similar", ] diff --git a/git-branchless/Cargo.toml b/git-branchless/Cargo.toml index 5096c36c7..8f3556b02 100644 --- a/git-branchless/Cargo.toml +++ b/git-branchless/Cargo.toml @@ -39,6 +39,7 @@ git-branchless-smartlog = { workspace = true } git-branchless-submit = { workspace = true } git-branchless-test = { workspace = true } git-branchless-undo = { workspace = true } +insta = { workspace = true, features = ["filters"] } itertools = { workspace = true } lazy_static = { workspace = true } lib = { workspace = true } diff --git a/git-branchless/tests/test_amend.rs b/git-branchless/tests/test_amend.rs index 5acc7be6b..7f255203c 100644 --- a/git-branchless/tests/test_amend.rs +++ b/git-branchless/tests/test_amend.rs @@ -592,6 +592,14 @@ fn test_amend_undo() -> eyre::Result<()> { { let (stdout, _stderr) = git.branchless("undo", &["-y"])?; let stdout = trim_lines(stdout); + insta::with_settings!({filters => vec![ + // ignore no-op checkouts, which is present in e.g. git 2.43 + // but disappears in e.g. git 2.46 + (r"\n2\. Check out from 94b1077 create file1.txt\s*to 94b1077 create file1.txt\n", "\n"), + // ignore different numbering of events + (r"(?m)^[0-9]+\. ", "#. "), + ("Applied ([0-9]+) inverse events.", "Applied # inverse events."), + ]}, { insta::assert_snapshot!(stdout, @r###" Will apply these actions: 1. Move branch foo from 94b1077 create file1.txt @@ -622,6 +630,7 @@ fn test_amend_undo() -> eyre::Result<()> { @ c0bdfb5 (> foo) create file1.txt Applied 6 inverse events. "###); + }); } { From 72d2b0f1d5167278f0830a1a789001d299febce1 Mon Sep 17 00:00:00 2001 From: Bryan Lai Date: Mon, 14 Oct 2024 01:00:12 +0800 Subject: [PATCH 2/2] fix(tests): update insta snapshots --- git-branchless/tests/test_amend.rs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/git-branchless/tests/test_amend.rs b/git-branchless/tests/test_amend.rs index 7f255203c..7583c1890 100644 --- a/git-branchless/tests/test_amend.rs +++ b/git-branchless/tests/test_amend.rs @@ -602,18 +602,16 @@ fn test_amend_undo() -> eyre::Result<()> { ]}, { insta::assert_snapshot!(stdout, @r###" Will apply these actions: - 1. Move branch foo from 94b1077 create file1.txt + #. Move branch foo from 94b1077 create file1.txt to 94b1077 create file1.txt - 2. Check out from 94b1077 create file1.txt - to 94b1077 create file1.txt - 3. Restore snapshot for branch foo + #. Restore snapshot for branch foo pointing to 94b1077 create file1.txt backed up using b4371f8 branchless: automated working copy snapshot - 4. Move branch foo from 94b1077 create file1.txt + #. Move branch foo from 94b1077 create file1.txt to c0bdfb5 create file1.txt - 5. Rewrite commit 94b1077 create file1.txt + #. Rewrite commit 94b1077 create file1.txt as c0bdfb5 create file1.txt - 6. Restore snapshot for branch foo + #. Restore snapshot for branch foo pointing to c0bdfb5 create file1.txt backed up using a293e0b branchless: automated working copy snapshot branchless: running command: checkout a293e0b4502882ced673f83b6742539ee06cbc74 -B foo @@ -628,7 +626,7 @@ fn test_amend_undo() -> eyre::Result<()> { O f777ecc (master) create initial.txt | @ c0bdfb5 (> foo) create file1.txt - Applied 6 inverse events. + Applied # inverse events. "###); }); }