@@ -213,8 +213,41 @@ defmodule ExUnit.DocTest do
213
213
214
214
quoted =
215
215
quote do
216
- assert_raise unquote ( exception ) , unquote ( message ) , fn ->
217
- unquote ( expr_ast )
216
+ try do
217
+ v = unquote ( expr_ast )
218
+ location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
219
+ stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
220
+ raise ExUnit.ExpectationError ,
221
+ [ prelude: "Expected doctest" ,
222
+ expected: unquote ( test . expr ) ,
223
+ actual: "by raising #{ inspect unquote ( exception ) } exception" ,
224
+ reason: "terminate" ,
225
+ instead: v ] ,
226
+ stack
227
+ rescue
228
+ e in [ ExUnit.ExpectationError ] -> raise ( e )
229
+ error in [ unquote ( exception ) ] ->
230
+ unless error . message == unquote ( message ) do
231
+ location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
232
+ stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
233
+ raise ExUnit.ExpectationError ,
234
+ [ prelude: "Expected doctest" ,
235
+ expected: unquote ( test . expr ) ,
236
+ actual: "by raising #{ inspect unquote ( exception ) } exception with a #{ inspect unquote ( message ) } message" ,
237
+ reason: "terminate" ,
238
+ instead: error ] ,
239
+ stack
240
+ end
241
+ error ->
242
+ location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
243
+ stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
244
+ raise ExUnit.ExpectationError ,
245
+ [ prelude: "Expected doctest" ,
246
+ expected: unquote ( test . expr ) ,
247
+ actual: "by raising #{ inspect unquote ( exception ) } " ,
248
+ reason: "terminate" ,
249
+ instead: error ] ,
250
+ stack
218
251
end
219
252
end
220
253
if do_import do
0 commit comments