zachallaun/mneme

New bug: auto_assert for tuples with :ok and maps with string values with newlines

Closed this issue · 4 comments

I seem to be an a roll... This bug might be tricky though. Repo here:

Test case:

test "formatting for newlines" do
    res = {:ok, %{
      a: ~s|first\nsecond|,
      b: :file
    }}
    auto_assert(res)
end
$ mix test

22:07:23.106 [error] GenServer #PID<0.247.0> terminating
** (FunctionClauseError) no function clause matching in Inspect.Algebra.color/3
    (elixir 1.14.2) lib/inspect/algebra.ex:609: Inspect.Algebra.color({:ok, {:%{}, [line: 15], [a: {:__block__, [line: 15, delimiter: "\"\"\""], ["first\nsecond\\\n"]}, b: :file]}}, :diff_delete, %Inspect.Opts{base: :decimal, binaries: :infer, char_lists: :infer, charlists: :infer, custom_options: [], inspect_fun: &Inspect.inspect/2, limit: 50, pretty: false, printable_limit: 4096, safe: true, structs: true, syntax_colors: [enabled: true, diff_delete: :red, diff_delete_whitespace: "\e[48;5;88m", diff_insert: :green, diff_insert_whitespace: "\e[48;5;28m"], width: 80})
    (ex_unit 1.14.2) lib/ex_unit/formatter.ex:337: ExUnit.Formatter.format_sides/6
    (ex_unit 1.14.2) lib/ex_unit/formatter.ex:325: ExUnit.Formatter.format_assertion_diff/4
    (ex_unit 1.14.2) lib/ex_unit/formatter.ex:247: ExUnit.Formatter.format_exception/6
    (ex_unit 1.14.2) lib/ex_unit/formatter.ex:161: anonymous fn/7 in ExUnit.Formatter.format_test_failure/5
    (elixir 1.14.2) lib/enum.ex:1755: anonymous fn/2 in Enum.map_join/3
    (elixir 1.14.2) lib/enum.ex:4289: Enum.map_intersperse_list/3
    (elixir 1.14.2) lib/enum.ex:1755: Enum.map_join/3
    (ex_unit 1.14.2) lib/ex_unit/formatter.ex:160: ExUnit.Formatter.format_test_failure/5
    (ex_unit 1.14.2) lib/ex_unit/cli_formatter.ex:109: ExUnit.CLIFormatter.handle_cast/2
    (mneme 0.2.5) lib/mneme/ex_unit_formatter.ex:17: Mneme.ExUnitFormatter.handle_cast/2
    (stdlib 4.2) gen_server.erl:1123: :gen_server.try_dispatch/4
    (stdlib 4.2) gen_server.erl:1200: :gen_server.handle_msg/6
    (stdlib 4.2) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:test_finished, %ExUnit.Test{name: :"test formatting for newlines", case: MnemeBugDbgTest, module: MnemeBugDbgTest, state: {:failed, [{:error, %ExUnit.AssertionError{left: {:__block__, [line: 15], [ok: {:%{}, [line: 15], [a: {:__block__, [line: 15, delimiter: "\"\"\""], ["first\nsecond\\\n"]}, b: :file]}]}, right: {:ok, %{a: "first\nsecond", b: :file}}, message: "match (=) failed", expr: {:assert, [line: 15], [{:=, [line: 15], [{:__block__, [line: 15], [ok: {:%{}, [line: 15], [a: {:__block__, [line: 15], ["first\nsecond\\\n"]}, b: :file]}]}, {:value, [line: 15], :mneme}]}]}, args: :ex_unit_no_meaningful_value, doctest: :ex_unit_no_meaningful_value, context: {:match, []}}, [{:elixir_eval, :__FILE__, 1, [file: '/Users/roman/Desktop/work/sandbox/0.elixir/mneme_bug_dbg/test/mneme_bug_dbg_test.exs', line: 15]}, {:elixir, :"-eval_external_handler/1-fun-2-", 4, [file: 'src/elixir.erl', line: 309]}, {:erl_eval, :do_apply, 7, [file: 'erl_eval.erl', line: 748]}, {:erl_eval, :expr, 6, [file: 'erl_eval.erl', line: 492]}, {:erl_eval, :exprs, 6, [file: 'erl_eval.erl', line: 136]}, {:elixir, :eval_forms, 4, [file: 'src/elixir.erl', line: 294]}, {Module.ParallelChecker, :verify, 1, [file: 'lib/module/parallel_checker.ex', line: 107]}, {Code, :eval_quoted, 3, [file: 'lib/code.ex', line: 829]}, {Mneme.Assertion, :run!, 5, [file: 'lib/mneme/assertion.ex', line: 63]}, {MnemeBugDbgTest, :"test formatting for newlines", 1, [file: 'test/mneme_bug_dbg_test.exs', line: 15]}]}]}, time: 50264, tags: %{async: false, case: MnemeBugDbgTest, describe: nil, describe_line: nil, file: "/Users/roman/Desktop/work/sandbox/0.elixir/mneme_bug_dbg/test/mneme_bug_dbg_test.exs", line: 9, module: MnemeBugDbgTest, registered: %{mneme: [], mneme_describe: [], mneme_module: [[action: :accept, default_pattern: :last]]}, test: :"test formatting for newlines", test_type: :test}, logs: ""}}}
State: {ExUnit.CLIFormatter, %{colors: [enabled: true, diff_delete: :red, diff_delete_whitespace: "\e[48;5;88m", diff_insert: :green, diff_insert_whitespace: "\e[48;5;28m"], excluded_counter: 0, failure_counter: 0, invalid_counter: 0, seed: 25923, skipped_counter: 0, slowest: 0, test_counter: %{}, test_timings: [], trace: false, width: 204}}
^C

I knew something like this would crop up -- I think I'm being inconsistent in the way I'm handling new lines and escape sequences. Thanks for the report! I'll dig into this and hopefully have a fix somewhat soon.

Fixed. This next release is going to be a bit bigger and I want to tighten up a few areas first, but I'll have it out in the next day or so! :)

Nice, thanks for fixing! Will wait for the release soon.

Have a greet Monday. ))

Nice, thanks for fixing! Will wait for the release soon.

Have a greet Monday. ))