@@ -191,52 +191,40 @@ defmodule ExUnit.DocTest do
191
191
end
192
192
whole_expr = String . strip ( whole_expr )
193
193
194
- { exception , message } = case Enum . find ( exprs , exc_filter_fn ) do
194
+ exception = case Enum . find ( exprs , exc_filter_fn ) do
195
195
{ _ , { :error , exception , message } } ->
196
- { exception , message }
196
+ inspect ( exception ) <> "[ message: \" #{ message } \" ]"
197
197
nil ->
198
- { nil , nil }
198
+ "nothing"
199
199
end
200
200
201
201
quote do
202
202
unquote_splicing ( test_import ( module , do_import ) )
203
- unquote ( gen_code_for_tests ( tests , whole_expr , exception , message , stack ) )
203
+ unquote ( gen_code_for_tests ( tests , whole_expr , exception , stack ) )
204
204
end
205
205
end
206
206
207
- defp gen_code_for_tests ( tests , whole_expr , exception , message , stack ) do
207
+ defp gen_code_for_tests ( tests , whole_expr , exception , stack ) do
208
208
quote do
209
+ stack = unquote ( stack )
209
210
try do
210
211
# Put all tests into one context
211
212
unquote_splicing ( tests )
212
213
rescue
213
214
e in [ ExUnit.ExpectationError ] ->
214
- raise e , [ ] , unquote ( stack )
215
-
216
- # If there was no exception among the tests, `exception` here will be
217
- # nil and this clause won't match.
218
- error in [ unquote ( exception ) ] ->
219
- unless error . message == unquote ( message ) do
220
- raise ExUnit.ExpectationError ,
221
- [ prelude: "Expected doctest" ,
222
- description: unquote ( whole_expr ) ,
223
- expected: "#{ inspect unquote ( exception ) } with message #{ inspect unquote ( message ) } " ,
224
- reason: "raise" ,
225
- actual: inspect ( error ) ] ,
226
- unquote ( stack )
227
- end
215
+ raise e , [ ] , stack
228
216
229
217
error ->
230
218
raise ExUnit.ExpectationError ,
231
219
[ prelude: "Expected doctest" ,
232
220
description: unquote ( whole_expr ) ,
233
- expected: " #{ inspect unquote ( exception ) } " ,
221
+ expected: unquote ( exception ) ,
234
222
# We're using a combined message here because all expressions
235
223
# (those that are expected to raise and those that aren't) are in
236
224
# the same try block above.
237
225
reason: "complete or raise" ,
238
226
actual: inspect ( error ) ] ,
239
- unquote ( stack )
227
+ stack
240
228
end
241
229
end
242
230
end
@@ -261,18 +249,36 @@ defmodule ExUnit.DocTest do
261
249
end
262
250
end
263
251
264
- defp test_case_content ( expr , { :error , exception , _ } , module , line , file , stack ) do
252
+ defp test_case_content ( expr , { :error , exception , message } , module , line , file , stack ) do
265
253
expr_ast = string_to_ast ( module , line , file , expr )
266
254
267
255
quote do
268
- v = unquote ( expr_ast )
269
- raise ExUnit.ExpectationError ,
270
- [ prelude: "Expected doctest" ,
271
- description: unquote ( expr ) ,
272
- expected: "#{ inspect unquote ( exception ) } []" ,
273
- reason: "raise" ,
274
- actual: inspect ( v ) ] ,
275
- unquote ( stack )
256
+ stack = unquote ( stack )
257
+ expr = unquote ( expr )
258
+ exception = inspect ( unquote ( exception ) ) <> "[message: \" #{ unquote ( message ) } \" ]"
259
+ try do
260
+ v = unquote ( expr_ast )
261
+ raise ExUnit.ExpectationError ,
262
+ [ prelude: "Expected doctest" ,
263
+ description: expr ,
264
+ expected: exception ,
265
+ reason: "raise" ,
266
+ actual: inspect ( v ) ] ,
267
+ stack
268
+ rescue
269
+ error in [ unquote ( exception ) ] ->
270
+ unless error . message == unquote ( message ) do
271
+ raise ExUnit.ExpectationError ,
272
+ [ prelude: "Expected doctest" ,
273
+ description: expr ,
274
+ expected: exception ,
275
+ reason: "raise" ,
276
+ actual: inspect ( error ) ] ,
277
+ stack
278
+ end
279
+
280
+ other -> raise other
281
+ end
276
282
end
277
283
end
278
284
0 commit comments