Closed azizk closed 3 years ago
Shouldn't match assertions raise ExUnit.AssertionError
instead of a regular MatchError
?
The same happens with refute/2. It works this way because they're just functions, not macros as assert. I ain't sure if this is a bug, but if it is, it should be easy to fix making those functions macros. If this is indeed a bug and nobody wants it, I can take it :)
After checking the APIs, this behaviour is correct. assert/1
is macro based and assert/2
simply executes the first argument, without doing any macro manipulation. You can do assert match?(...), "message"
in your case. I will add an example to the docs.
Okay, but why not do the same macro manipulation in assert/2
? I was hoping to get the comparison between the left and right-hand side and the highlighting of keys if it's a map, but with match?(...)
you won't see that...
@azizk you will see that if match?(...)
, you won't see that with assert/2
. Once you pass your own message, then it means you are replacing the message ExUnit generates (which is the one with the diff).
@jose Yeah, I meant match?
with assert/2
. Now I see that you intend the message to be a complete replacement. In that sense it's working correctly. But maybe you'd like to reconsider because it would seem more consistent with assert/1
, if assert/2
also printed a detailed AssertionError
where the custom message is used. Moreover there's no easy way to print the left and right-hand side expressions in your custom message and if there was it would be tedious and impractical to do so.
I just noticed some code in the module that looks like this case was planned, or maybe it was left in unintentionally:
_ ->
left = unquote(Macro.escape(left))
message =
(message || "match (=) failed") <>
ExUnit.Assertions.__pins__(unquote(pins))
@josevalim Never mind the code I posted above. That was just an attempt I made some time ago. :)
Environment
Current behavior
The assertion fails but doesn't display the provided message.
It's displayed if you use "==" for example.
Comparison with assert without message.
Expected behavior