Assertions don't expand macros in the error message

Hey All,

We have a slight problem with how a failed assert outputs its information in that it doesn’t tell you what a macro evaluated to at runtime. I have found where to fix it in the elixir codebase but was wondering if there is a reason it is like this and if a merge request would be considered.

To explain the issue here is an example message, and how I would like it to look after:

Now:

match (=) failed
The following variables were pinned:
b = 3
code: {@a, ^b} = {7, 3}
rhs: {7, 3}
stacktrace:
test/tally_test.exs:604: (test)

As you can see it does not tell me what @a ACTUALLY is just that it’s not 7. There are more complicated use cases where one might use macros in asserts where this would be an issue.

After (Alt. 1):

This I feel is wrong because @a isn’t actually a pinned variable at all.

match (=) failed
 The following variables were pinned:
   b  = 3
   @a = 1
 code: {@a, ^b} = {7, 3}
 rhs:  {7, 3}
 stacktrace:
   test/tally_test.exs:604: (test)

After (Alt. 2):

match (=) failed
 The following variables were pinned:
   b = 3
 code: {@a, ^b} = {7, 3}
 lhs: {1, 3}
 rhs:  {7, 3}
 stacktrace:
   test/tally_test.exs:604: (test)

After looking through the codebase it’s as simple as adding the expanded macro to the output of the assertions (an ‘expanded macro’ variable is already there in all cases).

This seems to be a problem with all variants of assert.

/Howard

1 Like