Skip to content

ExUnit assert crashing when trying to format AssertionError under some wierd condition with "improper list" #14291

Closed
@grzuy

Description

@grzuy

Elixir and Erlang/OTP versions

1.18.2
27.2.2

Operating system

Linux

Current behavior

Hi 👋

This is a very narrowed down of an issue with an assert of a pattern match of a map or struct that has in one of it fields value a :logger.log_event() map, that contains improper lists in the stacktrace list.

If having an ExUnit test case assertion:

    assert(
      %{
        a: nil
      } =
        %{
          a: %{
            b: [10 | "** (RuntimeError) an error"]
          }
        }
    )
** (FunctionClauseError) no function clause matching in Enum."-map/2-lists^map/1-1-"/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"(#Function<2.96213035/1 in ExUnit.Diff.container_to_algebra/5>, "** (RuntimeError) an error")
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ex_unit 1.18.2) lib/ex_unit/diff.ex:1101: ExUnit.Diff.container_to_algebra/5
    (ex_unit 1.18.2) lib/ex_unit/diff.ex:1073: ExUnit.Diff.safe_keyword_to_algebra/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ex_unit 1.18.2) lib/ex_unit/diff.ex:1101: ExUnit.Diff.container_to_algebra/5
    (ex_unit 1.18.2) lib/ex_unit/diff.ex:1141: ExUnit.Diff.wrap_on_diff/3
    (ex_unit 1.18.2) lib/ex_unit/diff.ex:1073: ExUnit.Diff.safe_keyword_to_algebra/2
    (elixir 1.18.2) lib/enum.ex:1714: Enum."-map/2-lists^map/1-1-"/2
    (ex_unit 1.18.2) lib/ex_unit/diff.ex:1101: ExUnit.Diff.container_to_algebra/5
    (ex_unit 1.18.2) lib/ex_unit/formatter.ex:489: ExUnit.Formatter.format_sides/6
    (ex_unit 1.18.2) lib/ex_unit/formatter.ex:471: ExUnit.Formatter.format_assertion_diff/4
    (ex_unit 1.18.2) lib/ex_unit/formatter.ex:382: ExUnit.Formatter.format_exception/6
    (ex_unit 1.18.2) lib/ex_unit/formatter.ex:278: anonymous fn/7 in ExUnit.Formatter.format_test_failure/5
    (elixir 1.18.2) lib/enum.ex:1815: anonymous fn/2 in Enum.map_join/3
    (elixir 1.18.2) lib/enum.ex:4493: Enum.map_intersperse_list/3
    (elixir 1.18.2) lib/enum.ex:1815: Enum.map_join/3
    (ex_unit 1.18.2) lib/ex_unit/formatter.ex:277: ExUnit.Formatter.format_test_failure/5
    (ex_unit 1.18.2) lib/ex_unit/cli_formatter.ex:122: ExUnit.CLIFormatter.handle_cast/2
    (stdlib 6.2) gen_server.erl:2371: :gen_server.try_handle_cast/3
Last message: {:"$gen_cast", {:test_finished, %ExUnit.Test{name: :"test test", case: TowerTest, module: TowerTest, state: {:failed, [{:error, %ExUnit.AssertionError{left: {:%{}, [line: 52, column: 7], [a: nil]}, right: %{a: %{b: [10 | "** (RuntimeError) an error"]}}, message: "match (=) failed", expr: {:assert, [line: 54], [{:=, [line: 54], [{:%{}, [line: 52], [a: nil]}, {:%{}, [line: 55], [a: {:%{}, [line: 56], [b: [{:|, [line: 57], [10, "** (RuntimeError) an error"]}]]}]}]}]}, args: :ex_unit_no_meaningful_value, doctest: :ex_unit_no_meaningful_value, context: {:match, []}}, [{TowerTest, :"test test", 1, [file: ~c"test/tower_test.exs", line: 51]}]}]}, time: 844, tags: %{async: false, line: 50, module: TowerTest, registered: %{}, file: "/home/gon/dev/tower/test/tower_test.exs", test: :"test test", describe_line: nil, test_type: :test, describe: nil}, logs: "", parameters: %{}}}}
State: %{trace: false, width: 190, colors: [enabled: true, diff_delete: :red, diff_delete_whitespace: "\e[48;5;88m", diff_insert: :green, diff_insert_whitespace: "\e[48;5;28m", success: :green, invalid: :yellow, skipped: :yellow, failure: :red, error_info: :red, extra_info: :cyan, location_info: [:bright, :black]], slowest: 0, slowest_modules: 0, failure_counter: 0, test_counter: %{test: 28, doctest: 5}, test_timings: [], skipped_counter: 0, invalid_counter: 0, excluded_counter: 33}

Expected behavior

What happens in elixir 1.17.3

     match (=) failed
     code:  assert %{a: nil} = %{a: %{b: [10 | "** (RuntimeError) an error"]}}
     left:  %{a: nil}
     right: %{a: %{b: [10 | "** (RuntimeError) an error"]}}
     stacktrace:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions