One of the usage guides for Erlang Rebar: introductory article

Source: Internet
Author: User

One of the usage guides for Erlang Rebar: introductory article


Full-Text Catalogs:

Https://github.com/rebar/rebar/wiki

The text of this chapter:

https://github.com/rebar/rebar/wiki/Getting-started

Rebar is a feature-rich Erlang build tool. For ERLANG/OTP Project compilation, testing, dependency management, package release, etc.

Rebar is a self-contained script that you can easily embed into your project. 1 Compiling rebar
    $ git clone git://github.com/rebar/rebar.git    $ CD Rebar    $./bootstrap
To view the command description:
    $./rebar-c    $./rebar Help Clean

2 Getting Started example 2.1 Creating a program Directory
    $ mkdir MyApp    $ cd MyApp

Copy the "1 compiled rebar" rebar to the MyApp directory
    $ CP.. /rebar/rebar.

2.2 Creating the first rebar project
    $./rebar Create-app Appid=myapp    $ touch rebar.config

After the above command was executed, 3 files were generated in MYAPP/SRC:
MYAPP.APP.SRC-OTP Application Resources
Myapp_app.erl-An implementation of OTP application behaviour
Myapp_sup.erl-the most top-level OTP Supervisor behaviour

2.3 Compiling the project
    $./rebar Compile

After the above command executes, the Ebin directory is generated, containing the. beam file that corresponds to the Src/erl file.
SRC/MYAPP.APP.SRC Generating Ebin/myapp.app

Cleanup Project
    $./rebar Clean

2.4 Test Project Rebar supports Eunit and common test framework. Add the Euint unit test to the project and add the following code to
Src/myapp_app.erl:

-export ([START/2, STOP/1]). Add later:

    Percent Eunit testing    -ifdef (TEST).    -include_lib ("Eunit/include/eunit.hrl").    -endif.

Add at the end of the file:
    Percent Eunit testing    -ifdef (TEST).    Simple_test ()        , OK = Application:start (MyApp),        ? assertnot (undefined = = Whereis (myapp_sup)).    -endif.

The IFDEF macro indicates the test phase code and is not compiled into the product.
To start compiling and testing:
    $./rebar Compile Eunit

The above command will be compiled 2 times, one output to ebin/, one output to. eunit/:
==> MyApp (Compile)
Compiled Src/myapp_app.erl
Compiled Src/myapp_sup.erl
==> MyApp (Eunit)
Compiled Src/myapp_sup.erl
Compiled Src/myapp_app.erl
Test passed.

=info report==== 30-nov-2014::03:50:01 = = =
Application:myapp
Exited:killed
Type:temporary

2.5 Test Code Coverage statistics add the following line to the Myapp/rebar.config:
    {cover_enabled, true}.

Run again:
    $ rebar Compile Eunit

The generated statistics page is in:. eunit/index.html

One of the usage guides for Erlang Rebar: introductory article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.