我创建了我的第一个Erlang项目。这是一个简单的密码游戏。我试图不惜一切代价避免OTP,因为这似乎确实令人困惑,我的导师认为没有必要在此过程中使用它。
我有三个文件夹:
宜宾
src
测试
我使用一个makefile来编译所有代码并运行测试。
直到今晚生活依然美好...
为了模拟游戏的输入(和输出?),建议我使用Meck,但是将其集成到项目中确实很难。
我尝试手动安装。我做了一个Meck的git克隆。我可以“cd”到Meck目录中的eBin文件夹并进行编译,运行所有系统测试并执行基本命令“meck:new(dog)”。惊人的!
现在我需要让Meck处理我的项目...我在Github Meck自述文件中读到了这一行:
“如果要安装自己的内置版本的meck,请将ebin目录添加到您的Erlang代码路径中,或将meck文件夹移至您的发布文件夹中,并确保该文件夹位于您的ERL_LIBS环境变量中。”
但是我不知道如何将ebin目录添加到我的Erland代码路径中,我没有发布文件夹(这是我认为的钢筋内容?),而且我不知道如何添加ERL_LIBS环境变量。所以我被卡住了。
这是我尝试过的:
要将ebin目录添加到我的代码路径中,我在我的makefile中执行了此操作(我的桌面上现在有meck目录):
erlc -pa ~/Desktop/meck/ebin/
然后将ERL_LIBS添加到我的.bash_profile中,如下所示:
export ERL_LIBS='~/Desktop/meck/ebin/'
我还尝试安装Agner并在安装时出现错误:
ERROR: compile failed while processing /private/tmp/agner.0r04Vm: {'EXIT',
{undef,
[{rebar,get_jobs,
[{config,"/private/tmp/agner.0r04Vm",
[{require_otp_vsn,"R14|R15"},
{lib_dirs,["deps"]},
{escript_incl_apps,
[getopt,gproc,rebar,plists,gen_fsm2,jsx]},
{erl_opts,[{i,"deps"}]},
{plugins,[agner_rebar_plugin]},
local]}],
[]},
{rebar_base_compiler,run,4,
[{file,"src/rebar_base_compiler.erl"},{line,49}]},
{rebar_erlc_compiler,doterl_compile,3,
[{file,"src/rebar_erlc_compiler.erl"},{line,157}]},
{rebar_core,run_modules,4,[{file,"src/rebar_core.erl"},{line,420}]},
{rebar_core,execute,4,[{file,"src/rebar_core.erl"},{line,354}]},
{rebar_core,process_dir0,6,[{file,"src/rebar_core.erl"},{line,217}]},
{rebar_core,process_dir,4,[{file,"src/rebar_core.erl"},{line,128}]},
{rebar_core,process_commands,2,
[{file,"src/rebar_core.erl"},{line,83}]}]}}
make: *** [compile] Error 1
有人可以帮忙吗?我觉得我有几种选择可以尝试,但没有一个起作用。
更新:
阅读@ d11wtq的解决方案后,我的make文件如下所示:
.SUFFIXES: .erl .beam .yrl
.erl.beam:
erlc -W $<
.yrl.erl:
erlc -W $<
ERL = erl -boot start_clean
MODS = console_io feedback mastermind secret_code meck
all: compile path run_test
compile:
erlc -o ebin/ src/*.erl
erlc -o ebin/ test/*.erl
path:
erlc -pa ebin/
-env ERL_LIBS deps/
run_test:
erl -noshell -pa ebin \
-eval 'eunit:test("ebin").' \
-eval 'mastermind:start_game().' \
-s init stop
clean:
rm -rf ebin/*.beam
rm -rf erl_crash.dump
最终更新:
根据提示,这是我现在可以使用的最终makefile。
all: compile run_test run_game
compile:
erlc -o ebin/ src/*.erl
erlc -o ebin/ test/*.erl
run_test:
erl -pa ebin \
-env ERL_LIBS deps/ \
-eval 'eunit:test("ebin").' \
-s init stop
run_game:
erl -pa ebin \
-env ERL_LIBS deps/ \
-eval "mastermind:start_game()." \
-s init stop
clean:
rm -rf ebin/*.beam
rm -rf erl_crash.dump
最佳答案
只需将meck(及其所有子目录)放在项目的子目录中即可;例如,部门/。
所以现在您将拥有:
src/
ebin/
deps/
meck/
src/
ebin/
由于Erlang中的库与应用程序的打包方式相同,因此存在环境变量ERL_LIBS,该变量将告诉VM在哪里可以找到您的应用程序使用的库。 Meck是其中的一个库,它位于路径“deps/”中。
erl -pa ebin/ -env ERL_LIBS deps/
现在,meck对Erlang VM应该可见。
关于erlang - 如何在我的Erlang项目中安装meck?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/16503603/