Skip to content
Browse files
Fix calling mocked modules from expectation fun.
Before this change calling a function in a mocked module
 from inside an expectation fun, and then calling
 meck:passthrough/1 raises an exception. This happens
  because the current function state is invalidated by
   the mocked function.
  • Loading branch information
pergu authored and eproxus committed Aug 25, 2021
1 parent 30f845f commit b9a3e6ed78c242a8203244a56f2a522b614e1610
Showing 3 changed files with 9 additions and 1 deletion.
@@ -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](
- Fix calling mocked modules from expectations fun [\#232](

### Removed

@@ -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}),
Result = meck_ret_spec:eval_result(Mod, Func, Args, ResultSpec),
@@ -183,7 +184,7 @@ eval(Pid, Mod, Func, Args, ResultSpec) ->
handle_exception(Pid, Mod, Func, Args,
Class, Reason, ?_get_stacktrace_(StackToken))
put(?CURRENT_CALL, PreviousCall)

-spec handle_exception(CallerPid::pid(), Mod::atom(), Func::atom(),
@@ -1376,6 +1376,12 @@ can_mock_sticky_modules_test() ->

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"),

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

0 comments on commit b9a3e6e

Please sign in to comment.