Skip to content

Commit 7149878

Browse files
committed
initial checkin
fixed type and case statement ordering removed unecessary ?DEBUG statement
1 parent aa46d85 commit 7149878

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

src/rebar_eunit.erl

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,16 @@
3939
%% <li>Reset OTP application environment variables</li>
4040
%% </ul>
4141
%% </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>
4252
%% </ul>
4353
%% The following Global options are supported:
4454
%% <ul>
@@ -164,19 +174,20 @@ run_eunit(Config, CodePath, SrcErls) ->
164174
{ok, CoverLog} = cover_init(Config, ModuleBeamFiles),
165175

166176
StatusBefore = status_before_eunit(),
167-
EunitResult = perform_eunit(Config, Tests),
168-
169-
perform_cover(Config, FilteredModules, SrcModules),
170-
cover_close(CoverLog),
171177

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
176180
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]
178186
end,
179187

188+
perform_cover(Config, FilteredModules, SrcModules),
189+
cover_close(CoverLog),
190+
180191
%% Stop cover to clean the cover_server state. This is important if we want
181192
%% eunit+cover to not slow down when analyzing many Erlang modules.
182193
ok = cover:stop(),
@@ -192,6 +203,14 @@ run_eunit(Config, CodePath, SrcErls) ->
192203
true = code:set_path(CodePath),
193204
ok.
194205

206+
maybe_cleanup(StatusBefore, DoClean) ->
207+
case DoClean of
208+
true ->
209+
reset_after_eunit(StatusBefore);
210+
false ->
211+
ok
212+
end.
213+
195214
ensure_dirs() ->
196215
%% Make sure ?EUNIT_DIR/ and ebin/ directory exists (append dummy module)
197216
ok = filelib:ensure_dir(filename:join(eunit_dir(), "dummy")),
@@ -391,18 +410,20 @@ pre15b02_eunit_primitive(generator, M, F) ->
391410
%% == run tests ==
392411
%%
393412

394-
perform_eunit(Config, Tests) ->
413+
perform_eunit(Config, Tests, StatusBeforeEunit, DoClean) ->
395414
EunitOpts = get_eunit_opts(Config),
396415

397416
%% Move down into ?EUNIT_DIR while we run tests so any generated files
398417
%% are created there (versus in the source dir)
399418
Cwd = rebar_utils:get_cwd(),
400419
ok = file:set_cwd(?EUNIT_DIR),
401-
420+
421+
?DEBUG("running tests:~w with options:~w~n", [Tests, EunitOpts]),
402422
EunitResult = (catch eunit:test(Tests, EunitOpts)),
403423

404424
%% Return to original working dir
405425
ok = file:set_cwd(Cwd),
426+
maybe_cleanup(StatusBeforeEunit, DoClean),
406427

407428
EunitResult.
408429

@@ -417,6 +438,7 @@ get_eunit_opts(Config) ->
417438

418439
BaseOpts ++ rebar_config:get_list(Config, eunit_opts, []).
419440

441+
420442
%%
421443
%% == code coverage ==
422444
%%

0 commit comments

Comments
 (0)