I have running application and in the interactive console I try to run common test suites located in test/common directory:
ct:run("test/common").
But I get a bunch of errors:
Reason: undef
and all tests fail.
I tried to run them from linux shell
ct_run -dir test/common
or like this:
ct_run -boot start_sasl -spec test/common/app_ct.spec -erl_args -config env/dev.config
with the same result.
But when I run them using rebar (the second version, not rebar3)
rebar ct
Everything works, tests pass. But it takes too much time to compile the app and to start it.
In the rebar.config I have:
{ct_dir,"test/common"}.
{ct_log_dir,"test/logs"}.
{ct_extra_params,"-boot start_sasl -pa deps/*/ebin -pa ebin -spec test/common/app_ct.spec -erl_args -config env/dev.config"}.
and in the test/common/app_ct.spec I have:
{verbosity, 100}.
{init, {eval, [{application, ensure_all_started, [app]}, {timer, sleep, [30000]}]}}.
{alias, common, "./test/common/"}.
{suites, "", [app_srv_SUITE, app_client_SUITE]}.
What can I do to run tests from erl console using ct:run("test/common")?
My goal is to be able to recompile single test files individually and run tests from working application console without stopping and recompiling all application.
I recompile singular test module without problems like this:
c("test/common/new_mod_SUITE.erl", [{i, "include"}, {i, "deps"}, {outdir, "test/common"}]).
But I still can't run tests after that.
First of all, need to be sure that all tests is compiled and they are inside of folder what is put as argument into ct:run/1. If need to run only one test from specific folder, can be used ct:run/2. If need to run specific test case from specific folder, can be used specific folder ct:run/3. Examples:
1> ct:run("test/common").
2> ct:run("test/common", "some_SUITE").
However I would recommend using rebar3, in rebar3 was added option like --dir and tests from specific folder can be run like:
$ ./rebar3 ct --dir="test/common"
This probably won't help, but here is what happens for me using rebar3:
~/erlang_programs/myrebar/myapp$ ls
LICENSE _build rebar.lock test
README.md rebar.config src
~/erlang_programs/myrebar/myapp$ cd src
~/erlang_programs/myrebar/myapp/src$ ls
a.erl myapp_app.erl rebar.lock
myapp.app.src myapp_sup.erl
~/erlang_programs/myrebar/myapp/src$ cat a.erl
-module(a).
-compile(export_all).
%%-include("eunit.hrl").
hello() -> io:format("hello").
~/erlang_programs/myrebar/myapp/src$ cd ../test
~/erlang_programs/myrebar/myapp/test$ ls
a_SUITE.erl
~/erlang_programs/myrebar/myapp/test$ cat a_SUITE.erl
-module(a_SUITE).
-compile(export_all).
all() -> [go].
go(_Config) ->
1 = 1.
~/erlang_programs/myrebar/myapp/test$ cd ..
~/erlang_programs/myrebar/myapp$ rebar3 compile
===> Verifying dependencies...
===> Compiling myapp
~/erlang_programs/myrebar/myapp$ rebar3 shell
===> Verifying dependencies...
===> Compiling myapp
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe] [kernel-poll:false]
Eshell V9.3 (abort with ^G)
1> ===> The rebar3 shell is a development tool; to deploy applications in production, consider using releases (http://www.rebar3.org/docs/releases)
===> Booted myapp
1> ct:run("test").
Common Test: Running make in test directories...
Recompile: a_SUITE
a_SUITE.erl:2: Warning: export_all flag enabled - all functions will be exported
CWD set to: "/Users/7stud/erlang_programs/myrebar/myapp/ct_run.nonode#nohost.2021-02-14_14.26.08"
TEST INFO: 1 test(s), 1 case(s) in 1 suite(s)
Testing myrebar.myapp: Starting test, 1 test cases
Testing myrebar.myapp: TEST COMPLETE, 1 ok, 0 failed of 1 test cases
Updating /Users/7stud/erlang_programs/myrebar/myapp/index.html ... done
Updating /Users/7stud/erlang_programs/myrebar/myapp/all_runs.html ... done
{1,0,{0,0}}
2>
Then after exiting the shell:
~/erlang_programs/myrebar/myapp$
~/erlang_programs/myrebar/myapp$ rebar3 ct
===> Verifying dependencies...
===> Compiling myapp
test/a_SUITE.erl:2: Warning: export_all flag enabled - all functions will be exported
===> Running Common Test suites...
%%% a_SUITE: .
All 1 tests passed.
~/erlang_programs/myrebar/myapp$
I didn't touch rebar.config, it is the default produced by rebar3:
{erl_opts, [debug_info]}.
{deps, [{eleveldb, "2.2.20"}]
}.
{shell, [
% {config, "config/sys.config"},
{apps, [myapp]}
]}.
I would try printing your current working directory when you are in the shell:
2> pwd().
/Users/7stud/erlang_programs/myrebar/myapp
ok
Then try using either a full path or a relative path from that directory, e.g.:
"./test/common"
"Users/../../test/common"
Then, I would move all your *_SUITE.erl files except one into a directory outside your app, and just work with one test file. Then, I would get rid of all that config file stuff and try again.
Related
I installed rebar3 and created a new release with
cd ~/apps
rebar3 new release tunnel
Then
I copied my src files from ~/tunnel/src/* to ~/apps/tunnel/src/
I ran into a compile error with rebar3 run and found Erlang "Kernel pid terminated" error as a possible solution. I renamed everything about tunnel_app to tunnel. So my src contains tunnel.erl , tunnel.app.src and tunnel_sup.erl. I renamed the module definition as appropriate.
Here's the rebar3 run error:
~/apps/tunnel:.rebar3 run
===> Verifying dependencies...
===> Compiling tunnel
===> Starting relx build process ...
===> Resolving OTP Applications from directories:
/Users/quantum/apps/tunnel/_build/default/lib
/Users/quantum/apps/tunnel/apps
/usr/local/Cellar/erlang/19.2/lib/erlang/lib
/Users/quantum/apps/tunnel/_build/default/rel
===> Resolved tunnel-0.1.0
===> Dev mode enabled, release will be symlinked
===> release successfully created!
readlink: illegal option -- f
usage: readlink [-n] [file ...]
Exec: /usr/local/Cellar/erlang/19.2/lib/erlang/erts-8.2/bin/erlexec -boot /Users/quantum/apps/tunnel/_build/default/rel/tunnel/releases/0.1.0/tunnel -mode embedded -boot_var ERTS_LIB_DIR /usr/local/Cellar/erlang/19.2/lib/erlang/lib -config /Users/quantum/apps/tunnel/_build/default/rel/tunnel/releases/0.1.0/sys.config -args_file /Users/quantum/apps/tunnel/_build/default/rel/tunnel/releases/0.1.0/vm.args -pa -- console
Root: /Users/quantum/apps/tunnel/_build/default/rel/tunnel
/Users/quantum/apps/tunnel/_build/default/rel/tunnel
Erlang/OTP 19 [erts-8.2] [source] [64-bit] [smp:8:8] [async-threads:30] [hipe] [kernel-poll:true] [dtrace]
=INFO REPORT==== 16-Feb-2017::15:02:21 ===
application: tunnel
exited: {bad_return,
{{tunnel,start,[normal,[]]},
{'EXIT',
{undef,
[{cowboy_router,compile,
[[{'_',
[{"/info",lobby_handler,[]},
{"/join/:name",join_handler,[]},
{"/play/:table_pid/:name/:auth/:team/:action/:x/:y",
play_handler,[]}]}]],
[]},
{tunnel,start,2,
[{file,
"/Users/quantum/apps/tunnel/_build/default/lib/tunnel/src/tunnel.erl"},
{line,8}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,273}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,tunnel,{bad_return,{{tunnel,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{\"/info\",lobby_handler,[]},{\"/join/:name\",join_handler,[]},{\"/play/:table_pid/:name/:auth/:team/:action/:x/:y\",play_handler,[]}]}]],[]},{tunnel,start,2,[{file,\"/Users/quantum/apps/tunnel/_build/default/lib/tunnel/src/tunnel.erl\"},{line,8}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,273}]}]}}}}}"}
Kernel pid terminated (application_controller) ({application_start_failure,tunnel,{bad_return,{{tunnel,start,[normal,[]]},{'EXIT',{undef,[{cowboy_router,compile,[[{'_',[{"/info",lobby_handler,[]},{"/j
Crash dump is being written
Why is this crashing?
If this is your first experience with rebar3, I suggest starting with an OTP application, not an OTP release:
rebar3 new app tunnel
and then do not blindly copy over the source files because you risk overwriting the files that have been created for you below src. Have a look at the contents of that directory beforehand.
I also suggest to take the time to read the rebar3 https://www.rebar3.org/docs/basic-usage page.
You will also have to read about what an OTP application is. I know, quite a lot to understand and sometimes confusing. A free source is http://learnyousomeerlang.com/building-applications-with-otp. It is also worthwhile to buy a book about Erlang. There are a few, I suggest https://www.manning.com/books/erlang-and-otp-in-action.
There is also an online course, free, that starts in a few days (20th Feb 2017) https://www.mooc-list.com/course/functional-programming-erlang-futurelearn
(Newbie here) I am having an error when trying to run ranch example.
Via rebar I created application and node (please see on github).
But when I am trying to build and run it I am getting undef ranch,start_listener.
Please see full console output:
$ rebar get-deps compile generate && sh rel/reverse/bin/reverse console
WARN: Expected reverse/deps/ranch to be an app dir (containing ebin/*.app), but no .app found.
==> rel (get-deps)
==> reverse (get-deps)
WARN: Expected reverse/deps/ranch to be an app dir (containing ebin/*.app), but no .app found.
Pulling ranch from {git,"git#github.com:ninenines/ranch.git",{tag,"1.1.0"}}
Cloning into 'ranch'...
==> ranch (get-deps)
==> ranch (compile)
Compiled src/ranch_transport.erl
Compiled src/ranch_sup.erl
Compiled src/ranch_ssl.erl
Compiled src/ranch_tcp.erl
Compiled src/ranch_protocol.erl
Compiled src/ranch_listener_sup.erl
Compiled src/ranch_app.erl
Compiled src/ranch_acceptors_sup.erl
Compiled src/ranch_acceptor.erl
Compiled src/ranch_server.erl
Compiled src/ranch.erl
Compiled src/ranch_conns_sup.erl
==> rel (compile)
==> reverse (compile)
Compiled src/reverse_sup.erl
Compiled src/reverse_app.erl
Compiled src/reverse_protocol.erl
==> rel (generate)
WARN: 'generate' command does not apply to directory reverse
Exec: reverse/rel/reverse/erts-6.3/bin/erlexec -boot reverse/rel/reverse/releases/1/reverse -mode embedded -config reverse/rel/reverse/releases/1/sys.config -args_file reverse/rel/reverse/releases/1/vm.args -- console
Root: reverse/rel/reverse
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
Eshell V6.3 (abort with ^G)
(reverse#127.0.0.1)1>
=INFO REPORT==== 30-Dec-2014::22:47:08 ===
application: reverse
exited: {bad_return,
{{reverse_app,start,[normal,[]]},
{'EXIT',
{undef,
[{ranch,start_listener,
[reverse,10,ranch_tcp,
[{port,5555}],
reverse_protocol,[]],
[]},
{reverse_app,start,2,
[{file,"src/reverse_app.erl"},{line,13}]},
{application_master,start_it_old,4,
[{file,"application_master.erl"},
{line,272}]}]}}}}
type: permanent
{"Kernel pid terminated",application_controller,"{application_start_failure,reverse,{bad_return,{{reverse_app,start,[normal,[]]},{'EXIT',{undef,[{ranch,start_listener,[reverse,10,ranch_tcp,[{port,5555}],reverse_protocol,[]],[]},{reverse_app,start,2,[{file,\"src/reverse_app.erl\"},{line,13}]},{application_master,start_it_old,4,[{file,\"application_master.erl\"},{line,272}]}]}}}}}"}
Crash dump was written to: erl_crash.dump
I am not sure I correctly added ranch to reltool.config (please see on github). But If I remove deps from libs_dir path I will get rebar generate error Application version clash. Multiple directories contain version ....
UPDATE if I remove failing call and run it, application:which_applications(). gives me {ranch,[],[]} as one of the running ones.
UPDATE versions
$ erl
Erlang/OTP 17 [erts-6.3] [source-f9282c6] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]
$ rebar --version
rebar 2.5.1 17 20141223_141030 git 2.5.1-84-gdd9125e
What I am doing wrong?
Thanks in advance!
In the reltool.config, remove the ebin directory from the path to Ranch:
{app, ranch, [{mod_cond, app}, {incl_cond, include}, {lib_dir, "../deps/ranch/"}]}
If you have lots of dependencies it's more convenient to do:
{lib_dirs, ["../deps"]}
instead of having a separate {app, <dep_name>, [...]} for each dependency.
The Application version clash. Multiple directories contain version XXX error indicates that the Ranch application is already installed, probably in the Erlang lib directory, creating conflicts with the deps version downloaded by Rebar.
I am new to Erlang world and currently can't figure out how to start my dummy erlang application. Probably, I am just missing something... So, I created an application with rebar (rebar create-app appid=dummys).
Currently I have
rebar.config
src/dummys.app.src
src/dummys_app.erl
src/dummys_sup.erl
I have found that in order to run an application during a development it is better to create an additional start method which should call application:start(module).
I added some basic logging to my start methods..
start() ->
error_logger:info_msg("Starting app(dev)..~n"),
application:start(dummys_app).
start(_StartType, _StartArgs) ->
error_logger:info_msg("Starting app..~n"),
dummys_sup:start_link().
If I try
erl -noshell -pa ebin -s application start dummys
erl -noshell -pa ebin -s application start dummys_app
there are no output..
If I try
erl -noshell -pa ebin -s dummys start
erl crashes with an error..
If I try
erl -noshell -pa ebin -s dummys_app start
it outputs just "Starting app(dev).." and that's all. But I also expect to see "Starting app.."
What I am missing or doing wrong??
=============
And another question: How to add a new module to my dummy application correctly? For example I have an additional module called "*dummys_cool*" which has a "start" method. How to tell my application to run that "dummys_cool#start" method?
Thank you!
For quick development, if you just want to ensure your appliction can start, start a shell, then start the application:
erl -pa ebin
1> dummys_app:start().
That will give you a clean indication of what is wrong and right without the shell bombing out after.
Since you're making an application to run, rather than just a library to share, you'll want to make a release. Rebar can get you most of the way there:
mkdir rel
cd rel
rebar create-node nodeid=dummysnode
After you've compiled your application, you can create a release:
rebar generate
This will build a portable release which includes all the required libraries and even the erlang runtime system. This is put by default in the rel/ directory; in your case rel/dummys.
Within that directory there will be a control script that you can use to start, stop, and attach to the application:
rel/dummys/bin/dummys start
rel/dummys/bin/dummys stop
rel/dummys/bin/dummys start
rel/dummys/bin/dummys attach
Have a look at your dummys.app.src file. The meaning of all the directives is explained in the 'app' manpage, but the one I suspect is missing here is mod, which indicates the name of your application callback module. So make sure that this line is present:
{mod, {dummys_app, []}}
The empty list in there will be passed as the StartArgs argument to dummys_app:start/2.
To make a new module start along with your application, add it to the supervision tree in dummys_sup:init. This function should look something like:
init(_) ->
{ok, {{one_for_one, 10, 10},
[{dummys_cool, {dummys_cool, start_link, []},
permanent, brutal_kill, worker, [dummys_cool]}]}.
This is described in the 'supervisor' manpage, but basically this means that on startup, this supervisor will start one child process. dummys_cool:start_link() will be called, and that function is expected to spawn a new process, link to it, and return its process id. If you need more processes, just add more child specifications to the list.
erl -noshell -pa ebin -s application start dummys
The code above will not work because application:start([dummys]) will be called.
You can take a reference of the Erlang documentation for details.
For your case,
erl -noshell -pa ebin -s dummys
I ran into this problem, and this was the first answer on Google.
If you are using rebar3, the standard configuration will have a shell command that compiles your project and opens a shell:
$ rebar3 shell
===> Analyzing applications...
===> Compiling myapp
Erlang/OTP 21 [erts-10.2.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]
Eshell V10.2.4 (abort with ^G)
1> ===> Booted myapp
I'm write a test with EUnit, but not anything exception detail output in console.
exp_test() ->
?assertEqual(0, 1/0).
Run this module:exp_test() in the Erlang Shell output following
** exception error: bad argument in an arithmetic expression
in function exp_test:'-exp_test/0-fun-0-'/1 (src/test/eunit/xxx_test.erl, line 8)
But in EUnit output following
> eunit:test(xxx).
> xxx_test: exp_test...*failed*
::badarith
EUnit not output anything exception trace info
Im trying the verbose config in eunit, but no effect.
I want to output some exception detail in eunit test result.
Thanks~
The problem seems to be that the version of eunit shipped with R15 does not understand the new stack trace format in R15. This has been fixed in the development version of eunit: github.com/richcarl/eunit
For example:
Eshell V5.10 (abort with ^G)
1> eunit:test(fun() -> (fun() -> exit(foo), ok end)() end).
erl_eval: expr...*failed*
in function erl_eval:do_apply/6 (erl_eval.erl, line 576)
in call from erl_eval:exprs/5 (erl_eval.erl, line 118)
**exit:foo
I hope this will make it into the next release of OTP R15.
This is a known problem in eunit as released in R15B and R15B01. This has been fixed in release R15B02. If you're stuck with an earlier version, you can download and apply a patch:
A workaround for releases before R15B02
You can fix the problem in your local installation by recompiling the affected module:
Download and unpack the Erlang/OTP sources, if you don't have them already.
wget http://www.erlang.org/download/otp_src_R15B01.tar.gz
tar xzf otp_src_R15B01.tar.gz
cd otp_src_R15B01
Download and apply the patch.
wget -O eunit-stacktrace.patch https://github.com/erlang/otp/commit/73b94a990bb91fd263dace4ccbaef6ff727a9637.patch
patch -p1 < eunit-stacktrace.patch
Recompile eunit_lib.erl.
cd lib/eunit
erlc -o ebin -I include src/eunit_lib.erl
Copy the new eunit_lib.beam over the old one (usually somewhere below /usr/local).
ls /usr/local/lib/erlang/lib/eunit-2.2.2/ebin/
# check that eunit_lib.beam is actually there
sudo cp ebin/eunit_lib.beam /usr/local/lib/erlang/lib/eunit-2.2.2/ebin/
Eunit is quite old and while it is officially maintained by the OTP team at Ericsson, it is usually uncared for. Eunit currently has the bad habit of eating up stack traces, and hasn't been updated for R15's line numbers in exceptions.
I wouldn't argue that "that's how it's supposed to work". No sane test tool should hide exception details and line numbers for you.
A trick I like to use is ?debugVal(catch expr) where expr is either a begin end block
or a call to the failing function. For example, ?debugVal(catch begin 1 = 2 end) will output a stacktrace in your tests.
Erlang was already installed:
$dpkg -l|grep erlang
ii erlang 1:13.b.3-dfsg-2ubuntu2 Concurrent, real-time, distributed function
ii erlang-appmon 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP application monitor
ii erlang-asn1 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP modules for ASN.1 support
ii erlang-base 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP virtual machine and base applica
ii erlang-common-test 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP application for automated testin
ii erlang-debugger 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP application for debugging and te
ii erlang-dev 1:13.b.3-dfsg-2ubuntu2 Erlang/OTP development libraries and header
[... many more]
Erlang seems to work:
$ erl
Erlang R13B03 (erts-5.7.4) [source] [64-bit] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]
Eshell V5.7.4 (abort with ^G)
1>
I downloaded lfe from github and checked out 0.5.2:
git clone http://github.com/rvirding/lfe.git
cd lfe
git checkout -b local0.5.2 e207eb2cad
$ configure
configure: command not found
$ make
mkdir -p ebin
erlc -I include -o ebin -W0 -Ddebug +debug_info src/*.erl
#erl -I -pa ebin -noshell -eval -noshell -run edoc file src/leex.erl -run init stop
#erl -I -pa ebin -noshell -eval -noshell -run edoc_run application "'Leex'" '"."' '[no_packages]'
#mv src/*.html doc/
Must be something stupid i missed :o
$ sudo make install
make: *** No rule to make target `install'. Stop.
$ erl -noshell -noinput -s lfe_boot start
{"init terminating in do_boot",{undef,[{lfe_boot,start,[]},{init,start_it,1},{init,start_em,1}]}}
Crash dump was written to: erl_crash.dump
init terminating in do_boot ()
Is there an example how I would create a hello world source file and compile and run it?
No, there is nothing you missed. The Makefile in LFE is "less than perfect" and should be ignored, it will be improved upon in the next release. To compensate all the needed files have already compiled and the .beam files are in the ebin directory. As it is not part of OTP I don't think it should ever install there.
The easiest way to handle this to create a private erlang library directory and point the environment variable ERL_LIBS to it. Then just drop the whole LFE directory there. When erlang starts the code server will automatically add the lfe/ebin directories into the path and the .beam files there will automagically be found and loaded. This will work with any package that contains an ebin directory. This also works on Windows. So:
Make an libs directory, say ~/erlang/lib
Set the environment variable ERL_LIBS, export ERL_LIBS=~/erlang/lib
Put the whole LFE directory there
When you start erlang you will then see /Users/rv/erlang/lib/lfe/ebin (or wherever you have it) in the code path (code:get_path()). You will then also be able to start the LFE shell directly with
erl -noshell -noinput -s lfe_boot start
There will be an lfe and an lfe.bat which does this included as well in the future.
As with erlang any text editor will work to edit LFE. For emacs there is an LFE mode which is still rather basic but works. You cannot yet run LFE in a window. Soon. The best way to include this is to put the following in your .emacs file:
;; LFE mode.
(setq load-path (cons "/Users/rv/erlang/lib/lfe/emacs" load-path))
(require 'lfe-start)
There are some example files in lfe/examples, all should work. In lfe/test/visual there is a bunch of my test files which have been included as example files. To compile an LFE file from the normal erlang shell do
lfe_comp:file("foo").
l(foo). %No autloload here, do this to ensure loading
while from the LFE shell do:
(c '"foo") ;This will autoload
There is a bunch of documentation in lfe/docs which is quite accurate but the user_guide.txt needs to be extended. There is also a Google group for LFE at
http://groups.google.se/group/lisp-flavoured-erlang
which contains some interesting discussions and people have written quite a lot in the github LFE wiki.
That's about it I think. contact me if/when you have more questions.