Erlang 学习 :makefile rebar使用

在Ubuntu 11.10上,通过下载rebar创建Erlang项目dptest,接着编写包含测试的Makefile,并编辑src/dptest_app.erl添加测试代码。执行`make`进行编译,`make test`运行测试,结果显示所有测试已通过。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  选定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.




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值