summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorFred Hebert <mononcqc@ferd.ca>2015-11-13 13:54:22 -0500
committerFred Hebert <mononcqc@ferd.ca>2015-11-13 13:54:22 -0500
commit0b01c9fcf7443d36c6c3d67c74a70bad789ede5f (patch)
treeb8290349a11d53937d7925a0f1c1b7cc240ad83b /src
parent5383e5fb946153bff943367148ef665fe510486c (diff)
parentb9c15df8736a8af737fc7fff5eb6f15d2789ea9a (diff)
Merge pull request #917 from ferd/ct-readable
Prettify all of common test output.
Diffstat (limited to 'src')
-rw-r--r--src/rebar.app.src1
-rw-r--r--src/rebar_prv_common_test.erl37
2 files changed, 36 insertions, 2 deletions
diff --git a/src/rebar.app.src b/src/rebar.app.src
index 5ab3ddd..14c08c9 100644
--- a/src/rebar.app.src
+++ b/src/rebar.app.src
@@ -25,6 +25,7 @@
bbmustache,
ssl_verify_hostname,
certifi,
+ cth_readable,
relx,
inets]},
{env, [
diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl
index 977a5f6..7a65dd5 100644
--- a/src/rebar_prv_common_test.erl
+++ b/src/rebar_prv_common_test.erl
@@ -152,7 +152,7 @@ split_string(String) ->
cfgopts(State) ->
Opts = rebar_state:get(State, ct_opts, []),
- rebar_utils:filtermap(fun filter_opts/1, Opts).
+ add_hooks(rebar_utils:filtermap(fun filter_opts/1, Opts), State).
filter_opts({test_spec, _}) ->
?WARN("Test specs not supported", []),
@@ -170,6 +170,19 @@ filter_opts({suite, Suites}) ->
Suites)}};
filter_opts(_) -> true.
+add_hooks(Opts, State) ->
+ case {readable(State), lists:keyfind(ct_hooks, 1, Opts)} of
+ {false, _} ->
+ Opts;
+ {true, false} ->
+ [{ct_hooks, [cth_readable_failonly, cth_readable_shell]} | Opts];
+ {true, {ct_hooks, Hooks}} ->
+ %% Make sure hooks are there once only.
+ ReadableHooks = [cth_readable_failonly, cth_readable_shell],
+ NewHooks = (Hooks -- ReadableHooks) ++ ReadableHooks,
+ lists:keyreplace(ct_hooks, 1, Opts, {ct_hooks, NewHooks})
+ end.
+
select_tests(State, ProjectApps, CmdOpts, CfgOpts) ->
FixedOpts = lists:filter(fun({_, _}) -> true; (V) -> ?WARN("`~p` is not a valid option for `ct_opts`", [V]) end, CfgOpts),
Merged = lists:ukeymerge(1,
@@ -249,7 +262,7 @@ inject(Opts, State) ->
%% append `ct_compile_opts` to app defined `erl_opts`
ErlOpts = rebar_opts:get(Opts, erl_opts, []),
CTOpts = rebar_state:get(State, ct_compile_opts, []),
- NewErlOpts = CTOpts ++ ErlOpts,
+ NewErlOpts = add_transforms(CTOpts, State) ++ ErlOpts,
%% append `ct_first_files` to app defined `erl_first_files`
FirstFiles = rebar_opts:get(Opts, erl_first_files, []),
CTFirstFiles = rebar_state:get(State, ct_first_files, []),
@@ -259,6 +272,23 @@ inject(Opts, State) ->
Opts,
[{erl_opts, NewErlOpts}, {erl_first_files, NewFirstFiles}]).
+add_transforms(CTOpts, State) ->
+ case readable(State) of
+ true ->
+ ReadableTransform = [{parse_transform, cth_readable_transform}],
+ (CTOpts -- ReadableTransform) ++ ReadableTransform;
+ false ->
+ CTOpts
+ end.
+
+readable(State) ->
+ {RawOpts, _} = rebar_state:command_parsed_args(State),
+ case proplists:get_value(readable, RawOpts) of
+ true -> true;
+ false -> false;
+ undefined -> rebar_state:get(State, ct_readable, true)
+ end.
+
test_dirs(State, Apps, Opts) ->
case {proplists:get_value(suite, Opts), proplists:get_value(dir, Opts)} of
{Suites, undefined} -> set_compile_dirs(State, Apps, {suite, Suites});
@@ -490,6 +520,7 @@ ct_opts(_State) ->
{multiply_timetraps, undefined, "multiply_timetraps", integer, help(multiple_timetraps)}, %% Integer
{scale_timetraps, undefined, "scale_timetraps", boolean, help(scale_timetraps)},
{create_priv_dir, undefined, "create_priv_dir", string, help(create_priv_dir)},
+ {readable, undefined, "readable", boolean, help(readable)},
{verbose, $v, "verbose", boolean, help(verbose)}
].
@@ -539,6 +570,8 @@ help(scale_timetraps) ->
"Scale timetraps";
help(create_priv_dir) ->
"Create priv dir (auto_per_run | auto_per_tc | manual_per_tc)";
+help(readable) ->
+ "Shows test case names and only displays logs to shell on failures";
help(verbose) ->
"Verbose output";
help(_) ->