Skip to content

Commit

Permalink
TEST check that we can replace calls to private functions
Browse files Browse the repository at this point in the history
This functionality will be implemented in moka_mod_utils
  • Loading branch information
samuelrivas committed Dec 13, 2012
1 parent ca84ac7 commit 601b377
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
22 changes: 22 additions & 0 deletions test/unit/moka_mod_utils_eunit.erl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ modify_remote_call_test_() ->
?_assertEqual(node(), Module:remote_bar())]}
end}.

modify_internal_call_test_() ->
Module = test_module(),
{setup,
setup_get_forms([Module]),
cleanup_restore_modules([Module]),
fun([AbsCode]) ->
{inorder,
[?_assertEqual({internal_result, 10}, Module:call_to_internal()),

?_test(moka_mod_utils:load_abs_code(
Module, modify_internal_call(AbsCode))),

?_assertEqual({argument, 10}, Module:call_to_internal())]}
end}.

%% Test we can capture the arguments of the substituted call
modify_remote_call_with_args_test_() ->
Module = test_module(),
Expand Down Expand Up @@ -152,5 +167,12 @@ modify_mult_call(AbsCode) ->
{?MODULE, hook_in, [factors, '$args']},
AbsCode).

modify_internal_call(AbsCode) ->
moka_mod_utils:replace_internal_calls(
{internal_fun, 1},
{?MODULE, hook_in, [argument, '$args']},
AbsCode).

%% We inject this function in some tests
hook_in(What, [A]) -> {What, A};
hook_in(What, [A, B]) -> {What, A, B}.
1 change: 0 additions & 1 deletion test/unit/moka_test_module.erl
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,3 @@ remote_mult(N) -> moka_test_module2:mult(N, 3).
call_to_internal() -> internal_fun(10).

internal_fun(N) -> {internal_result, N}.

0 comments on commit 601b377

Please sign in to comment.