mirror of
https://github.com/correl/rebar.git
synced 2024-11-23 19:19:54 +00:00
Merge pull request #223 from rebar/adt-random-suite-order
Add random_suite_order option to eunit command
This commit is contained in:
commit
ec448c0894
2 changed files with 33 additions and 1 deletions
|
@ -369,6 +369,8 @@ eunit [suite[s]=foo] Run eunit tests in foo.erl and
|
||||||
no such test exists, run the test whose
|
no such test exists, run the test whose
|
||||||
name starts with bar in the suite's
|
name starts with bar in the suite's
|
||||||
_tests module
|
_tests module
|
||||||
|
[random_suite_order=true] Run tests in a random order, either with
|
||||||
|
[random_suite_order=Seed] a random seed for the PRNG, or a specific one.
|
||||||
|
|
||||||
ct [suite[s]=] [case=] Run common_test suites
|
ct [suite[s]=] [case=] Run common_test suites
|
||||||
|
|
||||||
|
|
|
@ -126,6 +126,9 @@ info_help(Description) ->
|
||||||
" name starts with bar and, if no such test exists,~n"
|
" name starts with bar and, if no such test exists,~n"
|
||||||
" run the test whose name starts with bar in the~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)",
|
" compile_only=true (Compile but do not run tests)",
|
||||||
[
|
[
|
||||||
Description,
|
Description,
|
||||||
|
@ -150,7 +153,7 @@ run_eunit(Config, CodePath, SrcErls) ->
|
||||||
AllBeamFiles),
|
AllBeamFiles),
|
||||||
OtherBeamFiles = TestBeamFiles --
|
OtherBeamFiles = TestBeamFiles --
|
||||||
[filename:rootname(N) ++ "_tests.beam" || N <- AllBeamFiles],
|
[filename:rootname(N) ++ "_tests.beam" || N <- AllBeamFiles],
|
||||||
ModuleBeamFiles = BeamFiles ++ OtherBeamFiles,
|
ModuleBeamFiles = randomize_suites(Config, BeamFiles ++ OtherBeamFiles),
|
||||||
|
|
||||||
%% Get modules to be run in eunit
|
%% Get modules to be run in eunit
|
||||||
AllModules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- AllBeamFiles],
|
AllModules = [rebar_utils:beam_to_mod(?EUNIT_DIR, N) || N <- AllBeamFiles],
|
||||||
|
@ -233,6 +236,33 @@ get_suites(Config) ->
|
||||||
Suites
|
Suites
|
||||||
end.
|
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 ==
|
%% == get matching tests ==
|
||||||
%%
|
%%
|
||||||
|
|
Loading…
Reference in a new issue