Search code examples
makefileerlangcommon-testlagerparse-transform

Lager calls failing during Common Test test runs


I decided to setup lager in my Erlang project. I am using erlang.mk, so I added

ERLC_OPTS = +'{parse_transform, lager_transform}' 

to my Makefile. I can run make all and compile the modules without errors. I can also start an erl console and run the application containing the modules using lager. No errors are generated and lager logs messages during the console session. It seems as though everything is fine (this is the first time I have used lager). But, when I run Common Test, the lager calls fail:

10:11:17.174 [error] CRASH REPORT Process <0.238.0> with 2 neighbours exited with reason: call to undefined function lager:info("Params: ~p", [[]]) in gen_server:init_it/6 line 328

Since it appears as if the modules I am testing have been compile correctly, I assume this is an issue with lager module not being present. However, if I add this:

erlang:display(lager:module_info()),

above the first lager call it succeeds, printing the module info for lager. I assume the logging calls I am making are utilizing some parse transform magic in order to work and this is not present during my the Common Test runs.

Any suggestions are greatly appreciated!


Solution

  • Turns out I had a mispelling in my Makefile but I learned alot about erlang.mk in the process. erlang.mk was looking for a variable with a different name.

    I originally this in my Makefile:

    ERLC_OPTS = +'{parse_transform, lager_transform}'
    

    But erlang.mk doesn't use ERLC_OPTS for compiling modules before testing them. It always recompiles before the Common Test suites. In order to have the modules compile with the parse transform for testing I needed to do this:

    # Compile flags
    ERLC_COMPILE_OPTS= +'{parse_transform, lager_transform}'
    
    # Use the same settings for compiling releases as well as for testing
    ERLC_OPTS= $(ERLC_COMPILE_OPTS)
    TEST_ERLC_OPTS= $(ERLC_COMPILE_OPTS)
    

    This makes sure that the application source code is compiled with the exact same settings during testing.