Add ?awaitMatch macro

awaitMatch(Guard, Expr, Timeout) reevaluates Expr until it matches
Guard up to Timeout milliseconds from now. It returns the matched
value, in the event said value is useful later in a test.

Additionally simplify an instance of ?assertEqual(true, ... to ?assert(
This commit is contained in:
Philip Kuryloski 2020-07-02 11:33:17 +02:00
parent d930d0ea84
commit 9479c2e9cc
2 changed files with 22 additions and 2 deletions

View File

@ -0,0 +1,21 @@
-define(awaitMatch(Guard, Expr, Timeout),
begin
((fun Filter(Horizon) ->
R = Expr,
case (R) of
Guard -> R;
__V -> case erlang:system_time(millisecond) of
Now when Now < Horizon ->
timer:sleep(min(50, Horizon - Now)),
Filter(Horizon);
_ ->
erlang:error({awaitMatch,
[{module, ?MODULE},
{line, ?LINE},
{expression, (??Expr)},
{pattern, (??Guard)},
{value, __V}]})
end
end
end)(erlang:system_time(millisecond) + Timeout))
end).

View File

@ -20,8 +20,7 @@
-export([run_proper/3]).
run_proper(Fun, Args, NumTests) ->
?assertEqual(
true,
?assert(
proper:counterexample(erlang:apply(Fun, Args),
[{numtests, NumTests},
{on_output, fun(".", _) -> ok; % don't print the '.'s on new lines