浏览代码

define the 'EUNIT' macro in the test profile

pull/1106/head
alisdair sullivan 9 年前
父节点
当前提交
4c32c52b55
共有 2 个文件被更改,包括 21 次插入14 次删除
  1. +11
    -10
      src/rebar3.erl
  2. +10
    -4
      test/rebar_profiles_SUITE.erl

+ 11
- 10
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.

+ 10
- 4
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).

正在加载...
取消
保存