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

meck:new fails if running in embedded mode and module not loaded #35

Closed
bobergj opened this issue Aug 4, 2011 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@bobergj
Copy link
Collaborator

bobergj commented Aug 4, 2011

When running erlang in embedded mode, meck:new fails if the (original) module exists, but isn't loaded.

How to repeat

  1. Compile to following module:

$ erlc +debug_info test.erl

  1. 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}.
@ghost ghost assigned eproxus Aug 4, 2011
@eproxus
Copy link
Owner

eproxus commented Jan 10, 2012

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.

@eproxus eproxus closed this as completed Jan 10, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants