Skip to content

Commit 6684dbd

Browse files
committed
Simplify format stacktrace handling
1 parent ccb2a74 commit 6684dbd

File tree

1 file changed

+12
-20
lines changed

1 file changed

+12
-20
lines changed

lib/ex_unit/lib/ex_unit/formatter.ex

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -338,13 +338,7 @@ defmodule ExUnit.Formatter do
338338
{formatted_reason, wrapped_stack} =
339339
format_exception(test, struct, wrapped_stack, width, formatter, @counter_padding)
340340

341-
formatted_stack =
342-
format_stacktrace(
343-
wrapped_stack,
344-
stacktrace_case(test),
345-
stacktrace_test(test),
346-
formatter
347-
)
341+
formatted_stack = format_stacktrace(wrapped_stack, test, formatter)
348342

349343
{error_info(header, formatter) <> pad(formatted_reason <> formatted_stack), stack}
350344

@@ -374,14 +368,6 @@ defmodule ExUnit.Formatter do
374368

375369
defp linked_or_trapped_exit(_kind, _reason), do: :error
376370

377-
defp stacktrace_case(%ExUnit.Test{module: module}), do: module
378-
defp stacktrace_case(%ExUnit.TestModule{name: name}), do: name
379-
defp stacktrace_case(_), do: nil
380-
381-
defp stacktrace_test(%ExUnit.Test{name: name}), do: name
382-
defp stacktrace_test(%ExUnit.TestModule{}), do: nil
383-
defp stacktrace_test(_), do: nil
384-
385371
defp format_exception(test, %ExUnit.AssertionError{} = struct, stack, width, formatter, pad) do
386372
label_padding_size = if has_value?(struct.right), do: 7, else: 6
387373
padding_size = label_padding_size + byte_size(@counter_padding)
@@ -687,22 +673,28 @@ defmodule ExUnit.Formatter do
687673
|> Algebra.format(width)
688674
end
689675

690-
defp format_stacktrace([], _case, _test, _color) do
676+
defp format_stacktrace(stack, %{module: module, name: name}, color),
677+
do: format_stacktrace(stack, module, name, color)
678+
679+
defp format_stacktrace(stack, %{name: name}, color),
680+
do: format_stacktrace(stack, name, nil, color)
681+
682+
defp format_stacktrace([], _module, _test, _color) do
691683
""
692684
end
693685

694-
defp format_stacktrace(stacktrace, test_case, test, color) do
686+
defp format_stacktrace(stacktrace, module, test, color) do
695687
extra_info("stacktrace:", color) <>
696688
Enum.map_join(stacktrace, fn entry ->
697-
stacktrace_info(format_stacktrace_entry(entry, test_case, test), color)
689+
stacktrace_info(format_stacktrace_entry(entry, module, test), color)
698690
end)
699691
end
700692

701-
defp format_stacktrace_entry({test_case, test, _, location}, test_case, test) do
693+
defp format_stacktrace_entry({module, test, _, location}, module, test) do
702694
format_file_line(location[:file], location[:line], " (test)")
703695
end
704696

705-
defp format_stacktrace_entry(entry, _test_case, _test) do
697+
defp format_stacktrace_entry(entry, _module, _test) do
706698
format_stacktrace_entry(entry)
707699
end
708700

0 commit comments

Comments
 (0)