From 278a23e3d49fa3ef9f28d5d5f69a0039424a20b2 Mon Sep 17 00:00:00 2001 From: guglielmobartelloni Date: Sun, 20 Apr 2025 22:45:41 +0200 Subject: [PATCH 1/3] feat: add skip_all command Co-authored-by: Zach Allaun --- README.md | 1 + lib/mneme/assertion.ex | 6 ++++++ lib/mneme/patcher.ex | 3 +++ lib/mneme/server.ex | 3 +++ lib/mneme/terminal.ex | 2 ++ 5 files changed, 15 insertions(+) diff --git a/README.md b/README.md index b55bc5f..f211673 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,7 @@ Whenever that happens, you have a few options: |`y`|Accept|Accept the proposed change. The assertion will be re-run and should pass.| |`n`|Reject|Reject the proposed change and fail the test.| |`s`|Skip|Skip this assertion. The test will not fail, but the `mix test` process will exit with `1`.| +|`S`|Skip All|Skip all remaining assertions and exit. The tests will not fail, but the `mix test` process will exit with `1`.| |`k`|Next|If multiple patterns have been generated, cycle to the next one.| |`K`|Last|If multiple patterns have been generated, cycle to the last one.| |`j`|Previous|If multiple patterns have been generated, cycle to the previous one.| diff --git a/lib/mneme/assertion.ex b/lib/mneme/assertion.ex index 3fe80ee..bfce339 100644 --- a/lib/mneme/assertion.ex +++ b/lib/mneme/assertion.ex @@ -231,6 +231,12 @@ defmodule Mneme.Assertion do end defp handle_assertion({:error, :skipped}, assertion, _, _), do: {assertion, []} + + defp handle_assertion({:error, :skipped_all}, assertion, _, _) do + Mneme.Server.skip_all() + {assertion, []} + end + defp handle_assertion({:error, :file_changed}, assertion, _, _), do: {assertion, []} defp handle_assertion({:error, :rejected}, _, _, nil), do: assertion_error!() diff --git a/lib/mneme/patcher.ex b/lib/mneme/patcher.ex index c409c32..a0bf79e 100644 --- a/lib/mneme/patcher.ex +++ b/lib/mneme/patcher.ex @@ -100,6 +100,9 @@ defmodule Mneme.Patcher do :skip -> {{:error, :skipped}, project} + :skip_all -> + {{:error, :skipped_all}, project} + select -> prompt_and_patch!(project, Assertion.select(assertion, select), counter, node) end diff --git a/lib/mneme/server.ex b/lib/mneme/server.ex index 1328ba3..3304d81 100644 --- a/lib/mneme/server.ex +++ b/lib/mneme/server.ex @@ -262,6 +262,9 @@ defmodule Mneme.Server do {{:error, :skipped}, _} -> inc_stat(state, :skipped) + {{:error, :skipped_all}, _} -> + inc_stat(state, :skipped) + {{:error, :rejected}, _} -> inc_stat(state, :rejected) diff --git a/lib/mneme/terminal.ex b/lib/mneme/terminal.ex index 3d8fedc..f2fe6fb 100644 --- a/lib/mneme/terminal.ex +++ b/lib/mneme/terminal.ex @@ -41,6 +41,7 @@ defmodule Mneme.Terminal do "y" -> :accept "n" -> :reject "s" -> :skip + "S" -> :skip_all "k" -> :next "K" -> :last "j" -> :prev @@ -292,6 +293,7 @@ defmodule Mneme.Terminal do [tag("y", :green), " ", tag("yes", :faint)], [tag("n", :red), " ", tag("no", :faint)], [tag("s", :yellow), " ", tag("skip", :faint)], + [tag("S", :yellow), " ", tag("skip all", :faint)], format_nav_options(assertion) ], [" "] From a649f17c12f8fcb5356db63f893e915d46f4110b Mon Sep 17 00:00:00 2001 From: guglielmobartelloni Date: Sun, 20 Apr 2025 23:01:08 +0200 Subject: [PATCH 2/3] test: update terminal tests --- test/mneme/terminal_test.exs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/mneme/terminal_test.exs b/test/mneme/terminal_test.exs index 3417f68..9fa1f6f 100644 --- a/test/mneme/terminal_test.exs +++ b/test/mneme/terminal_test.exs @@ -15,7 +15,7 @@ defmodule Mneme.TerminalTest do Accept new assertion? > - y yes n no s skip + y yes n no s skip S skip all """ <- message(mock_assertion()) auto_assert """ @@ -30,7 +30,7 @@ defmodule Mneme.TerminalTest do Accept new assertion? > - y yes n no s skip + y yes n no s skip S skip all """ <- message(mock_assertion(), %{diff: :semantic}) auto_assert """ @@ -43,7 +43,7 @@ defmodule Mneme.TerminalTest do Accept new assertion? > - y yes n no s skip + y yes n no s skip S skip all """ <- message(mock_assertion(), %{ diff: :semantic, @@ -64,7 +64,7 @@ defmodule Mneme.TerminalTest do Accept new assertion? > - y yes n no s skip ❮ J/j ●○○ k/K ❯ + y yes n no s skip S skip all ❮ J/j ●○○ k/K ❯ """ <- message(assertion) end @@ -80,7 +80,7 @@ defmodule Mneme.TerminalTest do Value has changed! Update pattern? > - y yes n no s skip + y yes n no s skip S skip all """ <- message(assertion) end end From 29900d6ed06b56f3c7cec5117853f16e580e0947 Mon Sep 17 00:00:00 2001 From: guglielmobartelloni Date: Mon, 21 Apr 2025 17:04:34 +0200 Subject: [PATCH 3/3] test: add integration test for skip_all Co-authored-by: Zach Allaun --- .../skipped_all_assertion_test.exs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 test_integration/skipped_all_assertion_test.exs diff --git a/test_integration/skipped_all_assertion_test.exs b/test_integration/skipped_all_assertion_test.exs new file mode 100644 index 0000000..2a94831 --- /dev/null +++ b/test_integration/skipped_all_assertion_test.exs @@ -0,0 +1,18 @@ +# exit: 2 +defmodule Mneme.Integration.SkippedAllAssertionTest do + use ExUnit.Case + use Mneme + + test "skipping all tests does not update code but does exit with an error code" do + # S + auto_assert 2 + 2 + + auto_assert 2 + 2 + + auto_assert 1 + 2 + end + + test "shouldn't run because skip all was used in the first test" do + auto_assert 1 + 1 + end +end