39
39
% % <li>Reset OTP application environment variables</li>
40
40
% % </ul>
41
41
% % </li>
42
+ % % <li>reset_after_each_eunit::boolean() - default = false.
43
+ % % If true, try to "reset" VM state to approximate state prior to
44
+ % % running each EUnit test in the contstructed list of tests:
45
+ % % <ul>
46
+ % % <li>Stop net_kernel if it was started</li>
47
+ % % <li>Stop OTP applications not running before EUnit tests were run</li>
48
+ % % <li>Kill processes not running before EUnit tests were run</li>
49
+ % % <li>Reset OTP application environment variables</li>
50
+ % % </ul>
51
+ % % </li>
42
52
% % </ul>
43
53
% % The following Global options are supported:
44
54
% % <ul>
@@ -164,19 +174,20 @@ run_eunit(Config, CodePath, SrcErls) ->
164
174
{ok , CoverLog } = cover_init (Config , ModuleBeamFiles ),
165
175
166
176
StatusBefore = status_before_eunit (),
167
- EunitResult = perform_eunit (Config , Tests ),
168
-
169
- perform_cover (Config , FilteredModules , SrcModules ),
170
- cover_close (CoverLog ),
171
177
172
- case proplists :get_value (reset_after_eunit , get_eunit_opts (Config ),
173
- true ) of
174
- true ->
175
- reset_after_eunit (StatusBefore );
178
+ DoClean = rebar_config :get_global (Config , reset_after_eunit , true ),
179
+ EunitResult = case rebar_config :get_global (Config , reset_after_each_eunit , false ) of
176
180
false ->
177
- ok
181
+ ? DEBUG (" running all tests" , []),
182
+ perform_eunit (Config , Tests , StatusBefore , DoClean );
183
+ _IsTrue ->
184
+ ? DEBUG (" running cleanup after each test" , []),
185
+ [perform_eunit (Config , T , StatusBefore , true ) || T <- Tests ]
178
186
end ,
179
187
188
+ perform_cover (Config , FilteredModules , SrcModules ),
189
+ cover_close (CoverLog ),
190
+
180
191
% % Stop cover to clean the cover_server state. This is important if we want
181
192
% % eunit+cover to not slow down when analyzing many Erlang modules.
182
193
ok = cover :stop (),
@@ -192,6 +203,14 @@ run_eunit(Config, CodePath, SrcErls) ->
192
203
true = code :set_path (CodePath ),
193
204
ok .
194
205
206
+ maybe_cleanup (StatusBefore , DoClean ) ->
207
+ case DoClean of
208
+ true ->
209
+ reset_after_eunit (StatusBefore );
210
+ false ->
211
+ ok
212
+ end .
213
+
195
214
ensure_dirs () ->
196
215
% % Make sure ?EUNIT_DIR/ and ebin/ directory exists (append dummy module)
197
216
ok = filelib :ensure_dir (filename :join (eunit_dir (), " dummy" )),
@@ -391,18 +410,20 @@ pre15b02_eunit_primitive(generator, M, F) ->
391
410
% % == run tests ==
392
411
% %
393
412
394
- perform_eunit (Config , Tests ) ->
413
+ perform_eunit (Config , Tests , StatusBeforeEunit , DoClean ) ->
395
414
EunitOpts = get_eunit_opts (Config ),
396
415
397
416
% % Move down into ?EUNIT_DIR while we run tests so any generated files
398
417
% % are created there (versus in the source dir)
399
418
Cwd = rebar_utils :get_cwd (),
400
419
ok = file :set_cwd (? EUNIT_DIR ),
401
-
420
+
421
+ ? DEBUG (" running tests:~w with options:~w~n " , [Tests , EunitOpts ]),
402
422
EunitResult = (catch eunit :test (Tests , EunitOpts )),
403
423
404
424
% % Return to original working dir
405
425
ok = file :set_cwd (Cwd ),
426
+ maybe_cleanup (StatusBeforeEunit , DoClean ),
406
427
407
428
EunitResult .
408
429
@@ -417,6 +438,7 @@ get_eunit_opts(Config) ->
417
438
418
439
BaseOpts ++ rebar_config :get_list (Config , eunit_opts , []).
419
440
441
+
420
442
% %
421
443
% % == code coverage ==
422
444
% %
0 commit comments