aboutsummaryrefslogtreecommitdiffstats
path: root/lib/eunit/include
diff options
context:
space:
mode:
authorSerge Aleynikov <[email protected]>2015-02-14 17:19:17 -0500
committerZandra Hird <[email protected]>2015-05-18 14:27:56 +0200
commite56cf8d9846e51ae88fa72c8b0992d81da6fd7d5 (patch)
tree8ffa549565dc37ba5c1c3685b92904dfd19d78a3 /lib/eunit/include
parentbcc5248a76ee692ede18367a1f3d6cd9acd6cde7 (diff)
downloadotp-e56cf8d9846e51ae88fa72c8b0992d81da6fd7d5.tar.gz
otp-e56cf8d9846e51ae88fa72c8b0992d81da6fd7d5.tar.bz2
otp-e56cf8d9846e51ae88fa72c8b0992d81da6fd7d5.zip
Add ?assertReceive(Guard, Timeout) macro to eunit
A convenience macro used for testing message passing logic by allowing to fail if a message matching a `Guard` is not received in the mailbox of the current process.
Diffstat (limited to 'lib/eunit/include')
-rw-r--r--lib/eunit/include/eunit.hrl20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/eunit/include/eunit.hrl b/lib/eunit/include/eunit.hrl
index 53d291430d..8a829396ec 100644
--- a/lib/eunit/include/eunit.hrl
+++ b/lib/eunit/include/eunit.hrl
@@ -166,6 +166,26 @@
%% This is mostly a convenience which gives more detailed reports.
%% Note: Guard is a guarded pattern, and can not be used for value.
-ifdef(NOASSERT).
+-define(assertReceive(Guard, Timeout), ok).
+-else.
+-define(assertReceive(Guard, Timeout),
+ begin
+ ((fun () ->
+ receive (Guard) -> ok
+ after Timeout -> erlang:error({assertReceive_timedout,
+ [{module, ?MODULE},
+ {line, ?LINE},
+ {pattern, (??Guard)},
+ {timeout, __V}]})
+ end
+ end)())
+ end).
+-endif.
+-define(_assertReceive(Guard, Timeout), ?_test(?assertReceive(Guard, Timeout))).
+
+%% This is mostly a convenience which gives more detailed reports.
+%% Note: Guard is a guarded pattern, and can not be used for value.
+-ifdef(NOASSERT).
-define(assertMatch(Guard, Expr), ok).
-else.
-define(assertMatch(Guard, Expr),