Is there a way to make output not print charlists in tests?

Let’s say I make a assert in a test. If there is a failure the logs will show like this:

 left:  %{
              1 => [
                %{
                  count: 1,
                  group_rating: 21,
                  members: ~c"d",
                  ratings: [21]
                },
                %{count: 1, members: ~c"e", group_rating: 2, ratings: [2]}
              ],

Here ~c"e" should print an array of numbers. Any way to change this behaviour? Is there a config file I can place somewhere in my project?

2 Likes

Very interesting question. It doesn’t seem like that’s currently possible without creating a custom formatter. Being able to provide Inspect.Opts to the default ExUnit formatter would be a big win.

2 Likes

I agree. I was looking into this question last night and was surprised I couldn’t find anything. I was also surprised I’ve never run into this myself!

@joshua.aug for now you can use dbg(failing_data, charlists: :as_lists) just so you can see better what’s going on. It’s not ideal but it’s the best I can come up with for now without suggesting you write your own formatter :slight_smile:

1 Like

This is a very interesting idea. I’ve had some projects with binary protocol parsers that would benefit highly from a custom formatter, as it is incomprehensible when it starts to spew charlists for thousands of lines :joy: .

1 Like

Property-based tests, my dude. :wink: