Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix calling mocked modules from expectation fun. #232

Merged
merged 1 commit into from
Aug 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ The format is based on [Keep a Changelog], and this project adheres to
### Fixed

- Fix misleading not_mocked errors when when unloading a mock [\#231](https://github.com/eproxus/meck/pull/231)
- Fix calling mocked modules from expectations fun [\#232](https://github.com/eproxus/meck/pull/232)

### Removed

Expand Down
3 changes: 2 additions & 1 deletion src/meck_code_gen.erl
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ exec(Pid, Mod, Func, Args) ->
-spec eval(Pid::pid(), Mod::atom(), Func::atom(), Args::[any()],
ResultSpec::any()) -> Result::any() | no_return().
eval(Pid, Mod, Func, Args, ResultSpec) ->
PreviousCall = get(?CURRENT_CALL),
put(?CURRENT_CALL, {Mod, Func}),
try
Result = meck_ret_spec:eval_result(Mod, Func, Args, ResultSpec),
Expand All @@ -183,7 +184,7 @@ eval(Pid, Mod, Func, Args, ResultSpec) ->
handle_exception(Pid, Mod, Func, Args,
Class, Reason, ?_get_stacktrace_(StackToken))
after
erase(?CURRENT_CALL)
put(?CURRENT_CALL, PreviousCall)
end.

-spec handle_exception(CallerPid::pid(), Mod::atom(), Func::atom(),
Expand Down
6 changes: 6 additions & 0 deletions test/meck_tests.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1376,6 +1376,12 @@ can_mock_sticky_modules_test() ->
?assert(code:is_sticky(meck_test_module)),
code:unstick_mod(meck_test_module).

meck_reentrant_test() ->
meck:new(string, [unstick, passthrough]),
meck:expect(string, strip,
fun(String) -> meck:passthrough([string:reverse(String)]) end),
?assertEqual(string:strip(" ABC "), "CBA"),
meck:unload(string).

sticky_directory_test_() ->
{foreach, fun sticky_setup/0, fun sticky_teardown/1,
Expand Down