erlangeunitcommon-testrebar3

Using Rebar3 Common Test does not find hrl files in the include folder but eunit does


Using rebar3 eunit it is able to handle -include("some_file.hrl") in the tests, but this doesn't work with rebar3 ct. For some reason when I use rebar3 ct it tries to compile my eunit tests and fails because it can't find the .hrl files used in the eunit tests. ...can't find include file "some_file.hrl" What am I doing wrong? Why is it compiling eunit tests when I'm trying to run CT tests?


Solution

  • Quick answer:

    Additional compile options for eunit. erl_opts can be used like this with rebar3:

    {eunit_compile_opts, [
    {i, "custominclude"},
    {i, "include"},
    {i, "deps/nice/include"},
    {i, "/usr/lib64/erlang/lib/some-1.3.0/include"}
    ]}.
    

    https://github.com/erlang/rebar3/blob/fb363cd8de68e9113e407ac0be049cacdd9ddd07/rebar.config.sample#L165

    More about this subject

    rebar3 change the way eunit tests are performed.

    Original rebar2 behavior was to compile your project and anything in the test directory (including subdirectories) to the directory .eunit and then run tests from every file. That's why your include files directive may work under rebar2 simply because all files are included and centralized.

    Rebar3 instead, by default, sets Tests to [{application, yourapp}].The eunit command of rebar3 first does some preparation work and after this calls eunit:test(Tests, EUnitOpts).

    Notice that:

    1. test sets can be specified via {eunit_tests, [...]} in rebar.config
    2. rebar3 has application, module, file and dir command line flags that mirror the eunit test representations.

    http://www.rebar3.org/docs/from-rebar-2x-to-rebar3

    Since rebar3 ct will take all this in account, being more configurable and less automated (not including all of your applications and deps) this may happen to you.