diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 0c52c58..21228df 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -132,12 +132,14 @@ eunit(Config, _AppFile) -> ModuleBeamFiles = BeamFiles ++ OtherBeamFiles, Modules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- ModuleBeamFiles], SrcModules = [rebar_utils:erl_to_mod(M) || M <- SrcErls], + Suites = get_suites(), + FilteredModules = filtered_modules(Modules, Suites), {ok, CoverLog} = cover_init(Config, ModuleBeamFiles), StatusBefore = status_before_eunit(), - EunitResult = perform_eunit(Config, Modules), - perform_cover(Config, Modules, SrcModules), + EunitResult = perform_eunit(Config, FilteredModules), + perform_cover(Config, FilteredModules, SrcModules), cover_close(CoverLog), @@ -173,10 +175,16 @@ eunit_dir() -> ebin_dir() -> filename:join(rebar_utils:get_cwd(), "ebin"). -perform_eunit(Config, Modules) -> - %% suite defined, so only specify the module that relates to the - %% suite (if any). Suite can be a comma seperated list of modules to run. - Suite = rebar_config:get_global(suite, undefined), +get_suites() -> + Suites = rebar_utils:get_deprecated_global(suite, suites, [], "soon"), + [list_to_atom(Suite) || Suite <- string:tokens(Suites, ",")]. + +filtered_modules(Modules, []) -> + Modules; +filtered_modules(Modules, Suites) -> + [M || M <- Modules, lists:member(M, Suites)]. + +perform_eunit(Config, FilteredModules) -> EunitOpts = get_eunit_opts(Config), %% Move down into ?EUNIT_DIR while we run tests so any generated files @@ -184,19 +192,13 @@ perform_eunit(Config, Modules) -> Cwd = rebar_utils:get_cwd(), ok = file:set_cwd(?EUNIT_DIR), - EunitResult = perform_eunit(EunitOpts, Modules, Suite), + EunitResult = (catch eunit:test(FilteredModules, EunitOpts)), %% Return to original working dir ok = file:set_cwd(Cwd), EunitResult. -perform_eunit(EunitOpts, Modules, undefined) -> - (catch eunit:test(Modules, EunitOpts)); -perform_eunit(EunitOpts, _Modules, Suites) -> - (catch eunit:test([list_to_atom(Suite) || - Suite <- string:tokens(Suites, ",")], EunitOpts)). - get_eunit_opts(Config) -> %% Enable verbose in eunit if so requested.. BaseOpts = case rebar_config:is_verbose() of @@ -260,15 +262,7 @@ perform_cover(true, Config, BeamFiles, SrcModules) -> cover_analyze(_Config, [], _SrcModules) -> ok; -cover_analyze(Config, Modules, SrcModules) -> - %% suite can be a comma seperated list of modules to test - Suite = [list_to_atom(S) || - S <- string:tokens(rebar_config:get_global(suite, ""), ",")], - FilteredModules = case Suite of - [] -> Modules; - _ -> [M || M <- Modules, lists:member(M, Suite)] - end, - +cover_analyze(Config, FilteredModules, SrcModules) -> %% Generate coverage info for all the cover-compiled modules Coverage = lists:flatten([cover_analyze_mod(M) || M <- FilteredModules]), diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index abe837a..27b2440 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -45,7 +45,7 @@ deprecated/3, deprecated/4, expand_env_variable/3, vcs_vsn/2, - get_deprecated_global/3, + get_deprecated_global/3, get_deprecated_global/4, get_deprecated_list/4, get_deprecated_list/5, get_deprecated_local/4, get_deprecated_local/5, delayed_halt/1]). @@ -243,10 +243,10 @@ get_deprecated_global(OldOpt, NewOpt, When) -> get_deprecated_global(OldOpt, NewOpt, Default, When) -> case rebar_config:get_global(NewOpt, Default) of - undefined -> + Default -> case rebar_config:get_global(OldOpt, Default) of - undefined -> - undefined; + Default -> + Default; Old -> deprecated(OldOpt, NewOpt, When), Old @@ -255,7 +255,6 @@ get_deprecated_global(OldOpt, NewOpt, Default, When) -> New end. - get_deprecated_list(Config, OldOpt, NewOpt, When) -> get_deprecated_list(Config, OldOpt, NewOpt, undefined, When).