summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralisdair sullivan <alisdair.sullivan@askuity.com>2015-09-20 17:41:21 -0500
committeralisdair sullivan <alisdair.sullivan@askuity.com>2015-09-29 15:29:28 -0700
commit95716058650508f15fc1873e5ec34c08097217ca (patch)
treeb930cd5a207aed79d51f6652234cd45d3e668319
parent9e9c4212ce2c6b109bc1c027745bc2282df7977b (diff)
Revert "drop `eunit_first_files' and `eunit_compile_opts'. that's what"
This reverts commit dde60d491f64e8545c586d07015a466eb8e6e126.
-rw-r--r--rebar.config.sample4
-rw-r--r--src/rebar_prv_eunit.erl25
2 files changed, 27 insertions, 2 deletions
diff --git a/rebar.config.sample b/rebar.config.sample
index 43e7b62..de70998 100644
--- a/rebar.config.sample
+++ b/rebar.config.sample
@@ -157,6 +157,10 @@
{eunit_tests, [{application, rebar3}]}
%% Options for eunit:test(Tests, Opts)
{eunit_opts, [verbose]}.
+%% Additional compile options for eunit. erl_opts is also used
+{eunit_compile_opts, [{d, some_define}]}.
+%% {erl_first_files, ...} but for Eunit
+{eunit_first_files, ["test/test_behaviour.erl"]}.
%% == Overrides ==
diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl
index 4005098..b1c78b3 100644
--- a/src/rebar_prv_eunit.erl
+++ b/src/rebar_prv_eunit.erl
@@ -31,7 +31,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()),
+ State2 = rebar_state:add_to_profile(State1, test, test_state(State1)),
{ok, State2}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
@@ -89,7 +89,28 @@ format_error({error, Error}) ->
%% Internal functions
%% ===================================================================
-test_state() -> [{extra_src_dirs, ["test"]}, {erl_opts, [{d, 'TEST'}]}].
+test_state(State) ->
+ ErlOpts = rebar_state:get(State, eunit_compile_opts, []),
+ TestOpts = safe_define_test_macro(ErlOpts),
+ TestDir = [{extra_src_dirs, ["test"]}],
+ first_files(State) ++ [{erl_opts, TestOpts ++ TestDir}].
+
+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.
+
+test_defined([{d, 'TEST'}|_]) -> true;
+test_defined([{d, 'TEST', true}|_]) -> true;
+test_defined([_|Rest]) -> test_defined(Rest);
+test_defined([]) -> false.
+
+first_files(State) ->
+ EUnitFirst = rebar_state:get(State, eunit_first_files, []),
+ [{erl_first_files, EUnitFirst}].
prepare_tests(State) ->
{RawOpts, _} = rebar_state:command_parsed_args(State),