Exposed interface to assess success or failure returned by test.
authorStanislaw Klekot <dozzie@jarowit.net>
Mon, 15 Jun 2015 22:18:42 +0000 (00:18 +0200)
committerStanislaw Klekot <dozzie@jarowit.net>
Mon, 15 Jun 2015 22:18:42 +0000 (00:18 +0200)
src/estap_server.erl
src/estap_test.erl

index 85b943a..37b443e 100644 (file)
@@ -61,8 +61,9 @@ plan(TestCount) when is_integer(TestCount) ->
 -spec subplan(plan(), pos_integer()) ->
   test_run_id().
 
-subplan(TestCount, Level) when is_integer(TestCount), is_integer(Level) ->
-  {ok, Pid} = start_link(TestCount, Level),
+subplan(Plan, Level)
+when Plan == no_plan orelse is_integer(Plan), is_integer(Level) ->
+  {ok, Pid} = start_link(Plan, Level),
   Pid.
 
 %% @doc Mark the end of tests in this run.
index d73b75f..1ab7d4a 100644 (file)
@@ -8,6 +8,7 @@
 
 %% public interface
 -export([run/2]).
+-export([success_or_failure/1]).
 
 %% private interface
 -export([call/4]).
@@ -94,14 +95,8 @@ test({Mod, Func} = _TestFunSpec) ->
   ok.
 
 call({Pid, Ref} = _ResultTo, Mod, Fun, Args) ->
-  TestResult = try apply(Mod, Fun, Args) of
-    ok          -> {success, ok};
-    {ok, Value} -> {success, {ok, Value}};
-    true        -> {success, true};
-    error           -> {failure, error};
-    {error, Reason} -> {failure, {error, Reason}};
-    false           -> {failure, false};
-    Result          -> {dubious, Result}
+  TestResult = try
+    success_or_failure(apply(Mod, Fun, Args))
   catch
     throw:ok          -> {success, ok};
     throw:{ok, Value} -> {success, {ok, Value}};
@@ -115,5 +110,23 @@ call({Pid, Ref} = _ResultTo, Mod, Fun, Args) ->
 
 %%----------------------------------------------------------
 
+%% @doc Assess whether the value (returned by some function) is a success or
+%%   failure.
+
+-spec success_or_failure(Value) ->
+    {success, Value}
+  | {failure, Value}
+  | {dubious, Value}.
+
+success_or_failure(ok = Value)      -> {success, Value};
+success_or_failure({ok, _} = Value) -> {success, Value};
+success_or_failure(true = Value)    -> {success, Value};
+success_or_failure(error = Value)      -> {failure, Value};
+success_or_failure({error, _} = Value) -> {failure, Value};
+success_or_failure(false = Value)      -> {failure, Value};
+success_or_failure(Value) -> {dubious, Value}.
+
+%%----------------------------------------------------------
+
 %%%---------------------------------------------------------------------------
 %%% vim:ft=erlang:foldmethod=marker