aboutsummaryrefslogtreecommitdiffstats
path: root/lib/eunit
diff options
context:
space:
mode:
Diffstat (limited to 'lib/eunit')
-rw-r--r--lib/eunit/include/eunit.hrl64
1 files changed, 44 insertions, 20 deletions
diff --git a/lib/eunit/include/eunit.hrl b/lib/eunit/include/eunit.hrl
index cae0ceed05..9e8d34567a 100644
--- a/lib/eunit/include/eunit.hrl
+++ b/lib/eunit/include/eunit.hrl
@@ -101,7 +101,7 @@
%% X gets a new, local binding.
%% (Note that lowercase 'let' is a reserved word.)
-ifndef(LET).
--define(LET(X,Y,Z), ((fun(X)->(Z)end)(Y))).
+-define(LET(X,Y,Z), begin ((fun(X)->(Z)end)(Y)) end).
-endif.
%% It is important that testing code is short and readable.
@@ -109,13 +109,13 @@
%% Compare: case f(X) of true->g(X); false->h(X) end
%% and: ?IF(f(X), g(Y), h(Z))
-ifndef(IF).
--define(IF(B,T,F), (case (B) of true->(T); false->(F) end)).
+-define(IF(B,T,F), begin (case (B) of true->(T); false->(F) end) end).
-endif.
%% This macro yields 'true' if the value of E matches the guarded
%% pattern G, otherwise 'false'.
-ifndef(MATCHES).
--define(MATCHES(G,E), (case (E) of G -> true; _ -> false end)).
+-define(MATCHES(G,E), begin (case (E) of G -> true; _ -> false end) end).
-endif.
%% This macro can be used at any time to check whether or not the code
@@ -139,6 +139,7 @@
%% for clauses that cannot match, even if the expression is a constant.
-undef(assert).
-define(assert(BoolExpr),
+ begin
((fun () ->
case (BoolExpr) of
true -> ok;
@@ -151,7 +152,8 @@
_ -> {not_a_boolean,__V}
end}]})
end
- end)())).
+ end)())
+ end).
-endif.
-define(assertNot(BoolExpr), ?assert(not (BoolExpr))).
@@ -167,6 +169,7 @@
-define(assertMatch(Guard, Expr), ok).
-else.
-define(assertMatch(Guard, Expr),
+ begin
((fun () ->
case (Expr) of
Guard -> ok;
@@ -177,7 +180,8 @@
{pattern, (??Guard)},
{value, __V}]})
end
- end)())).
+ end)())
+ end).
-endif.
-define(_assertMatch(Guard, Expr), ?_test(?assertMatch(Guard, Expr))).
@@ -186,6 +190,7 @@
-define(assertNotMatch(Guard, Expr), ok).
-else.
-define(assertNotMatch(Guard, Expr),
+ begin
((fun () ->
__V = (Expr),
case __V of
@@ -197,7 +202,8 @@
{value, __V}]});
_ -> ok
end
- end)())).
+ end)())
+ end).
-endif.
-define(_assertNotMatch(Guard, Expr), ?_test(?assertNotMatch(Guard, Expr))).
@@ -207,6 +213,7 @@
-define(assertEqual(Expect, Expr), ok).
-else.
-define(assertEqual(Expect, Expr),
+ begin
((fun (__X) ->
case (Expr) of
__X -> ok;
@@ -217,7 +224,8 @@
{expected, __X},
{value, __V}]})
end
- end)(Expect))).
+ end)(Expect))
+ end).
-endif.
-define(_assertEqual(Expect, Expr), ?_test(?assertEqual(Expect, Expr))).
@@ -226,6 +234,7 @@
-define(assertNotEqual(Unexpected, Expr), ok).
-else.
-define(assertNotEqual(Unexpected, Expr),
+ begin
((fun (__X) ->
case (Expr) of
__X -> erlang:error({assertNotEqual_failed,
@@ -235,7 +244,8 @@
{value, __X}]});
_ -> ok
end
- end)(Unexpected))).
+ end)(Unexpected))
+ end).
-endif.
-define(_assertNotEqual(Unexpected, Expr),
?_test(?assertNotEqual(Unexpected, Expr))).
@@ -246,6 +256,7 @@
-define(assertException(Class, Term, Expr), ok).
-else.
-define(assertException(Class, Term, Expr),
+ begin
((fun () ->
try (Expr) of
__V -> erlang:error({assertException_failed,
@@ -270,7 +281,8 @@
{__C, __T,
erlang:get_stacktrace()}}]})
end
- end)())).
+ end)())
+ end).
-endif.
-define(assertError(Term, Expr), ?assertException(error, Term, Expr)).
@@ -290,6 +302,7 @@
-define(assertNotException(Class, Term, Expr), ok).
-else.
-define(assertNotException(Class, Term, Expr),
+ begin
((fun () ->
try (Expr) of
_ -> ok
@@ -315,7 +328,8 @@
_ -> ok
end
end
- end)())).
+ end)())
+ end).
-endif.
-define(_assertNotException(Class, Term, Expr),
?_test(?assertNotException(Class, Term, Expr))).
@@ -326,6 +340,7 @@
%% these can be used for simply running commands in a controlled way
-define(_cmd_(Cmd), (eunit_lib:command(Cmd))).
-define(cmdStatus(N, Cmd),
+ begin
((fun () ->
case ?_cmd_(Cmd) of
{(N), __Out} -> __Out;
@@ -336,7 +351,8 @@
{expected_status,(N)},
{status,__N}]})
end
- end)())).
+ end)())
+ end).
-define(_cmdStatus(N, Cmd), ?_test(?cmdStatus(N, Cmd))).
-define(cmd(Cmd), ?cmdStatus(0, Cmd)).
-define(_cmd(Cmd), ?_test(?cmd(Cmd))).
@@ -347,6 +363,7 @@
-define(assertCmdStatus(N, Cmd), ok).
-else.
-define(assertCmdStatus(N, Cmd),
+ begin
((fun () ->
case ?_cmd_(Cmd) of
{(N), _} -> ok;
@@ -357,7 +374,8 @@
{expected_status,(N)},
{status,__N}]})
end
- end)())).
+ end)())
+ end).
-endif.
-define(assertCmd(Cmd), ?assertCmdStatus(0, Cmd)).
@@ -365,6 +383,7 @@
-define(assertCmdOutput(T, Cmd), ok).
-else.
-define(assertCmdOutput(T, Cmd),
+ begin
((fun () ->
case ?_cmd_(Cmd) of
{_, (T)} -> ok;
@@ -375,7 +394,8 @@
{expected_output,(T)},
{output,__T}]})
end
- end)())).
+ end)())
+ end).
-endif.
-define(_assertCmdStatus(N, Cmd), ?_test(?assertCmdStatus(N, Cmd))).
@@ -393,26 +413,30 @@
-define(debugTime(S, E), (E)).
-else.
-define(debugMsg(S),
- (begin
- io:fwrite(user, <<"~s:~w:~w: ~s\n">>,
- [?FILE, ?LINE, self(), S]),
- ok
- end)).
+ begin
+ io:fwrite(user, <<"~s:~w:~w: ~s\n">>,
+ [?FILE, ?LINE, self(), S]),
+ ok
+ end).
-define(debugHere, (?debugMsg("<-"))).
-define(debugFmt(S, As), (?debugMsg(io_lib:format((S), (As))))).
-define(debugVal(E),
+ begin
((fun (__V) ->
?debugFmt(<<"~s = ~P">>, [(??E), __V, 15]),
__V
- end)(E))).
+ end)(E))
+ end).
-define(debugTime(S, E),
+ begin
((fun () ->
{__T0, _} = statistics(wall_clock),
__V = (E),
{__T1, _} = statistics(wall_clock),
?debugFmt(<<"~s: ~.3f s">>, [(S), (__T1-__T0)/1000]),
__V
- end)())).
+ end)())
+ end).
-endif.