From d31e663a67a483b6a740f973f52db41fd01e5861 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 13 Nov 2015 14:13:59 +0000 Subject: Prettify all of common test output. This uses cth_readable to: - silence error_logger output to the shell unless a test fails - silence ct:pal output to the shell unless a test fails I have currently not baked in any way to disable this behaviour, but I figured if it is required, there is time to do it before the final 3.0.0 release. --- rebar.config | 3 ++- rebar.lock | 1 + src/rebar_prv_common_test.erl | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/rebar.config b/rebar.config index c7bf381..31d65df 100644 --- a/rebar.config +++ b/rebar.config @@ -8,7 +8,8 @@ {getopt, "0.8.2"}, {bbmustache, "1.0.4"}, {relx, "3.8.0"}, - {cf, "0.1.3"}]}. + {cf, "0.1.3"}, + {cth_readable, "1.0.0"}]}. {escript_name, rebar3}. {escript_emu_args, "%%! +sbtu +A0\n"}. diff --git a/rebar.lock b/rebar.lock index 88685e2..36d4802 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,6 +1,7 @@ [{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.0.4">>},0}, {<<"certifi">>,{pkg,<<"certifi">>,<<"0.1.1">>},0}, {<<"cf">>,{pkg,<<"cf">>,<<"0.1.3">>},0}, + {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.0.0">>},0}, {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"0.16.0">>},0}, {<<"getopt">>,{pkg,<<"getopt">>,<<"0.8.2">>},0}, {<<"providers">>,{pkg,<<"providers">>,<<"1.5.0">>},0}, diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 977a5f6..525ddaf 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)). filter_opts({test_spec, _}) -> ?WARN("Test specs not supported", []), @@ -170,6 +170,18 @@ filter_opts({suite, Suites}) -> Suites)}}; filter_opts(_) -> true. +add_hooks(Opts) -> + %% cth_readable hooks + case lists:keyfind(ct_hooks, 1, Opts) of + false -> + [{ct_hooks, [cth_readable_failonly, cth_readable_shell]} | Opts]; + {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 +261,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) ++ 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 +271,11 @@ inject(Opts, State) -> Opts, [{erl_opts, NewErlOpts}, {erl_first_files, NewFirstFiles}]). +add_transforms(CTOpts) -> + ReadableTransform = [{parse_transform, cth_readable_transform}], + (CTOpts -- ReadableTransform) ++ ReadableTransform. + + 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}); -- cgit v1.1 From 2cb1aca6859c7f1d0e0e4687be82ad7628fbe33a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 13 Nov 2015 14:46:50 +0000 Subject: Work in R15 --- rebar.config | 2 +- rebar.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/rebar.config b/rebar.config index 31d65df..f19d81d 100644 --- a/rebar.config +++ b/rebar.config @@ -9,7 +9,7 @@ {bbmustache, "1.0.4"}, {relx, "3.8.0"}, {cf, "0.1.3"}, - {cth_readable, "1.0.0"}]}. + {cth_readable, "1.0.1"}]}. {escript_name, rebar3}. {escript_emu_args, "%%! +sbtu +A0\n"}. diff --git a/rebar.lock b/rebar.lock index 36d4802..1d0ab42 100644 --- a/rebar.lock +++ b/rebar.lock @@ -1,7 +1,7 @@ [{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.0.4">>},0}, {<<"certifi">>,{pkg,<<"certifi">>,<<"0.1.1">>},0}, {<<"cf">>,{pkg,<<"cf">>,<<"0.1.3">>},0}, - {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.0.0">>},0}, + {<<"cth_readable">>,{pkg,<<"cth_readable">>,<<"1.0.1">>},0}, {<<"erlware_commons">>,{pkg,<<"erlware_commons">>,<<"0.16.0">>},0}, {<<"getopt">>,{pkg,<<"getopt">>,<<"0.8.2">>},0}, {<<"providers">>,{pkg,<<"providers">>,<<"1.5.0">>},0}, -- cgit v1.1 From d4981b7913e63247a0db0a92742e7937fd804334 Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 13 Nov 2015 16:59:48 +0000 Subject: Add cth_readable to dep list --- src/rebar.app.src | 1 + 1 file changed, 1 insertion(+) 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, [ -- cgit v1.1 From b9c15df8736a8af737fc7fff5eb6f15d2789ea9a Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Fri, 13 Nov 2015 17:07:45 +0000 Subject: Optionally disable readable output --- src/rebar_prv_common_test.erl | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 525ddaf..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, []), - add_hooks(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,12 +170,13 @@ filter_opts({suite, Suites}) -> Suites)}}; filter_opts(_) -> true. -add_hooks(Opts) -> - %% cth_readable hooks - case lists:keyfind(ct_hooks, 1, Opts) of - false -> +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]; - {ct_hooks, Hooks} -> + {true, {ct_hooks, Hooks}} -> %% Make sure hooks are there once only. ReadableHooks = [cth_readable_failonly, cth_readable_shell], NewHooks = (Hooks -- ReadableHooks) ++ ReadableHooks, @@ -261,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 = add_transforms(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, []), @@ -271,10 +272,22 @@ inject(Opts, State) -> Opts, [{erl_opts, NewErlOpts}, {erl_first_files, NewFirstFiles}]). -add_transforms(CTOpts) -> - ReadableTransform = [{parse_transform, cth_readable_transform}], - (CTOpts -- ReadableTransform) ++ ReadableTransform. +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 @@ -507,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)} ]. @@ -556,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(_) -> -- cgit v1.1