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

Deleting existing function does not work #238

Open
Juliusan opened this issue Aug 31, 2022 · 1 comment
Open

Deleting existing function does not work #238

Juliusan opened this issue Aug 31, 2022 · 1 comment
Labels

Comments

@Juliusan
Copy link

It was possible to delete the function, that is implemented, using meck:delete in version 0.9.0, however in 0.9.1 this throws an error.

Reproduction Steps

  1. Implement a module with some exported function:
-module(some_module).
-export([some_function/2]).
some_function(SomeArg1, SomeArg2) ->
    {ok, SomeArg1, SomeArg2}.
  1. Delete the exported function using meck and check if it is still available to be called.

Expected behavior

This test should pass:

meck_delete_test() ->
    ok = meck:new(some_module, [passthrough]),
    ?assert(erlang:function_exported(some_module, some_function, 2)),
    ok = meck:delete(some_module, some_function, 2, true),
    ?assertNot(erlang:function_exported(some_module, some_function, 2)),
    ?assert(meck:validate([some_module])),
    ok = meck:unload([some_module]).

Observed behavior

The test fails, indicating that second call to function_exported is still true.

Versions

  • Meck version: 0.9.1 (the test passes in 0.9.0)
  • Erlang version: 24.3
@eproxus eproxus added the bug label Oct 7, 2022
@Alberdi
Copy link

Alberdi commented Jan 2, 2024

Adding the non_strict flag makes the test above pass:

meck_delete_test() ->
    ok = meck:new(some_module, [passthrough, non_strict]),
    ?assert(erlang:function_exported(some_module, some_function, 2)),
    ok = meck:delete(some_module, some_function, 2, true),
    ?assertNot(erlang:function_exported(some_module, some_function, 2)),
    ?assert(meck:validate([some_module])),
    ok = meck:unload([some_module]).

I'm not sure about the exact semantics of combining passthrough with non_strict to know if this was a hidden "feature", or if this brings new problems. But this seems to work, at least, as a workaround.

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

3 participants