Browse files

Updates to etap tests.

  • Loading branch information...
1 parent b73c7e0 commit 1d313208abfbb8698ef953a8b223c106c4c87d94 @davisp committed Mar 21, 2011
Showing with 46 additions and 73 deletions.
  1. +2 −1 Makefile
  2. +7 −9 test/001-basics.t
  3. +9 −13 test/003-test-ctx-creation.t
  4. +3 −14 test/004-basic-calls.t
  5. +2 −11 test/005-erl-to-js.t
  6. +2 −12 test/006-js-to-erl.t
  7. +3 −13 test/007-js-send-message.t
  8. +18 −0 test/test_util.erl
View
3 Makefile
@@ -1,6 +1,7 @@
TEST_SUPPORT = \
- test/etap.beam
+ test/etap.beam \
+ test/test_util.beam
%.beam: %.erl
erlc -o test/ $<
View
16 test/001-basics.t
@@ -1,19 +1,17 @@
-#! /usr/bin/env escript
+#! /usr/bin/env escript
+%%! -pa ./test/ -pa ./ebin/
% This file is part of Emonk released under the MIT license.
% See the LICENSE file for more information.
main([]) ->
- code:add_pathz("test"),
- code:add_pathz("ebin"),
+ test_util:run(length(modules()), fun() -> test() end).
- Modules = [
- emonk
- ],
+modules() ->
+ [emonk].
- etap:plan(length(Modules)),
+test() ->
lists:foreach(fun(Mod) ->
Mesg = atom_to_list(Mod) ++ " module loaded",
etap:loaded_ok(Mod, Mesg)
- end, Modules),
- etap:end_tests().
+ end, modules()).
View
22 test/003-test-ctx-creation.t
@@ -1,7 +1,16 @@
#! /usr/bin/env escript
+%%! -pa ./test/ -pa ./ebin/
% This file is part of Emonk released under the MIT license.
% See the LICENSE file for more information.
+
+main([]) ->
+ test_util:run(100, fun() -> test() end).
+
+test() ->
+ lists:foreach(fun(_) -> test_vm_creation() end, lists:seq(1, 100, 1)),
+ erlang:garbage_collect().
+
test_vm_creation() ->
etap:fun_is(
fun({ok, _}) -> true; (_) -> false end,
@@ -10,16 +19,3 @@ test_vm_creation() ->
),
erlang:garbage_collect().
-main([]) ->
- code:add_pathz("test"),
- code:add_pathz("ebin"),
-
- etap:plan(101),
-
- test_vm_creation(),
-
- lists:foreach(fun(_) -> test_vm_creation() end, lists:seq(1, 100, 1)),
- erlang:garbage_collect(),
-
- etap:end_tests().
-
View
17 test/004-basic-calls.t
@@ -1,20 +1,10 @@
#!/usr/bin/env escript
+%%! -pa ./test/ -pa ./ebin/
% This file is part of Emonk released under the MIT license.
% See the LICENSE file for more information.
main(_) ->
- code:add_pathz("test"),
- code:add_pathz("ebin"),
-
- etap:plan(10),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail()
- end,
- ok.
+ test_util:run(10, fun() -> test() end).
test() ->
{ok, Ctx} = emonk:create_ctx(),
@@ -26,8 +16,7 @@ test() ->
test_call_undefined(Ctx),
test_eval_error(Ctx),
- test_call_error(Ctx),
- ok.
+ test_call_error(Ctx).
test_eval_ok(Ctx) ->
etap:is(
View
13 test/005-erl-to-js.t
@@ -1,20 +1,11 @@
#!/usr/bin/env escript
+%%! -pa ./test/ -pa ./ebin/
% This file is part of Emonk released under the MIT license.
% See the LICENSE file for more information.
main(_) ->
- code:add_pathz("test"),
- code:add_pathz("ebin"),
+ test_util:run(29, fun() -> test() end).
- etap:plan(29),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail()
- end,
- ok.
test() ->
{ok, Ctx} = emonk:create_ctx(),
View
14 test/006-js-to-erl.t
@@ -1,20 +1,10 @@
#!/usr/bin/env escript
+%%! -pa ./test/ -pa ./ebin/
% This file is part of Emonk released under the MIT license.
% See the LICENSE file for more information.
main(_) ->
- code:add_pathz("test"),
- code:add_pathz("ebin"),
-
- etap:plan(unknown),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail()
- end,
- ok.
+ test_util:run(30, fun() -> test() end).
test() ->
{ok, Ctx} = emonk:create_ctx(),
View
16 test/007-js-send-message.t
@@ -1,20 +1,10 @@
#!/usr/bin/env escript
+%%! -pa ./test/ -pa ./ebin/
% This file is part of Emonk released under the MIT license.
% See the LICENSE file for more information.
main(_) ->
- code:add_pathz("test"),
- code:add_pathz("ebin"),
-
- etap:plan(unknown),
- case (catch test()) of
- ok ->
- etap:end_tests();
- Other ->
- etap:diag(io_lib:format("Test died abnormally: ~p", [Other])),
- etap:bail()
- end,
- ok.
+ test_util:run(unknown, fun() -> test() end).
test() ->
{ok, Ctx} = emonk:create_ctx(),
@@ -29,4 +19,4 @@ test_send_exists(Ctx) ->
test_send_message(Ctx) ->
JS = <<"var f = erlang.send(1.3) == 2.6; f;">>,
{message, Token, Data} = emonk:eval(Ctx, JS),
- etap:is(emonk:send(Ctx, Token, Data * 2), {ok, true}, "message passed ok").
+ etap:is(emonk:send(Ctx, Token, Data * 2), {ok, true}, "message passed ok").
View
18 test/test_util.erl
@@ -0,0 +1,18 @@
+% This file is part of Emonk released under the MIT license.
+% See the LICENSE file for more information.
+-module(test_util).
+
+-export([run/2]).
+
+run(Plan, Fun) ->
+ etap:plan(Plan),
+ try
+ Fun(),
+ etap:end_tests()
+ catch
+ Type:Error ->
+ etap:diag("Test died abnormally: ~p:~p", [Type, Error]),
+ etap:diag("~p", [erlang:get_stacktrace()]),
+ etap:bail()
+ end.
+

0 comments on commit 1d31320

Please sign in to comment.