@@ -160,9 +160,11 @@ defmodule ExUnit.DocTest do
160
160
:"test doc at #{ inspect m } .#{ f } /#{ a } (#{ n } )"
161
161
end
162
162
163
- defp test_content ( Test [ expected : { :ok , expected } ] = test , module , do_import ) do
163
+ defp test_content ( Test [ expected : { :test , expected } ] = test , module , do_import ) do
164
164
line = test . line
165
165
file = module . __info__ ( :compile ) [ :source ]
166
+ location = [ line: line , file: Path . relative_to ( file , System . cwd! ) ]
167
+ stack = Macro . escape [ { module , :__MODULE__ , 0 , location } ]
166
168
167
169
expr_ast = string_to_ast ( line , file , test . expr )
168
170
expected_ast = string_to_ast ( line , file , expected )
@@ -174,31 +176,25 @@ defmodule ExUnit.DocTest do
174
176
case unquote ( expr_ast ) do
175
177
^ v -> :ok
176
178
instead ->
177
- location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
178
- stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
179
179
raise ExUnit.ExpectationError ,
180
180
[ prelude: "Expected doctest" ,
181
181
expected: unquote ( test . expr ) ,
182
182
actual: inspect ( v ) ,
183
183
reason: "evaluate to" ,
184
184
instead: instead ] ,
185
- stack
185
+ unquote ( stack )
186
186
end
187
187
rescue
188
188
e in [ ExUnit.ExpectationError ] ->
189
- location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
190
- stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
191
- raise e , [ ] , stack
189
+ raise e , [ ] , unquote ( stack )
192
190
e ->
193
- location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
194
- stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
195
191
raise ExUnit.ExpectationError ,
196
192
[ prelude: "Expected doctest" ,
197
193
expected: unquote ( test . expr ) ,
198
194
actual: "without an exception" ,
199
195
reason: "complete" ,
200
196
instead: e ] ,
201
- stack
197
+ unquote ( stack )
202
198
end
203
199
end
204
200
if do_import do
@@ -213,46 +209,42 @@ defmodule ExUnit.DocTest do
213
209
defp test_content ( Test [ expected : { :error , exception , message } ] = test , module , do_import ) do
214
210
line = test . line
215
211
file = module . __info__ ( :compile ) [ :source ]
212
+ location = [ line: line , file: Path . relative_to ( file , System . cwd! ) ]
213
+ stack = Macro . escape [ { module , :__MODULE__ , 0 , location } ]
216
214
217
215
expr_ast = string_to_ast ( line , file , test . expr )
218
216
219
217
quoted =
220
218
quote do
221
219
try do
222
220
v = unquote ( expr_ast )
223
- location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
224
- stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
225
221
raise ExUnit.ExpectationError ,
226
222
[ prelude: "Expected doctest" ,
227
223
expected: unquote ( test . expr ) ,
228
224
actual: "by raising #{ inspect unquote ( exception ) } exception" ,
229
225
reason: "terminate" ,
230
226
instead: v ] ,
231
- stack
227
+ unquote ( stack )
232
228
rescue
233
229
e in [ ExUnit.ExpectationError ] -> raise ( e )
234
230
error in [ unquote ( exception ) ] ->
235
231
unless error . message == unquote ( message ) do
236
- location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
237
- stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
238
232
raise ExUnit.ExpectationError ,
239
233
[ prelude: "Expected doctest" ,
240
234
expected: unquote ( test . expr ) ,
241
235
actual: "by raising #{ inspect unquote ( exception ) } exception with a #{ inspect unquote ( message ) } message" ,
242
236
reason: "terminate" ,
243
237
instead: error ] ,
244
- stack
238
+ unquote ( stack )
245
239
end
246
240
error ->
247
- location = [ line: unquote ( line ) , file: Path . relative_to ( unquote ( file ) , System . cwd! ) ]
248
- stack = [ { unquote ( module ) , :__MODULE__ , 0 , location } ]
249
241
raise ExUnit.ExpectationError ,
250
242
[ prelude: "Expected doctest" ,
251
243
expected: unquote ( test . expr ) ,
252
244
actual: "by raising #{ inspect unquote ( exception ) } " ,
253
245
reason: "terminate" ,
254
246
instead: error ] ,
255
- stack
247
+ unquote ( stack )
256
248
end
257
249
end
258
250
if do_import do
@@ -306,12 +298,12 @@ defmodule ExUnit.DocTest do
306
298
defp extract_tests ( [ ] , _line , "" , "" , acc ) , do: Enum . reverse ( acc )
307
299
308
300
defp extract_tests ( [ ] , line , expr_acc , expected_acc , acc ) do
309
- test = Test [ expr : expr_acc , line: line , expected: { :ok , expected_acc } ]
301
+ test = Test [ expr : expr_acc , line: line , expected: { :test , expected_acc } ]
310
302
Enum . reverse ( [ test | acc ] )
311
303
end
312
304
313
305
defp extract_tests( [ << "iex>" , _ :: binary >> | _ ] = list , line, expr_acc, expected_acc, acc) when expr_acc != "" and expected_acc != "" do
314
- test = Test [ expr : expr_acc , line: line , expected: { :ok , expected_acc } ]
306
+ test = Test [ expr : expr_acc , line: line , expected: { :test , expected_acc } ]
315
307
extract_tests ( list , line , "" , "" , [ test | acc ] )
316
308
end
317
309
@@ -340,7 +332,7 @@ defmodule ExUnit.DocTest do
340
332
end
341
333
342
334
defp extract_tests( [ "" | lines ] , line, expr_acc, expected_acc, acc) do
343
- test = Test [ expr : expr_acc , line: line , expected: { :ok , expected_acc } ]
335
+ test = Test [ expr : expr_acc , line: line , expected: { :test , expected_acc } ]
344
336
extract_tests ( lines , line , "" , "" , [ test | acc ] )
345
337
end
346
338
0 commit comments