You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running erlang in embedded mode, meck:new fails if the (original) module exists, but isn't loaded.
How to repeat
Compile to following module:
$ erlc +debug_info test.erl
Start Erlang in embbedded mode and load all the modules needed by meck, and mock the test module:
$ erl -mode embedded -pa meck/ebin/ -pa . -pa PATH_TO_ERL_INSTALL/lib//ebin/
application:start(compiler).
{ok, Modules} = application:get_key(compiler, modules).
[ l(M) || M <- Modules ++ [meck, meck_mod, cover] ].
4> meck:new(test).
* exception exit: undef
in function test:module_info/1
called as test:module_info(compile)
in call from meck_mod:compile_options/1
in call from meck:backup_original/1
in call from meck:init/1
in call from gen_server:init_it/6
in call from proc_lib:init_p_do_apply/3
Solution
Normally, in embedded mode, one doesn't meck a module that isn't. Thus, in practice the problem occurs when the module is first loaded and when running the sequence: meck:new(test), meck:unload(test), meck:new(test), since meck:unload doesn't load the original module, but rather relies on the code server auto-loading it.
A potential fix would be to call code:ensure_loaded in meck:unload, and call code:load_file if that returns {error, embedded}. Since the original module doesn't have to exist, any errors from code:load_file would have to be ignored though.
Perhaps meck:new should call code:ensure_loaded in the function backup_original, and not backup the original if the result is {error, embedded}.
The text was updated successfully, but these errors were encountered:
Closing this as 'not reproducible' for now. Haven't been able to produce a test case where this is repeatable. Please re-open with a pull-request and a test case if it's possible.
When running erlang in embedded mode, meck:new fails if the (original) module exists, but isn't loaded.
How to repeat
$ erlc +debug_info test.erl
$ erl -mode embedded -pa meck/ebin/ -pa . -pa PATH_TO_ERL_INSTALL/lib//ebin/
application:start(compiler).
{ok, Modules} = application:get_key(compiler, modules).
[ l(M) || M <- Modules ++ [meck, meck_mod, cover] ].
4> meck:new(test).
* exception exit: undef
in function test:module_info/1
called as test:module_info(compile)
in call from meck_mod:compile_options/1
in call from meck:backup_original/1
in call from meck:init/1
in call from gen_server:init_it/6
in call from proc_lib:init_p_do_apply/3
Solution
Normally, in embedded mode, one doesn't meck a module that isn't. Thus, in practice the problem occurs when the module is first loaded and when running the sequence:
meck:new(test), meck:unload(test), meck:new(test)
, sincemeck:unload
doesn't load the original module, but rather relies on the code server auto-loading it.code:ensure_loaded
inmeck:unload
, and callcode:load_file
if that returns{error, embedded}
. Since the original module doesn't have to exist, any errors fromcode:load_file
would have to be ignored though.meck:new
should callcode:ensure_loaded
in the functionbackup_original
, and not backup the original if the result is{error, embedded}
.The text was updated successfully, but these errors were encountered: