From 4c32c52b557c66ac6e6764efb1ed9135c00a3c20 Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Wed, 2 Mar 2016 23:58:58 -0800 Subject: define the 'EUNIT' macro in the test profile --- src/rebar3.erl | 21 +++++++++++---------- test/rebar_profiles_SUITE.erl | 14 ++++++++++---- 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). -- cgit v1.1