From 0bd5e230d2689831cad1427287f3ecc62482dc1e Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Thu, 3 Mar 2016 17:39:17 -0800 Subject: move definition of 'EUNIT' macro to eunit provider add definition of 'COMMON_TEST' macro to eunit provider --- src/rebar_prv_eunit.erl | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/rebar_prv_eunit.erl') 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. -- cgit v1.1