@@ -106,9 +106,6 @@ defmodule ExUnit.Assertions do
106
106
defmacro assert ( { := , meta , [ left , right ] } = assertion ) do
107
107
code = escape_quoted ( :assert , meta , assertion )
108
108
109
- # If the match works, we need to check if the value
110
- # is not nil nor false. We need to rewrite the if
111
- # to avoid silly dialyzer warnings though.
112
109
check =
113
110
quote generated: true do
114
111
if right do
@@ -151,15 +148,13 @@ defmodule ExUnit.Assertions do
151
148
{ args , value } = extract_args ( assertion , __CALLER__ )
152
149
153
150
quote generated: true do
154
- case unquote ( value ) do
155
- value when value in [ nil , false ] ->
156
- raise ExUnit.AssertionError ,
157
- args: unquote ( args ) ,
158
- expr: unquote ( escape_quoted ( :assert , [ ] , assertion ) ) ,
159
- message: "Expected truthy, got #{ inspect ( value ) } "
160
-
161
- value ->
162
- value
151
+ if value = unquote ( value ) do
152
+ value
153
+ else
154
+ raise ExUnit.AssertionError ,
155
+ args: unquote ( args ) ,
156
+ expr: unquote ( escape_quoted ( :assert , [ ] , assertion ) ) ,
157
+ message: "Expected truthy, got #{ inspect ( value ) } "
163
158
end
164
159
end
165
160
end
@@ -213,18 +208,14 @@ defmodule ExUnit.Assertions do
213
208
else
214
209
{ args , value } = extract_args ( assertion , __CALLER__ )
215
210
216
- # if value, raise
217
- # We need to rewrite it to avoid dialyzer warnings though.
218
211
quote generated: true do
219
- case unquote ( value ) do
220
- value when value in [ nil , false ] ->
221
- value
222
-
223
- value ->
224
- raise ExUnit.AssertionError ,
225
- args: unquote ( args ) ,
226
- expr: unquote ( escape_quoted ( :refute , [ ] , assertion ) ) ,
227
- message: "Expected false or nil, got #{ inspect ( value ) } "
212
+ if value = unquote ( value ) do
213
+ raise ExUnit.AssertionError ,
214
+ args: unquote ( args ) ,
215
+ expr: unquote ( escape_quoted ( :refute , [ ] , assertion ) ) ,
216
+ message: "Expected false or nil, got #{ inspect ( value ) } "
217
+ else
218
+ value
228
219
end
229
220
end
230
221
end
0 commit comments