当我运行单元测试时,我以依赖应用程序的身份启动lager,但由于某种原因,测试中的代码没有看到它。
-module(main_tests).
-include_lib("eunit/include/eunit.hrl").
main_test_() ->
{foreach,
fun distr_setup/0,
fun distr_cleanup/1,
[
fun must_retain/1
]}.
must_retain(_) ->
{"Should do ping pong when is fully initialized",
fun() ->
?assertEqual(pong, abuse_counter:ping())
end}.
%%------------------------------------------------------------------
distr_setup() ->
abuse_counter:start_link(),
ok.
distr_cleanup(_) ->
abuse_counter:stop(),
ok.下面是日志的输出,它抱怨没有定义{undef,[{ lager,info,"up and run“,[]},尽管在运行输出中肯定存在。
下面是我运行它的方式:
erl -pa ebin/ ../../deps/*/ebin -s lager -eval 'eunit:test(main_tests,[verbose]), init:stop().'输出失败
Eshell V5.10.2 (abort with ^G)
1> 17:13:31.506 [info] Application lager started on node nonode@nohost
======================== EUnit ========================
module 'main_tests'
undefined
17:13:31.528 [error] CRASH REPORT Process <0.57.0> with 1 neighbours exited with reason: call to undefined function lager:info("up and running") in gen_server:init_it/6 line 328
*unexpected termination of test process*
::**{undef,[{lager,info,["up and running"],[]}**,
{abuse_counter,init,1,[{file,"src/abuse_counter.erl"},{line,37}]},
{gen_server,init_it,6,[{file,"gen_server.erl"},{line,304}]},
{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]}
=======================================================
Failed: 0. Skipped: 0. Passed: 0.
One or more tests were cancelled.已经花了3到4小时在谷歌和堆栈溢出,但似乎没有任何工作。
一种选择是将这个调用隐藏在一个?INFO(Mgs)宏后面,但不喜欢这个想法。
任何帮助都将不胜感激。
发布于 2013-10-31 21:50:56
因此,看起来src/abuse_counter.erl文件不是用{parse_transform, lager_transform}选项编译的。
函数lager:info("message!"),实际上并不存在,parse_transform将lager:info("message!")转换为这个函数:lager:dispatch_log(info, Metadata, "message!", [], Size)。
尝试使用{parse_transform, lager_transform}选项重新编译模块。
拉格展示了如何做到这一点:链接到自述文件。
https://stackoverflow.com/questions/19716949
复制相似问题