function_exported/3 and CT

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

function_exported/3 and CT

Roberto Ostinelli-5
All,
I'm experiencing something a little strange. I have a module test_event_handler.erl which exports the method resolve_registry_conflict/3.

This file is in the /test directory from where I run all of my Common Tests. For some reason, the call to erlang:function_exported(test_event_handler, resolve_registry_conflict, 3) returns true if I run rebar3 clean before running tests, otherwise false. This is true both when this call is run into the test itself, or in the code being tested.

Has someone seen this behavior? What am I missing?

Thank you,
r.
Reply | Threaded
Open this post in threaded view
|

Re: function_exported/3 and CT

José Valim-2
It is probably related to the module being loaded? function_exported/3 does not load modules and will return false if the module has not been loaded yet. Something in rebar3 lifecycle may be loading it under certain circumstances. Try calling code:ensure_loaded/1 before function_exported and see if the behavior becomes consistent.--


José Valim
Founder and Director of R&D
Reply | Threaded
Open this post in threaded view
|

Re: function_exported/3 and CT

Roberto Ostinelli-5
You were definitely right. Only change I've done is that instead of using code:ensure_loaded/1 (which doesn't work in embedded mode, for the 3 people that use it in the world ^^_) I am using a simple catch test_event_handler:module_info(exports) which seems to do the trick.

Thank you Jose,
r.


On Fri, Nov 15, 2019 at 10:20 AM Roberto Ostinelli <[hidden email]> wrote:
You were definitely right. Only change I've done is that instead of using code:ensure_loaded/1 (which doesn't work in embedded mode, for the 3 people that use it in the world ^^_) I am using a simple catch test_event_handler:module_info(exports) which seems to do the trick.

Thank you Jose,
r.

On Thu, Nov 14, 2019 at 8:34 PM José Valim <[hidden email]> wrote:
It is probably related to the module being loaded? function_exported/3 does not load modules and will return false if the module has not been loaded yet. Something in rebar3 lifecycle may be loading it under certain circumstances. Try calling code:ensure_loaded/1 before function_exported and see if the behavior becomes consistent.--


José Valim
Founder and Director of R&D