Skip to content

Commit

Permalink
Allow to wait for logs in log_helper
Browse files Browse the repository at this point in the history
  • Loading branch information
chrzaszcz committed Apr 23, 2024
1 parent c66c8fc commit 14f3b46
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions test/log_helper.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@
%% For set-up and tear-down, see log_helper.erl

-define(assertNoLog(LevelPattern, MsgPattern),
case ?receiveLog(LevelPattern, MsgPattern) of
?assertNoLog(LevelPattern, MsgPattern, 0)).

-define(assertNoLog(LevelPattern, MsgPattern, Timeout),
case ?receiveLog(LevelPattern, MsgPattern, Timeout) of
no_log -> ok;
_ -> ct:fail("Received unexpected log")
end).

-define(assertLog(LevelPattern, MsgPattern),
case ?receiveLog(LevelPattern, MsgPattern) of
?assertLog(LevelPattern, MsgPattern, 0)).

-define(assertLog(LevelPattern, MsgPattern, Timeout),
case ?receiveLog(LevelPattern, MsgPattern, Timeout) of
no_log -> ct:fail("Expected log not received");
_ -> ok
end).

-define(receiveLog(LevelPattern, MsgPattern),
?receiveLog(LevelPattern, MsgPattern, 0)).

-define(receiveLog(LevelPattern, MsgPattern, Timeout),
?wrap(receive
{log, #{level := Level = LevelPattern,
msg := {report, Msg = MsgPattern}}} ->
ct:log("Received ~p log: ~p", [Level, Msg]),
{Level, Msg}
after
0 -> no_log
Timeout -> no_log
end)).

%% Wrap in a fun to avoid unsafe variables
Expand Down

0 comments on commit 14f3b46

Please sign in to comment.