选定mochiweb作为erlang的入门学习项目,细节研究了一下mochiweb。是用rebar进行项目管理。所以今天学习erlang的项目构建,makefile + rebar
保存好,测试下。
(在ubuntu 11.10上)
首先下载rebar:在 https://github.com/basho/rebar
创建项目:
$mkdir dptest
$cd dptest
$wget http://cloud.github.com/downloads/basho/rebar/rebar && chmod u+x rebar
$./rebar create-app appid=dptest
然后就可以看到生成的代码,开始写Makefile
简单写个带测试的Makefile
PROFIX=./
REBAR=./rebar
all:
@$(REBAR) compile
test:
@rm -rf .eunit
@$(REBAR) compile eunit
开始编辑生成的代码,src/dptest_app.erl, 主要加入测试代码
-module(test_app).
-behaviour(application).
%% Application callbacks
-export([start/2, stop/1]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
%% ===================================================================
%% Application callbacks
%% ===================================================================
start(_StartType, _StartArgs) ->
test_sup:start_link().
stop(_State) ->
ok.
-ifdef(TEST).
simple_test() ->
ok = application:start(dptest),
?assertNot(undefined == whereis(dptest_sup)).
-endif.
保存好,测试下。
dp@dp0304:/bu/workspace/erlang/test$ make
==> test (compile)
dp@dp0304:/bu/workspace/erlang/test$ make test
==> test (compile)
==> test (eunit)
Compiled src/test_sup.erl
Compiled src/test_app.erl
Test passed.