test: make `clear_screen` safer

Useful when iterating on the tests in a loop, to get rid of all the garbaged printed
before the test itself beings.

Only actually does anything if the environment variable `CLEAR_SCREEN` is set to `true`
and only clears the screen the screen the first time it's encountered, so it's harmless
otherwise.
This commit is contained in:
Thales Macedo Garitezi 2024-02-26 09:31:06 -03:00
parent de5e4491f7
commit c6195fcf50
1 changed files with 17 additions and 7 deletions

View File

@ -1060,14 +1060,24 @@ expand_node_specs(Specs, CommonOpts) ->
Specs Specs
). ).
%% is useful when iterating on the tests in a loop, to get rid of all %% Useful when iterating on the tests in a loop, to get rid of all the garbaged printed
%% the garbaged printed before the test itself beings. %% before the test itself beings.
%% Only actually does anything if the environment variable `CLEAR_SCREEN' is set to `true'
%% and only clears the screen the screen the first time it's encountered, so it's harmless
%% otherwise.
clear_screen() -> clear_screen() ->
io:format(standard_io, "\033[H\033[2J", []), Key = {?MODULE, clear_screen},
io:format(standard_error, "\033[H\033[2J", []), case {os:getenv("CLEAR_SCREEN"), persistent_term:get(Key, false)} of
io:format(standard_io, "\033[H\033[3J", []), {"true", false} ->
io:format(standard_error, "\033[H\033[3J", []), io:format(standard_io, "\033[H\033[2J", []),
ok. io:format(standard_error, "\033[H\033[2J", []),
io:format(standard_io, "\033[H\033[3J", []),
io:format(standard_error, "\033[H\033[3J", []),
persistent_term:put(Key, true),
ok;
_ ->
ok
end.
with_mock(Mod, FnName, MockedFn, Fun) -> with_mock(Mod, FnName, MockedFn, Fun) ->
ok = meck:new(Mod, [non_strict, no_link, no_history, passthrough]), ok = meck:new(Mod, [non_strict, no_link, no_history, passthrough]),