@@ -114,8 +114,6 @@ defmodule ExUnit.DocTest do
114
114
115
115
defexception Error , message: nil
116
116
117
- defrecord Test , fun_arity: nil , line: nil , exprs: [ ]
118
-
119
117
@ doc """
120
118
This macro is used to generate ExUnit test cases for doctests.
121
119
@@ -189,15 +187,15 @@ defmodule ExUnit.DocTest do
189
187
{ test_name ( test , module , n ) , test_content ( test , module , do_import ) }
190
188
end
191
189
192
- defp test_name ( Test [ fun_arity : nil ] , m , n ) do
190
+ defp test_name ( % { fun_arity: nil } , m , n ) do
193
191
"moduledoc at #{ inspect m } (#{ n } )"
194
192
end
195
193
196
- defp test_name ( Test [ fun_arity : { f , a } ] , m , n ) do
194
+ defp test_name ( % { fun_arity: { f , a } } , m , n ) do
197
195
"doc at #{ inspect m } .#{ f } /#{ a } (#{ n } )"
198
196
end
199
197
200
- defp test_content ( Test [ exprs : exprs , line: line , fun_arity: fun_arity ] , module , do_import ) do
198
+ defp test_content ( % { exprs: exprs , line: line , fun_arity: fun_arity } , module , do_import ) do
201
199
file = module . __info__ ( :compile ) [ :source ] |> String . from_char_data!
202
200
location = [ line: line , file: Path . relative_to_cwd ( file ) ]
203
201
stack = Macro . escape [ { module , :__MODULE__ , 0 , location } ]
@@ -357,7 +355,7 @@ defmodule ExUnit.DocTest do
357
355
358
356
defp extract_from_doc ( { fa , line , _ , _ , doc } ) do
359
357
for test <- extract_tests ( line , doc ) do
360
- test . fun_arity ( fa )
358
+ % { test | fun_arity: fa }
361
359
end
362
360
end
363
361
@@ -441,21 +439,21 @@ defmodule ExUnit.DocTest do
441
439
end
442
440
443
441
# End of input and we've still got a test pending.
444
- defp extract_tests ( [ ] , _ , expr_acc , expected_acc , [ test = Test [ exprs : exprs ] | t ] , _ ) do
445
- test = test . exprs ( [ { expr_acc , { :test , expected_acc } } | exprs ] )
442
+ defp extract_tests ( [ ] , _ , expr_acc , expected_acc , [ test = % { exprs: exprs } | t ] , _ ) do
443
+ test = % { test | exprs: [ { expr_acc , { :test , expected_acc } } | exprs ] }
446
444
Enum . reverse ( reverse_last_test ( [ test | t ] ) )
447
445
end
448
446
449
447
# We've encountered the next test on an adjacent line. Put them into one group.
450
- defp extract_tests ( [ << "iex>" , _ :: binary >> | _ ] = list , line , expr_acc , expected_acc , [ test = Test [ exprs : exprs ] | t ] , newtest ) when expr_acc != "" and expected_acc != "" do
451
- test = test . exprs ( [ { expr_acc , { :test , expected_acc } } | exprs ] )
448
+ defp extract_tests ( [ << "iex>" , _ :: binary >> | _ ] = list , line , expr_acc , expected_acc , [ test = % { exprs: exprs } | t ] , newtest ) when expr_acc != "" and expected_acc != "" do
449
+ test = % { test | exprs: [ { expr_acc , { :test , expected_acc } } | exprs ] }
452
450
extract_tests ( list , line , "" , "" , [ test | t ] , newtest )
453
451
end
454
452
455
453
# Store expr_acc and start a new test case.
456
454
defp extract_tests ( [ << "iex>" , string :: binary >> | lines ] , line , "" , expected_acc , acc , true ) do
457
455
acc = reverse_last_test ( acc )
458
- test = Test [ line : line ]
456
+ test = % { line: line , fun_arity: nil , exprs: [ ] }
459
457
extract_tests ( lines , line , string , expected_acc , [ test | acc ] , false )
460
458
end
461
459
@@ -490,22 +488,22 @@ defmodule ExUnit.DocTest do
490
488
end
491
489
492
490
# Encountered an empty line, store pending test
493
- defp extract_tests ( [ "" | lines ] , line , expr_acc , expected_acc , [ test = Test [ exprs : exprs ] | t ] , _ ) do
494
- test = test . exprs ( [ { expr_acc , { :test , expected_acc } } | exprs ] )
491
+ defp extract_tests ( [ "" | lines ] , line , expr_acc , expected_acc , [ test = % { exprs: exprs } | t ] , _ ) do
492
+ test = % { test | exprs: [ { expr_acc , { :test , expected_acc } } | exprs ] }
495
493
extract_tests ( lines , line , "" , "" , [ test | t ] , true )
496
494
end
497
495
498
496
# Exception test.
499
- defp extract_tests ( [ << "** (" , string :: binary >> | lines ] , line , expr_acc , "" , [ test = Test [ exprs : exprs ] | t ] , newtest ) do
500
- test = test . exprs ( [ { expr_acc , extract_error ( string , "" ) } | exprs ] )
497
+ defp extract_tests ( [ << "** (" , string :: binary >> | lines ] , line , expr_acc , "" , [ test = % { exprs: exprs } | t ] , newtest ) do
498
+ test = % { test | exprs: [ { expr_acc , extract_error ( string , "" ) } | exprs ] }
501
499
extract_tests ( lines , line , "" , "" , [ test | t ] , newtest )
502
500
end
503
501
504
502
# Finally, parse expected_acc.
505
- defp extract_tests ( [ expected | lines ] , line , expr_acc , expected_acc , [ test = Test [ exprs : exprs ] | t ] = acc , newtest ) do
503
+ defp extract_tests ( [ expected | lines ] , line , expr_acc , expected_acc , [ test = % { exprs: exprs } | t ] = acc , newtest ) do
506
504
if expected =~ ~r/ ^#[A-Z][\w \. ]*<.*>$/ do
507
505
expected = expected_acc <> "\n " <> inspect ( expected )
508
- test = test . exprs ( [ { expr_acc , { :inspect , expected } } | exprs ] )
506
+ test = % { test | exprs: [ { expr_acc , { :inspect , expected } } | exprs ] }
509
507
extract_tests ( lines , line , "" , "" , [ test | t ] , newtest )
510
508
else
511
509
extract_tests ( lines , line , expr_acc , expected_acc <> "\n " <> expected , acc , newtest )
@@ -529,8 +527,8 @@ defmodule ExUnit.DocTest do
529
527
end
530
528
531
529
defp reverse_last_test ( [ ] ) , do: [ ]
532
- defp reverse_last_test ( [ test = Test [ exprs : exprs ] | t ] ) do
533
- test = test . exprs ( Enum . reverse ( exprs ) )
530
+ defp reverse_last_test ( [ test = % { exprs: exprs } | t ] ) do
531
+ test = % { test | exprs: Enum . reverse ( exprs ) }
534
532
[ test | t ]
535
533
end
536
534
end
0 commit comments