Skip to content

Commit

Permalink
Fix regression when diffing nested improper lists (#14292)
Browse files Browse the repository at this point in the history
Close #14291
  • Loading branch information
sabiwara authored Feb 21, 2025
1 parent 41a0f0c commit b3cc618
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ex_unit/lib/ex_unit/diff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,7 @@ defmodule ExUnit.Diff do
else
other
|> Map.to_list()
|> Enum.map(&escape_pair/1)
|> build_map_or_struct(struct)
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/ex_unit/test/ex_unit/diff_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,8 @@ defmodule ExUnit.DiffTest do
"[[[[], \"Hello-,- \"] | \"world\"] | \"!\"]",
"[[[[], \"Hello \"] | \"world\"] | \"!\"]"
)

refute_diff(:foo = %{bar: [:a | :b]}, "", "")
end

test "proper lists" do
Expand Down
11 changes: 11 additions & 0 deletions lib/ex_unit/test/ex_unit/formatter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,17 @@ defmodule ExUnit.FormatterTest do
"""
end

test "formats assertions with nested improper list diffing" do
failure = [{:error, catch_assertion(assert :foo = %{bar: [1 | 2]}), []}]

assert format_test_all_failure(test_module(), failure, 1, :infinity, &diff_formatter/2) =~ """
match (=) failed
code: assert :foo = %{bar: [1 | 2]}
left: :foo
right: %{bar: [1 | 2]}
"""
end

defmodule BadInspect do
defstruct key: 0

Expand Down

0 comments on commit b3cc618

Please sign in to comment.