eproxus / meck

A mocking library for Erlang
http://eproxus.github.io/meck
Apache License 2.0
811 stars 231 forks source link

Can not unload after passthrough meck #214

Closed TC-yWu closed 3 years ago

TC-yWu commented 3 years ago

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

eproxus commented 3 years ago

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.

eproxus commented 3 years ago

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

eproxus commented 3 years ago

This is now fixed by #228.