summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Thompson <andrew@hijacked.us>2014-02-05 14:41:25 -0500
committerAndrew Thompson <andrew@hijacked.us>2014-02-07 13:05:33 -0500
commit03da5e0be061dfed832ca7eaaf5998fa7cf27640 (patch)
tree57bb3dcb4f8c48a0f1dd015b1f0ab0533575fffc
parentfa679b43434020e8765f6f8ee9b7abebfb3b0109 (diff)
Add random_suite_order option to eunit command
Option takes either 'true' or a numeric seed value. If true is passed, a random seed is generated and used. The numeric seed value is for repeatability. The idea here is to root out test suites that are order dependant, or that fail in the presence of certain orderings.
-rw-r--r--src/rebar_eunit.erl29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/rebar_eunit.erl b/src/rebar_eunit.erl
index e04b28e..323e199 100644
--- a/src/rebar_eunit.erl
+++ b/src/rebar_eunit.erl
@@ -150,7 +150,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],
@@ -234,6 +234,33 @@ get_suites(Config) ->
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_tests(Config, SuitesProvided, ModuleBeamFiles, FilteredModules) ->