Skip to content

Commit

Permalink
testing of compilation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
sasa1977 committed Jan 9, 2013
1 parent 459b25b commit 538ca31
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion test/dynamic_generator.erl
Expand Up @@ -4,7 +4,7 @@
% we can check that transform correctly generates errors.

-module(dynamic_generator).
-export([exec_dynamic/3]).
-export([exec_dynamic/3, compile/4]).

-include_lib("eunit/include/eunit.hrl").

Expand Down
27 changes: 20 additions & 7 deletions test/fun_chain_tests.erl
Expand Up @@ -3,11 +3,11 @@

chain_last_test_() ->
[
?_assertEqual(dict:new(), compile_dynamic("fun_chain:last(dict:new())")),
?_assertEqual(dict:new(), exec_dynamic("fun_chain:last(dict:new())")),

?_assertEqual(
dict:from_list([{b,2}, {c,3}]),
compile_dynamic("
exec_dynamic("
fun_chain:last(dict:new(),
dict:store(a,1),
dict:store(b,2),
Expand All @@ -19,12 +19,12 @@ chain_last_test_() ->

?_assertEqual(
dict:new(),
compile_dynamic("fun_chain:last(fun_chain:last(dict:new()))")
exec_dynamic("fun_chain:last(fun_chain:last(dict:new()))")
),

?_assertEqual(
dict:from_list([{a,1}]),
compile_dynamic("
exec_dynamic("
fun_chain:last(dict:new(),
(fun(Dict) ->
dict:store(a,1,Dict)
Expand All @@ -35,7 +35,7 @@ chain_last_test_() ->

?_assertEqual(
dict:from_list([{a,1}]),
compile_dynamic("
exec_dynamic("
fun_chain:last(dict:new(),
(fun(Dict) ->
fun_chain:last(Dict, dict:store(a,1))
Expand All @@ -48,15 +48,28 @@ chain_last_test_() ->

chain_first_test_() ->
[
?_assertEqual(9, compile_dynamic("
?_assertEqual(9, exec_dynamic("
Inc = fun(X, Increment) -> X + Increment end,
fun_chain:first(1, Inc(3), Inc(5))
"))
].

error_test_() -> [
?_assertMatch({error, _, _}, compile("fun_chain:last()")),
?_assertMatch({error, _, _}, compile("fun_chain:invalid_function(3)")),
?_assertMatch({error, _, _}, compile("fun_chain:last(3,3)"))
].

% Dynamic execution of the code. See dynamic_generator for explanation.
compile_dynamic(Code) ->
exec_dynamic(Code) ->
dynamic_generator:exec_dynamic(dynamic_test,
"-compile({parse_transform, fun_chain}).",
Code
).

compile(Code) ->
dynamic_generator:compile(dynamic_test,
"-compile({parse_transform, fun_chain}).",
Code,
fun(Result) -> Result end
).

0 comments on commit 538ca31

Please sign in to comment.