From 16c265486a49c620d4103497bd6c6dc153956bd6 Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Tue, 26 Aug 2025 08:27:38 -0500 Subject: [PATCH 1/2] Fix order in ExUnit results when listing pinned variables The pinned variables were returned in a reversed alphabetical order. test/ex_unit_pinned_variables_order_test.exs:23 match (=) failed The following variables were pinned: var_d = "four" var_c = "three" var_b = "two" var_a = "one" code: assert %{a: ^var_d, b: ^var_c, c: ^var_b, d: ^var_a} = build(var_a, var_b, var_c, var_d) left: %{a: ^var_d, b: ^var_c, c: ^var_b, d: ^var_a} right: %{a: "one", b: "two", c: "three", d: "four"} stacktrace: test/ex_unit_pinned_variables_order_test.exs:29: (test) This fix sorts them alphabetically. This bug was introduced in 884e93391e when the pinned vars were now accumulated in a map (instead of a list), therefore no longer the need to reverse the results. A repo replicating the issue can be found here: - https://github.com/eksperimental-debug/elixir_debug/tree/ex-unit-pinned-variables-order - https://github.com/eksperimental-debug/elixir_debug/blob/ex-unit-pinned-variables-order/ex_unit_pinned_variables_order/test/ex_unit_pinned_variables_order_test.exs --- lib/ex_unit/lib/ex_unit/assertions.ex | 1 - lib/ex_unit/test/ex_unit/assertions_test.exs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/ex_unit/lib/ex_unit/assertions.ex b/lib/ex_unit/lib/ex_unit/assertions.ex index e1f64a99b28..a70f285e8a8 100644 --- a/lib/ex_unit/lib/ex_unit/assertions.ex +++ b/lib/ex_unit/lib/ex_unit/assertions.ex @@ -614,7 +614,6 @@ defmodule ExUnit.Assertions do def __pins__(pins) do pins |> Enum.filter(fn {{_, ctx}, _} -> ctx == nil end) - |> Enum.reverse() |> Enum.map_join(@indent, fn {{name, _}, var} -> "#{name} = #{inspect(var)}" end) |> case do "" -> diff --git a/lib/ex_unit/test/ex_unit/assertions_test.exs b/lib/ex_unit/test/ex_unit/assertions_test.exs index 7254edd5e5a..9f213f9749b 100644 --- a/lib/ex_unit/test/ex_unit/assertions_test.exs +++ b/lib/ex_unit/test/ex_unit/assertions_test.exs @@ -524,8 +524,8 @@ defmodule ExUnit.AssertionsTest do """ Assertion failed, no matching message after 0ms The following variables were pinned: - status = :valid other_status = :invalid + status = :valid Showing 1 of 1 message in the mailbox\ """ = error.message From 2b76aa1fb59b31a5edb42f13675849bf7d4a9bf8 Mon Sep 17 00:00:00 2001 From: Eksperimental Date: Tue, 26 Aug 2025 16:09:52 -0500 Subject: [PATCH 2/2] Update lib/ex_unit/lib/ex_unit/assertions.ex MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: José Valim --- lib/ex_unit/lib/ex_unit/assertions.ex | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/ex_unit/lib/ex_unit/assertions.ex b/lib/ex_unit/lib/ex_unit/assertions.ex index a70f285e8a8..2bad20c2039 100644 --- a/lib/ex_unit/lib/ex_unit/assertions.ex +++ b/lib/ex_unit/lib/ex_unit/assertions.ex @@ -614,6 +614,7 @@ defmodule ExUnit.Assertions do def __pins__(pins) do pins |> Enum.filter(fn {{_, ctx}, _} -> ctx == nil end) + |> Enum.sort() |> Enum.map_join(@indent, fn {{name, _}, var} -> "#{name} = #{inspect(var)}" end) |> case do "" ->