summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralisdair sullivan <alisdairsullivan@yahoo.ca>2015-10-30 01:24:18 -0700
committeralisdair sullivan <alisdairsullivan@yahoo.ca>2015-10-30 01:24:18 -0700
commit3fc51b912cb8a71cb48e7e21af96057b14a3828e (patch)
tree694de3dc0b47321c2f319af9a9ee4ba9d5a23c4a
parent12dbed831184a20c4a7764e10f155b60316a56eb (diff)
move test profile bootstrap into core
-rw-r--r--src/rebar3.erl23
-rw-r--r--src/rebar_prv_eunit.erl21
2 files changed, 23 insertions, 21 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index e55db71..2b73844 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -96,7 +96,7 @@ run(RawArgs) ->
run_aux(BaseState2, RawArgs).
run_aux(State, RawArgs) ->
- State2 = case os:getenv("REBAR_PROFILE") of
+ State1 = case os:getenv("REBAR_PROFILE") of
false ->
State;
"" ->
@@ -105,6 +105,9 @@ run_aux(State, RawArgs) ->
rebar_state:apply_profiles(State, [list_to_atom(Profile)])
end,
+ %% bootstrap test profile
+ State2 = rebar_state:add_to_profile(State1, test, test_state(State1)),
+
%% Process each command, resetting any state between each one
BaseDir = rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR),
State3 = rebar_state:set(State2, base_dir,
@@ -319,3 +322,21 @@ state_from_global_config(Config, GlobalConfigFile) ->
GlobalConfig2 = rebar_state:set(GlobalConfig, plugins, []),
GlobalConfig3 = rebar_state:set(GlobalConfig2, {plugins, global}, rebar_state:get(GlobalConfigThrowAway, plugins, [])),
rebar_state:providers(rebar_state:new(GlobalConfig3, Config), GlobalPlugins).
+
+test_state(State) ->
+ ErlOpts = rebar_state:get(State, erl_opts, []),
+ TestOpts = safe_define_test_macro(ErlOpts),
+ [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}].
+
+safe_define_test_macro(Opts) ->
+ %% defining a compile macro twice results in an exception so
+ %% make sure 'TEST' is only defined once
+ case test_defined(Opts) of
+ true -> [];
+ false -> [{d, 'TEST'}]
+ end.
+
+test_defined([{d, 'TEST'}|_]) -> true;
+test_defined([{d, 'TEST', true}|_]) -> true;
+test_defined([_|Rest]) -> test_defined(Rest);
+test_defined([]) -> false. \ No newline at end of file
diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl
index b748b06..2c687ac 100644
--- a/src/rebar_prv_eunit.erl
+++ b/src/rebar_prv_eunit.erl
@@ -34,8 +34,7 @@ init(State) ->
{opts, eunit_opts(State)},
{profiles, [test]}]),
State1 = rebar_state:add_provider(State, Provider),
- State2 = rebar_state:add_to_profile(State1, test, test_state(State1)),
- {ok, State2}.
+ {ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
@@ -103,19 +102,6 @@ format_error({error, Error}) ->
%% Internal functions
%% ===================================================================
-test_state(State) ->
- ErlOpts = rebar_state:get(State, erl_opts, []),
- TestOpts = safe_define_test_macro(ErlOpts),
- [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}].
-
-safe_define_test_macro(Opts) ->
- %% defining a compile macro twice results in an exception so
- %% make sure 'TEST' is only defined once
- case test_defined(Opts) of
- true -> Opts;
- false -> [{d, 'TEST'}] ++ Opts
- end.
-
compile(State, {ok, Tests}) ->
%% inject `eunit_first_files`, `eunit_compile_opts` and any
%% directories required by tests into the applications
@@ -191,11 +177,6 @@ inject_test_dir(Opts, Dir) ->
ExtraSrcDirs = rebar_opts:get(Opts, extra_src_dirs, []),
rebar_opts:set(Opts, extra_src_dirs, ExtraSrcDirs ++ [Dir]).
-test_defined([{d, 'TEST'}|_]) -> true;
-test_defined([{d, 'TEST', true}|_]) -> true;
-test_defined([_|Rest]) -> test_defined(Rest);
-test_defined([]) -> false.
-
prepare_tests(State) ->
%% parse and translate command line tests
CmdTests = resolve_tests(State),