本文介绍了在普通测试测试运行期间,Lager调用失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我决定在我的Erlang项目中设置缓存。我使用erlang.mk,所以我添加了

  ERLC_OPTS = +'{parse_transform,lager_transform}'

到我的Makefile。我可以运行 make all 并编译没有错误的模块。我也可以启动一个 erl 控制台,并使用Lager运行包含模块的应用程序。在控制台会话期间不会生成错误并且记录消息。好像一切都好(这是我第一次使用过啤酒)。但是,当我运行通用测试时,Lager呼叫失败:



10:11:17.174 [错误] CRASH报告过程< 0.238.0& ;有两个邻居退出原因:在gen_server中调用undefined函数lager:info(Params:〜p,[[]]):init_it / 6第328行



由于看起来我正在测试的模块已经正确编译,我认为这是一个Lager模块不存在的问题。但是,如果我添加:

  erlang:display(lager:module_info()),

上面的第一个lager调用成功,打印lager的模块信息。我假设我正在做的日志调用正在利用一些解析变换魔法来工作,这在我的普通测试运行中不存在。



任何建议都非常感谢原来我在Makefile中有一个误区,但是在这个过程中我学到了很多关于erlang.mk的信息。 erlang.mk正在寻找一个名称不同的变量。



我原来是在我的Makefile中:

  ERLC_OPTS = +' {parse_transform,lager_transform}'

但是,在测试它们之前,erlang.mk不使用ERLC_OPTS编译模块。它总是在普通测试套件之前重新编译。为了让模块编译用解析变换进行测试,我需要这样做:

 #编译标志
ERLC_COMPILE_OPTS = +'{parse_transform,lager_transform}'

#使用相同的设置编译版本以及测试
ERLC_OPTS = $(ERLC_COMPILE_OPTS)
TEST_ERLC_OPTS = $(ERLC_COMPILE_OPTS )

这样可以确保应用程序源代码在测试期间使用完全相同的设置进行编译。 p>

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!

解决方案

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.

这篇关于在普通测试测试运行期间,Lager调用失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-08 14:14