summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2016-03-03 21:48:24 -0500
committerFred Hebert <mononcqc@ferd.ca>2016-03-03 21:48:24 -0500
commitb47839e18b84e4479ad918f6d8a72c7fe861d2e8 (patch)
tree4dc24ffa4d7e9e35011cb816a5923120758d8602 /src
parent925ecefc12fffd4075f5dd6d1a9c31ae07610e9b (diff)
parent0bd5e230d2689831cad1427287f3ecc62482dc1e (diff)
Merge pull request #1108 from talentdeficit/make_omar_happy
make omar happy
Diffstat (limited to 'src')
-rw-r--r--src/rebar3.erl21
-rw-r--r--src/rebar_prv_common_test.erl20
-rw-r--r--src/rebar_prv_eunit.erl20
3 files changed, 48 insertions, 13 deletions
diff --git a/src/rebar3.erl b/src/rebar3.erl
index ab7d35a..c1a1ae4 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -337,19 +337,18 @@ state_from_global_config(Config, GlobalConfigFile) ->
test_state(State) ->
ErlOpts = rebar_state:get(State, erl_opts, []),
- TestOpts = safe_define_test_macro(ErlOpts, 'TEST'),
- MoreTestOpts = safe_define_test_macro(ErlOpts, 'EUNIT'),
- [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts ++ MoreTestOpts}].
+ TestOpts = safe_define_test_macro(ErlOpts),
+ [{extra_src_dirs, ["test"]}, {erl_opts, TestOpts}].
-safe_define_test_macro(Opts, Macro) ->
+safe_define_test_macro(Opts) ->
%% defining a compile macro twice results in an exception so
- %% make sure 'TEST' or 'EUNIT' is only defined once
- case test_defined(Opts, Macro) of
+ %% make sure 'TEST' is only defined once
+ case test_defined(Opts) of
true -> [];
- false -> [{d, Macro}]
+ false -> [{d, 'TEST'}]
end.
-test_defined([{d, Macro}|_], Macro) -> true;
-test_defined([{d, Macro, true}|_], Macro) -> true;
-test_defined([_|Rest], Macro) -> test_defined(Rest, Macro);
-test_defined([], _) -> false.
+test_defined([{d, 'TEST'}|_]) -> true;
+test_defined([{d, 'TEST', true}|_]) -> true;
+test_defined([_|Rest]) -> test_defined(Rest);
+test_defined([]) -> false.
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 784b682..6b94f79 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -329,9 +329,27 @@ include_files(Opts, Tests) ->
Is = lists:map(fun(I) -> {i, I} end, Includes),
case append(Is, ErlOpts) of
{error, _} = Error -> Error;
- NewIncludes -> rebar_opts:set(Opts, erl_opts, NewIncludes)
+ NewIncludes -> ct_macro(rebar_opts:set(Opts, erl_opts, NewIncludes))
end.
+ct_macro(Opts) ->
+ ErlOpts = opts(Opts, erl_opts, []),
+ NewOpts = safe_define_ct_macro(ErlOpts),
+ rebar_opts:set(Opts, erl_opts, NewOpts).
+
+safe_define_ct_macro(Opts) ->
+ %% defining a compile macro twice results in an exception so
+ %% make sure 'COMMON_TEST' is only defined once
+ case test_defined(Opts) of
+ true -> Opts;
+ false -> [{d, 'COMMON_TEST'}|Opts]
+ end.
+
+test_defined([{d, 'COMMON_TEST'}|_]) -> true;
+test_defined([{d, 'COMMON_TEST', true}|_]) -> true;
+test_defined([_|Rest]) -> test_defined(Rest);
+test_defined([]) -> false.
+
append({error, _} = Error, _) -> Error;
append(_, {error, _} = Error) -> Error;
append(A, B) -> A ++ B.
diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl
index c085ee4..46ea48d 100644
--- a/src/rebar_prv_eunit.erl
+++ b/src/rebar_prv_eunit.erl
@@ -244,9 +244,27 @@ first_files(Opts) ->
EUnitFirstFiles = opts(Opts, eunit_first_files, []),
case append(EUnitFirstFiles, FirstFiles) of
{error, _} = Error -> Error;
- NewFirstFiles -> rebar_opts:set(Opts, erl_first_files, NewFirstFiles)
+ NewFirstFiles -> eunit_macro(rebar_opts:set(Opts, erl_first_files, NewFirstFiles))
end.
+eunit_macro(Opts) ->
+ ErlOpts = opts(Opts, erl_opts, []),
+ NewOpts = safe_define_eunit_macro(ErlOpts),
+ rebar_opts:set(Opts, erl_opts, NewOpts).
+
+safe_define_eunit_macro(Opts) ->
+ %% defining a compile macro twice results in an exception so
+ %% make sure 'EUNIT' is only defined once
+ case test_defined(Opts) of
+ true -> Opts;
+ false -> [{d, 'EUNIT'}|Opts]
+ end.
+
+test_defined([{d, 'EUNIT'}|_]) -> true;
+test_defined([{d, 'EUNIT', true}|_]) -> true;
+test_defined([_|Rest]) -> test_defined(Rest);
+test_defined([]) -> false.
+
append({error, _} = Error, _) -> Error;
append(_, {error, _} = Error) -> Error;
append(A, B) -> A ++ B.