How do I install meck with my Erlang project?

I created my first Erlang project. This is a simple game with a secret code. I try to avoid OTP at all costs, because it seems REALLY confusing, and my mentor thought there was no need to use it in this round.

I have three folders: Ebin CSI test

I use the makefile to compile all the code and run the tests.

Life is good to this day ...

To mock my input (and outputs?) For the game, it was recommended to use Meck, but it is very difficult for me to integrate it into my project.

I tried to perform a manual installation. I made a git mek clone. I can "cd" to the eBin folder in the Meck directory and compile, run all system tests and execute the basic command "meck: new (dog)". Excellent!

Now I need to get Mek to work with my project ... I read this line in the Github Meck readme: "If you want to install your own version of meck, add the ebin directory to your Erlang code path or move the meck folder to your release folder and make sure that folder is in your environment variable ERL_LIBS ".

But I can’t figure out how to add the ebin directory to my path to the Erland code, I don’t have a folder with releases (does this I think is reinforcement?), And I don’t know how to add the ERL_LIBS environment variable. So I'm stuck.

Here's what I tried: To add the ebin directory to my code path, I did this in my makefile (I now have the meck directory on my desktop):

erlc -pa ~/Desktop/meck/ebin/ 

And I added ERL_LIBS to my .bash_profile, for example:

  export ERL_LIBS='~/Desktop/meck/ebin/' 

I also tried installing Agner and getting installation errors:

  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 

Can anyone help? I feel that there were several options for me, and none of them work.

Update:

This is what my make file looks like after reading @ d11wtq's solution:

  .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 

Final update:

Based on the tips, here is my last make file that now works.

  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 
+4
source share
2 answers

Just put meck (and all its subdirectories) in a subdirectory of your project; let's say deps /.

So now you will have:

 src/ ebin/ deps/ meck/ src/ ebin/ 

Since libs in Erlang are packaged in the same way as applications, there is an ERL_LIBS environment variable that tells the virtual machine where to look for libraries that your application uses. Mek is one of these libraries, and it is on the path "deps /".

 erl -pa ebin/ -env ERL_LIBS deps/ 

Meck should now be visible to the Erlang virtual machine.

+3
source

Quoting meck README :

Mek is best used with a reinforcing bar. Add the following dependency t to your rebar.config in the root of your project:

 {deps, [ {meck, ".*", {git, "https://github.com/eproxus/meck.git"}} ]}. 

Then run rebar get-deps and rebar compile .

+2
source

Source: https://habr.com/ru/post/1480303/


All Articles