Assertion with == failed: How to disable truncation? (limit infinity)

Hello,

How can I prevent ExUnit from truncating the left and right values in an assertion failure with “…” ellipses? :thinking: Does ExUnit have a configuration option like limit: :infinity for IO.inspect()?

  1) test encode() single (EncoderTest)
     test/encoder_test.exs:25
     Assertion with == failed
     code:  assert actual == expected
     left:  <<87, 0, 0, 0, 2, 95, 105, 100, 0, 7, 0, 0, 0, 115, 99, 104, 101,
              109, 97, 0, 2, 118, 101, 114, 115, 105, 111, 110, 0, 6, 0, 0, 0,
              49, 46, 49, 46, 51, 0, 2, 103, 101, 110, 101, 114, 97, 116, 111,
              114, 0, ...>>
     right: <<109, 0, 0, 0, 2, 95, 105, 100, 0, 7, 0, 0, 0, 115, 99, 104, 101,
              109, 97, 0, 2, 118, 101, 114, 115, 105, 111, 110, 0, 6, 0, 0, 0,
              49, 46, 49, 46, 51, 0, 2, 103, 101, 110, 101, 114, 97, 116, 111,
              114, 0, ...>>
     stacktrace:
       test/encoder_test.exs:43: (test)

Currently, I’m having to manually inspect the contents of my binary data strings with IO.inspect(limit: :infinity) so that I can see them printed in their entirety for manual visual comparison: :weary:

actual = binary1 |> IO.inspect(label: "actual", limit: :infinity)
expected = binary2 |> IO.inspect(label: "expected", limit: :infinity)
assert actual == expected

Thanks for your consideration.

1 Like

At the moment it looks like the default CLI formatter for ExUnit does not have a way to display diffs with an infinite size because it uses IO.puts/2, and that function doesn’t have all the same options that IO.inspect/3 takes. It’s totally possible to write and use a separate formatter if one wanted to do that. The docs on how to do that are here: https://hexdocs.pm/ex_unit/ExUnit.Formatter.html