Lager calls failing during Common Test test runs

雨燕双飞 提交于 2019-12-07 07:23:37

问题


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!


回答1:


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.




回答2:


This is a slight reformation of Stratus3D answer that does not shadow erlang.mk's values for ERLC_OPTS and TEST_ERLC_OPTS, but adds to them:

# this must be first
include erlang.mk

# Compile flags
ERLC_COMPILE_OPTS= +'{parse_transform, lager_transform}'

# Append these settings
ERLC_OPTS += $(ERLC_COMPILE_OPTS)
TEST_ERLC_OPTS += $(ERLC_COMPILE_OPTS)


来源:https://stackoverflow.com/questions/25530298/lager-calls-failing-during-common-test-test-runs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!