eproxus/meck

Can not unload after passthrough meck

Closed this issue · 3 comments

The original module can not be recovered after passthrough meck.

Reproduction Steps

  1. meck:new(my_module,[passthrough]).
  2. meck:unload().
  3. erlang:module_loaded(my_module). --> false

Expected behavior

erlang:module_loaded(my_module) return true.

Observed behavior

Here is my trace, please notice that the parameter no_passthrough_cover is expected to be a binary one.
% 14:31:26 <0.4841.0>(my_module_meck)
% meck_proc:export_original_cover(my_module, {false,no_passthrough_cover})

% 14:31:26 <0.4841.0>(my_module_meck)
% meck_proc:export_original_cover/2 -> undefined

export_original_cover(Mod, {_, Bin}) when is_binary(Bin) ->
    OriginalMod = meck_util:original_name(Mod),
    BackupCover = meck_cover:dump_coverdata(OriginalMod),
    ok = meck_cover:rename_module(BackupCover, Mod),
    BackupCover;
export_original_cover(_, _) ->
    undefined.

Versions

  • Meck version: 0.9.0
  • Erlang version: OTP 22

This might be unexpected. If my_module wasn't loaded or didn't exist before mocking, this is not so strange. However, if it was loaded it could be considered a desired feature that Meck loads it back into memory the last thing it does. Currently Meck relies on Erlang to automatically load the module when it is used the next time.

To clarify: the behavior for Meck has always been like this and it is not something we've considered before.

This is now fixed by #228.