From e6be44667d5786fafa9a2fd056c94e40cfe5deab Mon Sep 17 00:00:00 2001 From: alisdair sullivan Date: Tue, 17 Feb 2015 14:36:19 -0800 Subject: suppress common_test output unless `rebar3 ct` is run with verbose switch --- src/rebar_prv_common_test.erl | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/src/rebar_prv_common_test.erl b/src/rebar_prv_common_test.erl index 5de1618..a55faa2 100644 --- a/src/rebar_prv_common_test.erl +++ b/src/rebar_prv_common_test.erl @@ -55,7 +55,8 @@ do(State) -> Path = code:get_path(), true = code:add_patha(OutDir), CTOpts = resolve_ct_opts(State, Opts, OutDir), - Result = handle_results(ct:run_test(CTOpts)), + Verbose = proplists:get_value(verbose, Opts, false), + Result = run_test(CTOpts, Verbose), true = code:set_path(Path), case Result of {error, Reason} -> @@ -70,6 +71,19 @@ format_error({failures_running_tests, FailedCount}) -> format_error({error_running_tests, Reason}) -> io_lib:format("Error running tests: ~p", [Reason]). +run_test(CTOpts, true) -> + handle_results(ct:run_test(CTOpts)); +run_test(CTOpts, false) -> + Pid = self(), + LogDir = proplists:get_value(logdir, CTOpts), + erlang:spawn(fun() -> + {ok, F} = file:open(filename:join([LogDir, "ct.latest.log"]), + [write]), + true = group_leader(F, self()), + Pid ! ct:run_test(CTOpts) + end), + receive Result -> handle_quiet_results(CTOpts, Result) end. + ct_opts(State) -> DefaultLogsDir = filename:join([rebar_state:dir(State), "logs"]), [{dir, undefined, "dir", string, help(dir)}, %% comma-seperated list @@ -104,7 +118,8 @@ ct_opts(State) -> {until, undefined, "until", string, help(until)}, %% format: YYMoMoDD[HHMMSS] {force_stop, undefined, "force_stop", string, help(force_stop)}, % enum: skip_rest, bool {basic_html, undefined, "basic_html", boolean, help(basic_html)}, %% Booloean - {ct_hooks, undefined, "ct_hooks", string, help(ct_hooks)} %% List: [CTHModule | {CTHModule, CTHInitArgs}] where CTHModule is atom CthInitArgs is term + {ct_hooks, undefined, "ct_hooks", string, help(ct_hooks)}, %% List: [CTHModule | {CTHModule, CTHInitArgs}] where CTHModule is atom CthInitArgs is term + {verbose, $v, "verbose", boolean, help(verbose)} ]. help(outdir) -> @@ -166,7 +181,9 @@ help(basic_html) -> help(ct_hooks) -> ""; help(userconfig) -> - "". + ""; +help(verbose) -> + "Verbose output". split_ct_dirs(State, RawOpts) -> %% preserve the override nature of command line opts by only checking @@ -339,9 +356,17 @@ handle_results([Result|Results]) when is_list(Results) -> Error -> Error end; -handle_results({_, 0, _}) -> - ok; -handle_results({_, FailedCount, _}) -> - {error, {failures_running_tests, FailedCount}}; handle_results({error, Reason}) -> - {error, {error_running_tests, Reason}}. + {error, {error_running_tests, Reason}}; +handle_results(_) -> ok. + +handle_quiet_results(_, {Passed, 0, {0, 0}}) -> + io:format(" All ~p tests passed.~n", [Passed]); +handle_quiet_results(_, {Passed, 0, {UserSkipped, AutoSkipped}}) -> + io:format(" All ~p tests passed. Skipped ~p tests.~n", + [Passed, UserSkipped + AutoSkipped]); +handle_quiet_results(CTOpts, {_, Failed, _}) -> + LogDir = proplists:get_value(logdir, CTOpts), + Index = filename:join([LogDir, "index.html"]), + io:format(" ~p tests failed.~n Results written to ~p.~n", [Failed, Index]); +handle_quiet_results(_CTOpts, Result) -> handle_results(Result). -- cgit v1.1