Disclaimer: The author of this question has mostly theoretical knowledge of Erlang/OTP.
I have a small OTP application which calls some non-Erlang executable inside the myapp/ebin
directory via open_port()
. When I run the application itself everything goes well and the port to the executable is successfully opened.
But when I try to run unit tests for the application, the ones that depend on the open_port()
fail, because when started with EUnit
the application tries to find the executable under myapp/.eunit/ebin
.
How can I change that behaviour without changing the code of the application itself? How can I run EUnit tests with the same current directory as when running the application itself? (I mean it would not be a good idea to change the code which provides the path to the executable just to be able to run EUnit).
Edit: I followed the advice in the Erlang mailing list, but code:priv_dir(myapp_name)
returns {error, bad_name}
.
Edit: I can see that .eunit/
contains modulename.beam
files and ebin/
contains both modulename.beam
files and modulename_tests.beam
files. Now I am completely lost. When I run make test
, rebar
runs eunit
command, which calls each modulename_tests.beam
file in the ebin/
directory which calls a corresponding modulename.beam
file in the .eunit/
directory (filename:absname("")
clearly shows that modulename.beam
files are executed from .eunit/
during test). Why is it so? Why do we need to run modulename.beam
files from the .eunit/
directory instead of ebin/
?
Why do we actually need to have the very same .beam files in myapp/ebin
and myapp/.eunit/ebin
?
P.S. I have read the official documentation and did not find the solution.