Browse files

Added expect_fun tests to test actual value against an anonymous func…

…tion.
  • Loading branch information...
1 parent 18dd588 commit f08ed1a5064794ac7135d5ce3ebab17b4243e115 @kenpratt kenpratt committed with ngerakines Sep 24, 2009
Showing with 25 additions and 2 deletions.
  1. +23 −2 src/etap.erl
  2. +2 −0 t/etap_t_001.erl
View
25 src/etap.erl
@@ -47,8 +47,8 @@
-export([
ensure_test_server/0, start_etap_server/0, test_server/1,
msg/1, msg/2, diag/1, diag/2, expectation_mismatch_message/3,
- plan/1, end_tests/0, not_ok/2, ok/2, is/3, isnt/3,
- any/3, none/3, fun_is/3, is_greater/3, skip/1, skip/2,
+ plan/1, end_tests/0, not_ok/2, ok/2, is/3, isnt/3, any/3, none/3,
+ fun_is/3, expect_fun/3, expect_fun/4, is_greater/3, skip/1, skip/2,
ensure_coverage_starts/0, ensure_coverage_ends/0, coverage_report/0,
datetime/1, skip/3, bail/0, bail/1
]).
@@ -263,6 +263,27 @@ none(Got, Items, Desc) ->
fun_is(Fun, Expected, Desc) when is_function(Fun) ->
is(Fun(Expected), true, Desc).
+%% @spec expect_fun(ExpectFun, Got, Desc) -> Result
+%% ExpectFun = function()
+%% Got = any()
+%% Desc = string()
+%% Result = true | false
+%% @doc Use an anonymous function to assert a pattern match, using actual
+%% value as the argument to the function.
+expect_fun(ExpectFun, Got, Desc) ->
+ evaluate(ExpectFun(Got), Got, ExpectFun, Desc).
+
+%% @spec expect_fun(ExpectFun, Got, Desc, ExpectStr) -> Result
+%% ExpectFun = function()
+%% Got = any()
+%% Desc = string()
+%% ExpectStr = string()
+%% Result = true | false
+%% @doc Use an anonymous function to assert a pattern match, using actual
+%% value as the argument to the function.
+expect_fun(ExpectFun, Got, Desc, ExpectStr) ->
+ evaluate(ExpectFun(Got), Got, ExpectStr, Desc).
+
%% @equiv skip(TestFun, "")
skip(TestFun) when is_function(TestFun) ->
skip(TestFun, "").
View
2 t/etap_t_001.erl
@@ -26,4 +26,6 @@ start() ->
etap:none(fun([{color, red} | _]) -> true; (_)-> false end, [[{something, nothing}, {somewhere, nowhere}], [{name, nick}, {has_family, true}], [{record, value}, {term, atom}]], "Proving etap:none/3 works with simple structures"),
etap:fun_is(fun(Expected) -> case Expected of "abc" ++ _ -> true; _ -> false end end, "abcdefg", "fun_is/3 works with simple lists"),
etap:fun_is(fun(Expected) -> case Expected of {foo, _} -> true; _ -> false end end, {foo, bar}, "fun_is/3 works with simple lists"),
+ etap:expect_fun(fun(Got) -> case Got of "abc" ++ _ -> true; _ -> false end end, "abcdefg", "expect_fun/3 works with simple lists"),
+ etap:expect_fun(fun(Got) -> case Got of {foo, _} -> true; _ -> false end end, {foo, bar}, "expect_fun/3 works with simple lists"),
etap:end_tests().

0 comments on commit f08ed1a

Please sign in to comment.