diff options
Diffstat (limited to 'src/rebar_eunit.erl')
-rw-r--r-- | src/rebar_eunit.erl | 76 |
1 files changed, 61 insertions, 15 deletions
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl index 95ba3e8..d969f96 100644 --- a/src/rebar_eunit.erl +++ b/src/rebar_eunit.erl @@ -84,8 +84,7 @@ eunit(Config, _AppFile) -> ok = ensure_dirs(), %% Save code path CodePath = setup_code_path(), - CompileOnly = rebar_utils:get_experimental_global(Config, compile_only, - false), + CompileOnly = rebar_config:get_global(Config, compile_only, false), {ok, SrcErls} = rebar_erlc_compiler:test_compile(Config, "eunit", ?EUNIT_DIR), case CompileOnly of @@ -121,12 +120,16 @@ info_help(Description) -> " ~p~n" " ~p~n" "Valid command line options:~n" - " suites=\"foo,bar\" (Run tests in foo.erl, test/foo_tests.erl and~n" + " suite[s]=\"foo,bar\" (Run tests in foo.erl, test/foo_tests.erl and~n" " tests in bar.erl, test/bar_tests.erl)~n" - " tests=\"baz\" (For every existing suite, run the first test whose~n" + " test[s]=\"baz\" (For every existing suite, run the first test whose~n" " name starts with bar and, if no such test exists,~n" " run the test whose name starts with bar in the~n" - " suite's _tests module)~n", + " suite's _tests module)~n" + " random_suite_order=true (Run tests in random order)~n" + " random_suite_order=Seed (Run tests in random order,~n" + " with the PRNG seeded with Seed)~n" + " compile_only=true (Compile but do not run tests)", [ Description, {eunit_opts, []}, @@ -150,7 +153,7 @@ run_eunit(Config, CodePath, SrcErls) -> AllBeamFiles), OtherBeamFiles = TestBeamFiles -- [filename:rootname(N) ++ "_tests.beam" || N <- AllBeamFiles], - ModuleBeamFiles = BeamFiles ++ OtherBeamFiles, + ModuleBeamFiles = randomize_suites(Config, BeamFiles ++ OtherBeamFiles), %% Get modules to be run in eunit AllModules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- AllBeamFiles], @@ -215,7 +218,7 @@ setup_code_path() -> %% filter_suites(Config, Modules) -> - RawSuites = rebar_config:get_global(Config, suites, ""), + RawSuites = get_suites(Config), SuitesProvided = RawSuites =/= "", Suites = [list_to_atom(Suite) || Suite <- string:tokens(RawSuites, ",")], {SuitesProvided, filter_suites1(Modules, Suites)}. @@ -225,6 +228,41 @@ filter_suites1(Modules, []) -> filter_suites1(Modules, Suites) -> [M || M <- Suites, lists:member(M, Modules)]. +get_suites(Config) -> + case rebar_config:get_global(Config, suites, "") of + "" -> + rebar_config:get_global(Config, suite, ""); + Suites -> + Suites + end. + +%% +%% == randomize suites == +%% + +randomize_suites(Config, Modules) -> + case rebar_config:get_global(Config, random_suite_order, undefined) of + undefined -> + Modules; + "true" -> + Seed = crypto:rand_uniform(1, 65535), + randomize_suites1(Modules, Seed); + String -> + try list_to_integer(String) of + Seed -> + randomize_suites1(Modules, Seed) + catch + error:badarg -> + ?ERROR("Bad random seed provided: ~p~n", [String]), + ?FAIL + end + end. + +randomize_suites1(Modules, Seed) -> + _ = random:seed(35, Seed, 1337), + ?CONSOLE("Randomizing suite order with seed ~b~n", [Seed]), + [X||{_,X} <- lists:sort([{random:uniform(), M} || M <- Modules])]. + %% %% == get matching tests == %% @@ -259,8 +297,16 @@ get_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules) -> end, get_matching_tests(Config, Modules). +get_tests(Config) -> + case rebar_config:get_global(Config, tests, "") of + "" -> + rebar_config:get_global(Config, test, ""); + Suites -> + Suites + end. + get_matching_tests(Config, Modules) -> - RawFunctions = rebar_utils:get_experimental_global(Config, tests, ""), + RawFunctions = get_tests(Config), Tests = [list_to_atom(F1) || F1 <- string:tokens(RawFunctions, ",")], case Tests of [] -> @@ -408,7 +454,7 @@ perform_eunit(Config, Tests) -> get_eunit_opts(Config) -> %% Enable verbose in eunit if so requested.. - BaseOpts = case rebar_config:is_verbose(Config) of + BaseOpts = case rebar_log:is_verbose(Config) of true -> [verbose]; false -> @@ -802,11 +848,11 @@ pause_until_net_kernel_stopped() -> pause_until_net_kernel_stopped(0) -> exit(net_kernel_stop_failed); pause_until_net_kernel_stopped(N) -> - try - timer:sleep(100), - pause_until_net_kernel_stopped(N - 1) - catch - error:badarg -> + case node() of + 'nonode@nohost' -> ?DEBUG("Stopped net kernel.\n", []), - ok + ok; + _ -> + timer:sleep(100), + pause_until_net_kernel_stopped(N - 1) end. |