Erlang 构建工具 rebar
更新历史:
- 2014-09-25 22:40:22
https://bitbucket.org/basho/rebar/wiki/GettingStarted这篇文章是直接下载二进制的rabar,建议从源代码进行编译,可以了解rebar的更多信息.还有现成的rebar.config配置文件,下载编译过程很简单,请看图一
1 | debian:~/erlang# hg clone https://bitbucket.org/basho/rebar debian:~/erlang# cd rebar debian:~/erlang# ./bootstrap |
在src/myapp_app.erl文件的-export()指令后面添加如下行:
1 | -ifdef(TEST). -include_lib("eunit/include/eunit.hrl"). -endif. |
在文件的末尾添加如下行:
1 | -ifdef(TEST). simple_test() -> ok = application:start(myapp), ?assertNot(undefined == whereis(myapp_sup)). -endif. |
1 | debian:~/erlang/rebar/myapp# ./rebat compile eunit |
输出
1 | debian:~/erlang/rebar/myapp# ./rebar compile eunit ==> myapp (compile) ==> myapp (eunit) Test passed. Cover analysis: /var/root/erlang/rebar/myapp/.eunit/index.html |
.eunit
目录中包含了一些调试信息.
在rebar.config中添加如下行,让rebar为我们生成代码覆盖率信息.
1 | {cover_enabled, true}. |
执行:
1 | debian:~/erlang/rebar/myapp# ./rebar clean debian:~/erlang/rebar/myapp# ./rebar compile eunit ==> myapp (compile) ==> myapp (eunit) Test passed. Cover analysis: /var/root/erlang/rebar/myapp/.eunit/index.html |
覆盖率报告html文件生成了.
命令
Rebar提供了开发过程中大多数功能, 包括:
In addition, it allows for OTP embedded system generation, taking advantage of the template processing afforded by rebar and the reltool application.
The most common commands are:
COMMAND | DESCRIPTION |
---|---|
compile | Compile all the available source in the project. |
eunit | Perform unit testing using the Eunit application |
doc | Generate documention using the Edoc application |
clean | Remove any generated artifacts from compilation, unit testing, etc. |
参考: