Skip to content

Commit d458fcb

Browse files
eksperimentaljosevalim
authored andcommitted
Fix order in ExUnit results when listing pinned variables (#14723)
The pinned variables were returned in a random order (often reversed): 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 884e933 when the pinned vars were now accumulated in a map (instead of a list). 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
1 parent d507502 commit d458fcb

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

lib/ex_unit/lib/ex_unit/assertions.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,7 @@ defmodule ExUnit.Assertions do
624624
def __pins__(pins) do
625625
pins
626626
|> Enum.filter(fn {{_, ctx}, _} -> ctx == nil end)
627-
|> Enum.reverse()
627+
|> Enum.sort()
628628
|> Enum.map_join(@indent, fn {{name, _}, var} -> "#{name} = #{inspect(var)}" end)
629629
|> case do
630630
"" ->

lib/ex_unit/test/ex_unit/assertions_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,8 +524,8 @@ defmodule ExUnit.AssertionsTest do
524524
"""
525525
Assertion failed, no matching message after 0ms
526526
The following variables were pinned:
527-
status = :valid
528527
other_status = :invalid
528+
status = :valid
529529
Showing 1 of 1 message in the mailbox\
530530
""" = error.message
531531

0 commit comments

Comments
 (0)