浏览代码

warn on incorrectly specified test options in `rebar.config`

when `ct_opts`, `eunit_tests`, `eunit_first_files`, `ct_first_files`, `erl_first_files`,
`eunit_compile_opts`, `ct_compile_opts` and `erl_opts` have values that are single non-list
terms warn and try wrapping them in a list when processing them in the `eunit` and `ct`
providers
pull/922/head
alisdair sullivan 9 年前
父节点
当前提交
aea9809bdb
共有 2 个文件被更改,包括 47 次插入14 次删除
  1. +21
    -6
      src/rebar_prv_common_test.erl
  2. +26
    -8
      src/rebar_prv_eunit.erl

+ 21
- 6
src/rebar_prv_common_test.erl 查看文件

@ -151,8 +151,15 @@ split_string(String) ->
string:tokens(String, [$,]).
cfgopts(State) ->
Opts = rebar_state:get(State, ct_opts, []),
add_hooks(rebar_utils:filtermap(fun filter_opts/1, Opts), State).
case rebar_state:get(State, ct_opts, []) of
Opts when is_list(Opts) ->
add_hooks(rebar_utils:filtermap(fun filter_opts/1, Opts), State);
Wrong ->
%% probably a single non list term, try wrapping it in a list and
%% continuing
?WARN("Value `~p' of option `ct_opts' is not a list, trying to adjust and continue", [Wrong]),
add_hooks(rebar_utils:filtermap(fun filter_opts/1, [Wrong]), State)
end.
filter_opts({test_spec, _}) ->
?WARN("Test specs not supported", []),
@ -258,14 +265,22 @@ inject_ct_state(State, Tests) ->
NewState = rebar_state:opts(State, NewOpts),
test_dirs(NewState, ModdedApps, Tests).
opts(Opts, Key, Default) ->
case rebar_opts:get(Opts, Key, Default) of
Vs when is_list(Vs) -> Vs;
Wrong ->
?WARN("Value `~p' of option `~p' is not a list, trying to adjust and continue", [Wrong, Key]),
[Wrong]
end.
inject(Opts, State) ->
%% append `ct_compile_opts` to app defined `erl_opts`
ErlOpts = rebar_opts:get(Opts, erl_opts, []),
CTOpts = rebar_state:get(State, ct_compile_opts, []),
ErlOpts = opts(Opts, erl_opts, []),
CTOpts = opts(Opts, ct_compile_opts, []),
NewErlOpts = add_transforms(CTOpts, State) ++ ErlOpts,
%% append `ct_first_files` to app defined `erl_first_files`
FirstFiles = rebar_opts:get(Opts, erl_first_files, []),
CTFirstFiles = rebar_state:get(State, ct_first_files, []),
FirstFiles = opts(Opts, erl_first_files, []),
CTFirstFiles = opts(Opts, ct_first_files, []),
NewFirstFiles = CTFirstFiles ++ FirstFiles,
%% insert the new keys into the opts
lists:foldl(fun({K, V}, NewOpts) -> rebar_opts:set(NewOpts, K, V) end,

+ 26
- 8
src/rebar_prv_eunit.erl 查看文件

@ -121,21 +121,29 @@ compile(_State, Error) -> Error.
inject_eunit_state(State, Tests) ->
Apps = rebar_state:project_apps(State),
ModdedApps = lists:map(fun(App) ->
NewOpts = inject(rebar_app_info:opts(App), State),
NewOpts = inject(rebar_app_info:opts(App)),
rebar_app_info:opts(App, NewOpts)
end, Apps),
NewOpts = inject(rebar_state:opts(State), State),
NewOpts = inject(rebar_state:opts(State)),
NewState = rebar_state:opts(State, NewOpts),
test_dirs(NewState, ModdedApps, Tests).
inject(Opts, State) ->
opts(Opts, Key, Default) ->
case rebar_opts:get(Opts, Key, Default) of
Vs when is_list(Vs) -> Vs;
Wrong ->
?WARN("Value ~p of option `~p' is not a list, trying to adjust and continue", [Wrong, Key]),
[Wrong]
end.
inject(Opts) ->
%% append `eunit_compile_opts` to app defined `erl_opts`
ErlOpts = rebar_opts:get(Opts, erl_opts, []),
EUnitOpts = rebar_state:get(State, eunit_compile_opts, []),
ErlOpts = opts(Opts, erl_opts, []),
EUnitOpts = opts(Opts, eunit_compile_opts, []),
NewErlOpts = EUnitOpts ++ ErlOpts,
%% append `eunit_first_files` to app defined `erl_first_files`
FirstFiles = rebar_opts:get(Opts, erl_first_files, []),
EUnitFirstFiles = rebar_state:get(State, eunit_first_files, []),
FirstFiles = opts(Opts, erl_first_files, []),
EUnitFirstFiles = opts(Opts, eunit_first_files, []),
NewFirstFiles = EUnitFirstFiles ++ FirstFiles,
%% insert the new keys into the opts
lists:foldl(fun({K, V}, NewOpts) -> rebar_opts:set(NewOpts, K, V) end,
@ -180,13 +188,23 @@ inject_test_dir(Opts, Dir) ->
prepare_tests(State) ->
%% parse and translate command line tests
CmdTests = resolve_tests(State),
CfgTests = rebar_state:get(State, eunit_tests, []),
CfgTests = cfg_tests(State),
ProjectApps = rebar_state:project_apps(State),
%% prioritize tests to run first trying any command line specified
%% tests falling back to tests specified in the config file finally
%% running a default set if no other tests are present
select_tests(State, ProjectApps, CmdTests, CfgTests).
cfg_tests(State) ->
case rebar_state:get(State, eunit_tests, []) of
Tests when is_list(Tests) -> Tests;
Wrong ->
%% probably a single non list term, try wrapping it in a list and
%% continuing
?WARN("Value `~p' of option `eunit_tests' is not a list, trying to adjust and continue", [Wrong]),
[Wrong]
end.
resolve_tests(State) ->
{RawOpts, _} = rebar_state:command_parsed_args(State),
Apps = resolve(app, application, RawOpts),

正在加载...
取消
保存