diff --git a/src/rebar_config.erl b/src/rebar_config.erl
index 461de5de..f2b80924 100644
--- a/src/rebar_config.erl
+++ b/src/rebar_config.erl
@@ -107,7 +107,14 @@ get_global(Config, Key, Default) ->
error ->
Default;
{ok, Value} ->
- Value
+ case string:to_lower(Value) of
+ "true" ->
+ true;
+ "false" ->
+ false;
+ _ ->
+ Value
+ end
end.
is_verbose(Config) ->
diff --git a/src/rebar_deps.erl b/src/rebar_deps.erl
index 5e4f482b..ae57420e 100644
--- a/src/rebar_deps.erl
+++ b/src/rebar_deps.erl
@@ -92,7 +92,7 @@ preprocess(Config, _) ->
%% Also, if skip_deps=comma,separated,app,list, then only the given
%% dependencies are skipped.
NewConfig = case rebar_config:get_global(Config3, skip_deps, false) of
- "true" ->
+ true ->
lists:foldl(
fun(#dep{dir = Dir}, C) ->
rebar_config:set_skip_dir(C, Dir)
@@ -106,7 +106,7 @@ preprocess(Config, _) ->
false -> C
end
end, Config3, AvailableDeps);
- _ ->
+ false ->
Config3
end,
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl
index d39b1a21..bb00e335 100644
--- a/src/rebar_eunit.erl
+++ b/src/rebar_eunit.erl
@@ -39,6 +39,16 @@
%%
Reset OTP application environment variables
%%
%%
+%% reset_after_each_eunit::boolean() - default = false.
+%% If true, try to "reset" VM state to approximate state prior to
+%% running each EUnit test in the contstructed list of tests:
+%%
+%% - Stop net_kernel if it was started
+%% - Stop OTP applications not running before EUnit tests were run
+%% - Kill processes not running before EUnit tests were run
+%% - Reset OTP application environment variables
+%%
+%%
%%
%% The following Global options are supported:
%%
@@ -164,19 +174,21 @@ run_eunit(Config, CodePath, SrcErls) ->
{ok, CoverLog} = cover_init(Config, ModuleBeamFiles),
StatusBefore = status_before_eunit(),
- EunitResult = perform_eunit(Config, Tests),
- perform_cover(Config, FilteredModules, SrcModules),
- cover_close(CoverLog),
+ DoClean = rebar_config:get_global(Config, reset_after_eunit, true),
- case proplists:get_value(reset_after_eunit, get_eunit_opts(Config),
- true) of
- true ->
- reset_after_eunit(StatusBefore);
+ EunitResult = case rebar_config:get_global(Config, reset_after_each_eunit, false) of
false ->
- ok
+ ?DEBUG("running all tests~n", []),
+ perform_eunit(Config, Tests, StatusBefore, DoClean);
+ true ->
+ ?DEBUG("running cleanup after each test~n", []),
+ [perform_eunit(Config, T, StatusBefore, true) || T <- Tests]
end,
+ perform_cover(Config, FilteredModules, SrcModules),
+ cover_close(CoverLog),
+
%% Stop cover to clean the cover_server state. This is important if we want
%% eunit+cover to not slow down when analyzing many Erlang modules.
ok = cover:stop(),
@@ -192,6 +204,11 @@ run_eunit(Config, CodePath, SrcErls) ->
true = code:set_path(CodePath),
ok.
+maybe_cleanup(_StatusBefore, false) ->
+ ok;
+maybe_cleanup(StatusBefore, true) ->
+ reset_after_eunit(StatusBefore).
+
ensure_dirs() ->
%% Make sure ?EUNIT_DIR/ and ebin/ directory exists (append dummy module)
ok = filelib:ensure_dir(filename:join(eunit_dir(), "dummy")),
@@ -391,18 +408,20 @@ pre15b02_eunit_primitive(generator, M, F) ->
%% == run tests ==
%%
-perform_eunit(Config, Tests) ->
+perform_eunit(Config, Tests, StatusBeforeEunit, DoClean) ->
EunitOpts = get_eunit_opts(Config),
%% Move down into ?EUNIT_DIR while we run tests so any generated files
%% are created there (versus in the source dir)
Cwd = rebar_utils:get_cwd(),
ok = file:set_cwd(?EUNIT_DIR),
-
+
+ ?DEBUG("running tests:~w with options:~w~n", [Tests, EunitOpts]),
EunitResult = (catch eunit:test(Tests, EunitOpts)),
%% Return to original working dir
ok = file:set_cwd(Cwd),
+ maybe_cleanup(StatusBeforeEunit, DoClean),
EunitResult.
@@ -417,6 +436,7 @@ get_eunit_opts(Config) ->
BaseOpts ++ rebar_config:get_list(Config, eunit_opts, []).
+
%%
%% == code coverage ==
%%