summaryrefslogtreecommitdiff
path: root/src/rebar_prv_common_test.erl
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2017-11-23 13:52:38 -0500
committerFred Hebert <mononcqc@ferd.ca>2017-11-24 14:59:31 -0500
commit32ae99650110637d479bb0db64dc1e6583d7b094 (patch)
tree00d3bfc0a7c2e69331f8786d58d2f040b22d2076 /src/rebar_prv_common_test.erl
parentefeaa91f0b9a53909b0258f078f22bac7c4f5507 (diff)
Add experimental support for ct --retry option
This commit adds a common test hook along with the cth_readable stuff whose role is to track failing test cases, and create a test specification out of them. The test specification is dumped on disk at _build/<profile>/logs/retry.spec and can be accessed by calling 'rebar3 ct --retry'. This will auto-load the spec file if it can be found and re-run the failing cases. If any other argument is found on the list specifying tests, the '--retry' argument is ignored. All code for this is marked as experimental in case we end up (keeping and then) dropping the feature.
Diffstat (limited to 'src/rebar_prv_common_test.erl')
-rw-r--r--src/rebar_prv_common_test.erl23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 2443710..9631a0d 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -135,7 +135,7 @@ cmdopts(State) ->
{RawOpts, _} = rebar_state:command_parsed_args(State),
%% filter out opts common_test doesn't know about and convert
%% to ct acceptable forms
- transform_opts(RawOpts, []).
+ transform_retry(transform_opts(RawOpts, []), State).
transform_opts([], Acc) -> lists:reverse(Acc);
transform_opts([{dir, Dirs}|Rest], Acc) ->
@@ -172,6 +172,18 @@ transform_opts([{verbose, _}|Rest], Acc) ->
transform_opts([Opt|Rest], Acc) ->
transform_opts(Rest, [Opt|Acc]).
+%% @private only retry if specified and if no other spec
+%% is given.
+transform_retry(Opts, State) ->
+ case proplists:get_value(retry, Opts, false) andalso
+ not is_any_defined([spec,dir,suite], Opts) of
+ false ->
+ Opts;
+ true ->
+ Path = filename:join([rebar_dir:base_dir(State), "logs", "retry.spec"]),
+ filelib:is_file(Path) andalso [{spec, Path}|Opts]
+ end.
+
split_string(String) ->
rebar_string:lexemes(String, [$,]).
@@ -213,10 +225,10 @@ add_hooks(Opts, State) ->
{false, _} ->
Opts;
{true, false} ->
- [{ct_hooks, [cth_readable_failonly, cth_readable_shell]} | Opts];
+ [{ct_hooks, [cth_readable_failonly, cth_readable_shell, cth_retry]} | Opts];
{true, {ct_hooks, Hooks}} ->
%% Make sure hooks are there once only.
- ReadableHooks = [cth_readable_failonly, cth_readable_shell],
+ ReadableHooks = [cth_readable_failonly, cth_readable_shell, cth_retry],
NewHooks = (Hooks -- ReadableHooks) ++ ReadableHooks,
lists:keyreplace(ct_hooks, 1, Opts, {ct_hooks, NewHooks})
end.
@@ -751,7 +763,8 @@ ct_opts(_State) ->
{sname, undefined, "sname", atom, help(sname)},
{setcookie, undefined, "setcookie", atom, help(setcookie)},
{sys_config, undefined, "sys_config", string, help(sys_config)}, %% comma-separated list
- {compile_only, undefined, "compile_only", boolean, help(compile_only)}
+ {compile_only, undefined, "compile_only", boolean, help(compile_only)},
+ {retry, undefined, "retry", boolean, help(retry)}
].
help(compile_only) ->
@@ -820,5 +833,7 @@ help(sname) ->
"Gives a short name to the node";
help(setcookie) ->
"Sets the cookie if the node is distributed";
+help(retry) ->
+ "Experimental feature. If any specification for previously failing test is found, runs them.";
help(_) ->
"".