#!/usr/bin/escript
-%%
+%%! -pa ebin
%%----------------------------------------------------------------------------
main([]) -> main(["--help"]);
io:fwrite("Usage: ~s filename~n", [escript:script_name()]);
main([File]) ->
- {ok, {Module, Forms}} = estap_file:read_file(File, []),
+ {ok, {_Module, Forms}} = estap_file:read_file(File, []),
{ok, {Plan, Tests}} = estap_file:load_code(Forms),
- io:fwrite("plan: ~p~ntests: ~p~n", [Plan, Tests]).
+ TestRunId = case Plan of
+ no_plan -> estap_server:no_plan();
+ {plan, C} -> estap_server:plan(C)
+ end,
+ io:fwrite("plan: ~p~ntests: ~p~n", [Plan, Tests]),
+ run_tests(Tests, TestRunId).
+
+%%----------------------------------------------------------------------------
+
+run_tests([] = _Tests, TestRunId) ->
+ estap_server:done(TestRunId),
+ ok;
+run_tests([{{Mod, Func}, Description, Status} | Rest] = _Tests, TestRunId) ->
+ % TODO: bail out support
+ case Status of
+ run ->
+ {Pid, Ref} = spawn_monitor(
+ fun() ->
+ estap_server:running(TestRunId, Description),
+ try Mod:Func() of
+ ok -> estap_server:test_passed(TestRunId);
+ {ok, _Value} -> estap_server:test_passed(TestRunId);
+ true -> estap_server:test_passed(TestRunId);
+ error -> estap_server:test_failed(TestRunId, error);
+ {error, Reason} -> estap_server:test_failed(TestRunId, {error, Reason});
+ false -> estap_server:test_failed(TestRunId, false);
+ Result -> estap_server:dubious_result(TestRunId, Result)
+ catch
+ throw:ok -> estap_server:test_passed(TestRunId);
+ throw:{ok, _Value} -> estap_server:test_passed(TestRunId);
+ throw:true -> estap_server:test_passed(TestRunId);
+ throw:error -> estap_server:test_failed(TestRunId, error);
+ throw:{error, Reason} -> estap_server:test_failed(TestRunId, {error, Reason});
+ throw:false -> estap_server:test_failed(TestRunId, false)
+ end
+ end
+ ),
+ receive
+ {'DOWN', Ref, process, Pid, normal} ->
+ estap_server:join_test(Pid);
+ {'DOWN', Ref, process, Pid, Reason} ->
+ estap_server:test_died(Pid, Reason)
+ end,
+ run;
+ {skip, Why} ->
+ estap_server:test_skipped(TestRunId, Description, Why),
+ skip;
+ {todo, Why} ->
+ estap_server:test_todo(TestRunId, Description, Why),
+ todo
+ end,
+ run_tests(Rest, TestRunId).
%%----------------------------------------------------------------------------
%% vim:ft=erlang
-behaviour(gen_server).
%% public interface
--export([]).
+-export([no_plan/0, plan/1, done/1]).
+-export([running/2, join_test/1, test_skipped/3, test_todo/3]).
+-export([test_passed/1, test_failed/2, dubious_result/2, test_died/2]).
%% supervision tree API
-export([start/0, start_link/0]).
%%%---------------------------------------------------------------------------
+-type test_run_id() :: reference().
+
-record(state, {
}).
%%% public interface
%%%---------------------------------------------------------------------------
+%% @doc "No plan" plan.
+
+-spec no_plan() ->
+ test_run_id().
+
+no_plan() ->
+ 'TODO'.
+
+%% @doc Test plan.
+
+-spec plan(pos_integer()) ->
+ test_run_id().
+
+plan(_TestCount) ->
+ 'TODO'.
+
+%% @doc Mark the end of tests in this run.
+
+done(_TestRunId) ->
+ 'TODO'.
+
+%% @doc Mark the beginning of new test.
+%% Call this before call to test function.
+
+running(_TestRunId, _Description) ->
+ 'TODO'.
+
+%% @doc Mark the end of a test with a success.
+
+test_passed(_TestRunId) ->
+ 'TODO'.
+
+%% @doc Mark the end of a test with a failure.
+
+test_failed(_TestRunId, _Value) ->
+ 'TODO'.
+
+%% @doc Mark the end of a test with a failure, but a dubious one.
+
+dubious_result(_TestRunId, _Value) ->
+ 'TODO'.
+
+%% @doc Mark the end of a test with an exception.
+%% This means that the test function, which was called in `Pid' process,
+%% simply died.
+
+test_died(_Pid, _Reason) ->
+ % XXX: synchronous call
+ 'TODO'.
+
+%% @doc Wait until all the processing of test results submitted by `Pid' is
+%% finished.
+
+join_test(_Pid) ->
+ 'TODO'.
+
+%% @doc Mark the test as skipped.
+
+test_skipped(_TestRunId, _Description, _Reason) ->
+ 'TODO'.
+
+%% @doc Mark the test as "TODO".
+
+test_todo(_TestRunId, _Description, _Reason) ->
+ 'TODO'.
+
%%%---------------------------------------------------------------------------
%%% supervision tree API
%%%---------------------------------------------------------------------------