summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTristan Sloughter <t@crashfast.com>2016-03-03 10:02:51 -0600
committerTristan Sloughter <t@crashfast.com>2016-03-03 10:02:51 -0600
commit33011a2779a9ebe411c283f2e6753b2ae7c2671c (patch)
tree4d7db9889f517bcd99d628dcb7a10889d756e5d8
parente389238d8abffb2f345c715a3c4d29622114cad3 (diff)
parent4c32c52b557c66ac6e6764efb1ed9135c00a3c20 (diff)
Merge pull request #1106 from talentdeficit/EUNIT
define the 'EUNIT' macro in the test profile
-rw-r--r--src/rebar3.erl21
-rw-r--r--test/rebar_profiles_SUITE.erl14
2 files changed, 21 insertions, 14 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index c1a1ae4..ab7d35a 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -337,18 +337,19 @@ state_from_global_config(Config, GlobalConfigFile) ->
test_state(State) ->
ErlOpts = rebar_state:get(State, erl_opts, []),
- TestOpts = safe_define_test_macro(ErlOpts),
- [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}].
+ TestOpts = safe_define_test_macro(ErlOpts, 'TEST'),
+ MoreTestOpts = safe_define_test_macro(ErlOpts, 'EUNIT'),
+ [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts ++ MoreTestOpts}].
-safe_define_test_macro(Opts) ->
+safe_define_test_macro(Opts, Macro) ->
%% defining a compile macro twice results in an exception so
- %% make sure 'TEST' is only defined once
- case test_defined(Opts) of
+ %% make sure 'TEST' or 'EUNIT' is only defined once
+ case test_defined(Opts, Macro) of
true -> [];
- false -> [{d, 'TEST'}]
+ false -> [{d, Macro}]
end.
-test_defined([{d, 'TEST'}|_]) -> true;
-test_defined([{d, 'TEST', true}|_]) -> true;
-test_defined([_|Rest]) -> test_defined(Rest);
-test_defined([]) -> false.
+test_defined([{d, Macro}|_], Macro) -> true;
+test_defined([{d, Macro, true}|_], Macro) -> true;
+test_defined([_|Rest], Macro) -> test_defined(Rest, Macro);
+test_defined([], _) -> false.
diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl
index a31a4c9..fb7b140 100644
--- a/test/rebar_profiles_SUITE.erl
+++ b/test/rebar_profiles_SUITE.erl
@@ -377,7 +377,8 @@ test_profile_applied_at_completion(Config) ->
[App] = rebar_state:project_apps(State),
ErlOpts = rebar_app_info:get(App, erl_opts),
- true = lists:member({d, 'TEST'}, ErlOpts).
+ true = lists:member({d, 'TEST'}, ErlOpts),
+ true = lists:member({d, 'EUNIT'}, ErlOpts).
test_profile_applied_before_compile(Config) ->
AppDir = ?config(apps, Config),
@@ -393,7 +394,9 @@ test_profile_applied_before_compile(Config) ->
code:add_paths(rebar_state:code_paths(State, all_deps)),
S = list_to_atom("not_a_real_src_" ++ Name),
- true = lists:member({d, 'TEST'}, proplists:get_value(options, S:module_info(compile), [])).
+ Opts = proplists:get_value(options, S:module_info(compile), []),
+ true = lists:member({d, 'TEST'}, Opts),
+ true = lists:member({d, 'EUNIT'}, Opts).
test_profile_applied_before_eunit(Config) ->
AppDir = ?config(apps, Config),
@@ -409,7 +412,9 @@ test_profile_applied_before_eunit(Config) ->
code:add_paths(rebar_state:code_paths(State, all_deps)),
T = list_to_atom("not_a_real_src_" ++ Name ++ "_tests"),
- true = lists:member({d, 'TEST'}, proplists:get_value(options, T:module_info(compile), [])).
+ Opts = proplists:get_value(options, T:module_info(compile), []),
+ true = lists:member({d, 'TEST'}, Opts),
+ true = lists:member({d, 'EUNIT'}, Opts).
test_profile_applied_to_apps(Config) ->
AppDir = ?config(apps, Config),
@@ -430,5 +435,6 @@ test_profile_applied_to_apps(Config) ->
lists:foreach(fun(App) ->
Opts = rebar_app_info:opts(App),
ErlOpts = dict:fetch(erl_opts, Opts),
- true = lists:member({d, 'TEST'}, ErlOpts)
+ true = lists:member({d, 'TEST'}, ErlOpts),
+ true = lists:member({d, 'EUNIT'}, ErlOpts)
end, Apps).