diff options
| -rw-r--r-- | src/rebar_prv_common_test.erl | 27 | ||||
| -rw-r--r-- | src/rebar_prv_eunit.erl | 34 | 
2 files changed, 47 insertions, 14 deletions
| diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 7a65dd5..608261a 100644 --- a/src/rebar_prv_common_test.erl +++ b/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, diff --git a/src/rebar_prv_eunit.erl b/src/rebar_prv_eunit.erl index 1884f02..b754d87 100644 --- a/src/rebar_prv_eunit.erl +++ b/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), | 
