Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions lib/ex_unit/lib/ex_unit/diff.ex
Original file line number Diff line number Diff line change
Expand Up @@ -765,16 +765,20 @@ defmodule ExUnit.Diff do
end
end

# if kw represents a struct, this returns the result of `struct.__info__(:struct)`, otherwise nil
defp struct_module(kw) do
{struct, struct_kw} = Keyword.pop(kw, :__struct__)

info =
is_atom(struct) and struct != nil and
Code.ensure_loaded?(struct) and function_exported?(struct, :__info__, 1) and
struct.__info__(:struct)
case Enum.split_with(kw, fn {k, _} -> k == :__struct__ end) do
{[{_, struct} | _], struct_kw} when is_atom(struct) and struct != nil ->
info =
Code.ensure_loaded?(struct) and function_exported?(struct, :__info__, 1) and
struct.__info__(:struct)

if info && Enum.all?(struct_kw, fn {k, _} -> Enum.any?(info, &(&1.field == k)) end) do
struct
end

if info && Enum.all?(struct_kw, fn {k, _} -> Enum.any?(info, &(&1.field == k)) end) do
struct
_ ->
nil
end
end

Expand Down
Loading