@@ -2,28 +2,24 @@ defmodule Mix.Tasks.Test do
22 defmodule Cover do
33 @ moduledoc false
44
5- def run ( compile_path , opts , callback ) do
6- Mix . shell . info "Cover compiling modules ...\n "
5+ def start ( compile_path , opts ) do
6+ Mix . shell . info "Cover compiling modules ... "
77 :cover . start
88 :cover . compile_beam_directory ( compile_path |> to_char_list )
99
10- output = opts [ :output ]
11- callback . ( )
10+ if :application . get_env ( :cover , :started ) != { :ok , true } do
11+ output = opts [ :output ]
1212
13- Mix . shell . info " \n Generating cover results ..."
14- File . mkdir_p! ( output )
15- Enum . each :cover . modules , fn ( mod ) ->
16- :cover . analyse_to_file ( mod , ' #{ output } / #{ mod } .html' , [ :html ] )
17- end
18- end
19- end
13+ System . at_exit fn ( _ ) ->
14+ Mix . shell . info " \n Generating cover results ... "
15+ File . mkdir_p! ( output )
16+ Enum . each :cover . modules , fn ( mod ) ->
17+ :cover . analyse_to_file ( mod , ' #{ output } / #{ mod } .html' , [ :html ] )
18+ end
19+ end
2020
21- defmodule Bare do
22- @ moduledoc false
23-
24- def run ( _ , _ , fun ) do
25- Mix . shell . info ""
26- fun . ( )
21+ :application . set_env ( :cover , :started , true )
22+ end
2723 end
2824 end
2925
@@ -75,8 +71,8 @@ defmodule Mix.Tasks.Test do
7571
7672 test_coverage: [tool: CoverModule]
7773
78- `CoverModule` can be any module that exports `run/3 `, receiving the
79- compilation path, `test_coverage` options and the callback function as arguments.
74+ `CoverModule` can be any module that exports `start/2 `, receiving the
75+ compilation path and the `test_coverage` options as arguments.
8076 """
8177
8278 @ switches [ force: :boolean , color: :boolean , cover: :boolean ,
@@ -96,11 +92,13 @@ defmodule Mix.Tasks.Test do
9692
9793 project = Mix . project
9894 cover = Keyword . merge ( @ cover , project [ :test_coverage ] || [ ] )
99- wrapper = if opts [ :cover ] , do: cover [ :tool ] , else: Bare
95+
96+ if opts [ :cover ] do
97+ cover [ :tool ] . start ( project [ :compile_path ] , cover )
98+ end
10099
101100 :application . load ( :ex_unit )
102101 opts = Dict . take ( opts , [ :trace , :max_cases , :color ] )
103- opts = Keyword . put ( opts , :autorun , false )
104102 ExUnit . configure ( opts )
105103
106104 test_paths = project [ :test_paths ] || [ "test" ]
@@ -109,20 +107,8 @@ defmodule Mix.Tasks.Test do
109107 test_paths = if files == [ ] , do: test_paths , else: files
110108 test_pattern = project [ :test_pattern ] || "*_test.exs"
111109
112- wrapper . run project [ :compile_path ] , cover , fn -> do_run ( test_paths , test_pattern ) end
113- end
114-
115- defp do_run ( test_paths , test_pattern ) do
116110 files = Mix.Utils . extract_files ( test_paths , test_pattern )
117- Kernel.ParallelRequire . files ( files )
118-
119- failures = ExUnit . run
120- System . at_exit fn
121- 0 ->
122- if failures > 0 , do: System . halt ( 1 ) , else: System . halt ( 0 )
123- _ ->
124- :ok
125- end
111+ Kernel.ParallelRequire . files files
126112 end
127113
128114 defp require_test_helper ( dir ) do
0 commit comments