Skip to content

Commit

Permalink
Have CLI and .config read from the _same_ option source
Browse files Browse the repository at this point in the history
The CLI, however, takes precedence from the .config file
  • Loading branch information
paulo-ferraz-oliveira committed Sep 15, 2023
1 parent 86219dc commit fd487a9
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions apps/rebar/src/rebar_prv_common_test.erl
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ run_tests(State, Opts) ->
Opts1 = setup_logdir(State, T),
Opts2 = turn_off_auto_compile(Opts1),
?DEBUG("Running tests with {ct_opts, ~p}.", [Opts2]),
{RawOpts, _} = rebar_state:command_parsed_args(State),
Result = case proplists:get_value(verbose, RawOpts, false) of
CTOpts = rebar_state:get(State, ct_opts, []),
VerboseFromConfig = verbose({from_config, State}, _DefaultFromConfig = false, CTOpts),
Result = case verbose({from_cli, State}, VerboseFromConfig) of
true -> run_test_verbose(Opts2);
false -> run_test_quiet(Opts2)
end,
Expand Down Expand Up @@ -273,16 +274,18 @@ add_hooks(Opts, State) ->
true -> [cth_fail_fast];
false -> []
end,
VerboseFromConfig = verbose({from_config, State}, _DefaultFromConfig = false, Opts),
Verbose = [{verbose, verbose({from_cli, State}, VerboseFromConfig)}],
case {readable(State), lists:keyfind(ct_hooks, 1, Opts)} of
{false, _} ->
Opts;
{Other, false} ->
ShellTypeWithOpts = {readable_shell_type(Other), [verbose(Opts)]},
ShellTypeWithOpts = {readable_shell_type(Other), Verbose},
[{ct_hooks, [cth_readable_failonly, ShellTypeWithOpts,
cth_retry] ++ FailFast ++ cth_log_redirect()} | Opts];
{Other, {ct_hooks, Hooks}} ->
%% Make sure hooks are there once only and add wanted hooks that are not defined yet
ShellTypeWithOpts = {readable_shell_type(Other), [verbose(Opts)]},
ShellTypeWithOpts = {readable_shell_type(Other), Verbose},
ReadableHooks = [cth_readable_failonly, ShellTypeWithOpts,
cth_retry] ++ FailFast,
NewHooks = Hooks ++ [ReadableHook ||
Expand All @@ -298,8 +301,12 @@ is_defined(Key, [{Key, _Opts} | _Hs]) -> true;
is_defined(Key, [{Key, _Opts, _Prio} | _Hs]) -> true;
is_defined(Key, [_ | Hs]) -> is_defined(Key, Hs).

verbose(Opts) ->
{verbose, proplists:get_value(verbose, Opts, true)}.
verbose({from_cli, State}, Default) ->
{Opts, _} = rebar_state:command_parsed_args(State),
proplists:get_value(verbose, Opts, Default).

verbose({from_config, _State}, Default, Opts) ->
proplists:get_value(verbose, Opts, Default).

readable_shell_type(true) -> cth_readable_shell;
readable_shell_type(compact) -> cth_readable_compact_shell.
Expand Down

0 comments on commit fd487a9

Please sign in to comment.