Moved ec_cmd_log
tests into separate file
* moved colour macros into `src/ec_cmd_log.hrl` * moved `ec_cmd_log` tests into `test/ec_cmd_log_tests.erl`. Signed-off-by: Ariel Otilibili <otilibil@eurecom.fr>
This commit is contained in:
parent
d24ad72034
commit
ca7581cbb0
3 changed files with 48 additions and 49 deletions
|
@ -43,14 +43,8 @@
|
|||
colorize/4,
|
||||
format/1]).
|
||||
|
||||
-include("ec_cmd_log.hrl").
|
||||
|
||||
-define(RED, $r).
|
||||
-define(GREEN, $g).
|
||||
-define(YELLOW, $y).
|
||||
-define(BLUE, $b).
|
||||
-define(MAGENTA, $m).
|
||||
-define(CYAN, $c).
|
||||
-include("include/ec_cmd_log.hrl").
|
||||
-include("src/ec_cmd_log.hrl").
|
||||
|
||||
-define(PREFIX, "===> ").
|
||||
|
||||
|
@ -261,44 +255,3 @@ colorize(#state_t{caller=command_line, intensity = low},
|
|||
lists:flatten(cf:format("~!" ++ [Color] ++"~ts~!!~ts", [?PREFIX, Msg]));
|
||||
colorize(_LogState, _Color, _Bold, Msg) ->
|
||||
Msg.
|
||||
|
||||
%%%===================================================================
|
||||
%%% Test Functions
|
||||
%%%===================================================================
|
||||
|
||||
-ifdef(TEST).
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
should_test() ->
|
||||
ErrorLogState = new(error),
|
||||
?assertMatch(true, should(ErrorLogState, ?EC_ERROR)),
|
||||
?assertMatch(true, not should(ErrorLogState, ?EC_INFO)),
|
||||
?assertMatch(true, not should(ErrorLogState, ?EC_DEBUG)),
|
||||
?assertEqual(?EC_ERROR, log_level(ErrorLogState)),
|
||||
?assertEqual(error, atom_log_level(ErrorLogState)),
|
||||
|
||||
InfoLogState = new(info),
|
||||
?assertMatch(true, should(InfoLogState, ?EC_ERROR)),
|
||||
?assertMatch(true, should(InfoLogState, ?EC_INFO)),
|
||||
?assertMatch(true, not should(InfoLogState, ?EC_DEBUG)),
|
||||
?assertEqual(?EC_INFO, log_level(InfoLogState)),
|
||||
?assertEqual(info, atom_log_level(InfoLogState)),
|
||||
|
||||
DebugLogState = new(debug),
|
||||
?assertMatch(true, should(DebugLogState, ?EC_ERROR)),
|
||||
?assertMatch(true, should(DebugLogState, ?EC_INFO)),
|
||||
?assertMatch(true, should(DebugLogState, ?EC_DEBUG)),
|
||||
?assertEqual(?EC_DEBUG, log_level(DebugLogState)),
|
||||
?assertEqual(debug, atom_log_level(DebugLogState)).
|
||||
|
||||
|
||||
no_color_test() ->
|
||||
LogState = new(debug, command_line, none),
|
||||
?assertEqual("test",
|
||||
colorize(LogState, ?RED, true, "test")).
|
||||
|
||||
color_test() ->
|
||||
LogState = new(debug, command_line, high),
|
||||
?assertEqual("\e[1;31m===> test\e[0m",
|
||||
colorize(LogState, ?RED, true, "test")).
|
||||
-endif.
|
||||
|
|
7
src/ec_cmd_log.hrl
Normal file
7
src/ec_cmd_log.hrl
Normal file
|
@ -0,0 +1,7 @@
|
|||
%%% @copyright 2024 Erlware, LLC.
|
||||
-define(RED, $r).
|
||||
-define(GREEN, $g).
|
||||
-define(YELLOW, $y).
|
||||
-define(BLUE, $b).
|
||||
-define(MAGENTA, $m).
|
||||
-define(CYAN, $c).
|
Loading…
Add table
Add a link
Reference in a new issue