Skip to content

Commit

Permalink
Merge branch 'feature/external_decorator' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
egobrain committed Mar 13, 2014
2 parents 4543001 + 87708ed commit 9e2c192
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 40 deletions.
44 changes: 5 additions & 39 deletions Makefile
@@ -1,57 +1,23 @@

PREFIX:=../
DEST:=$(PREFIX)$(PROJECT)

SRC_TMP=.tmp

REBAR= `which rebar || ./rebar`

all:
build:
@$(REBAR) compile skip_deps=true

deps: _deps
_deps:
deps:
@$(REBAR) get-deps
@$(REBAR) compile

docs:
@$(REBAR) doc skip_deps=true

eunit:
@rm -rf .eunit
@mkdir -p .eunit
@$(REBAR) skip_deps=true eunit

xref: _xref
_xref:
@$(REBAR) xref skip_deps=true

test: ct
ct:
- @mv src $(SRC_TMP)
- @mkdir src
- @find $(SRC_TMP) -name "*erl" -exec ln -s "../{}" src/ \;
- @$(REBAR) skip_deps=true ct
- @rm -Rf src
- @mv $(SRC_TMP) src

test: eunit

clean:
@$(REBAR) clean skip_deps=true

clean_all:
@$(REBAR) clean

build_plt:
@$(REBAR) build_plt

dialyzer:
@$(REBAR) analyze

app:
@$(REBAR) create template=mochiwebapp dest=$(DEST) appid=$(PROJECT)

devrel: dip1 dip2

dip1 dip2 dip3:
mkdir -p dev
(cd rel && rebar generate target_dir=../dev/$@ overlay_vars=vars/$@_vars.config force=1)
PHONY: build deps eunit clean clean_all test
2 changes: 1 addition & 1 deletion rebar.config
@@ -1,3 +1,3 @@
%% -*- erlang -*-
{erl_opts, [debug_info, warnings_as_errors]}.
{erl_opts, [debug_info]}.
{cover_enabled, true}.
98 changes: 98 additions & 0 deletions test/src/dec_test.erl
@@ -0,0 +1,98 @@
-module(dec_test).

-compile([{parse_transform, decorators}]).

-export([
wrap/2,
tag/3,
info/3,
info_tag/4
]).

-export([
w1/0, w2/0,
t1/0, t2/0,
i1/0, i2/0,
it1/0, it2/0
]).

%% =============================================================================
%%% Decorators
%% =============================================================================

wrap(F, Args) ->
{wrap, F(Args)}.

tag(F, Args, Tag) ->
{Tag, F(Args)}.

info(F, Args, {FunName, _Line}) ->
{FunName, F(Args)}.

info_tag(F, Args, {FunName, _Line}, Tag) ->
{{Tag, FunName}, F(Args)}.

%% =============================================================================
%%% Functions
%% =============================================================================

-decorate({?MODULE, wrap}).
w1() -> 1.

-decorate({?MODULE, wrap}).
-decorate({?MODULE, wrap}).
w2() -> 2.

-decorate({?MODULE, tag, [tag1]}).
t1() -> 1.

-decorate({?MODULE, tag, [tag1]}).
-decorate({?MODULE, tag, [tag2]}).
t2() -> 2.

-decorate({?MODULE, info, [], verbose}).
i1() -> 1.

-decorate({?MODULE, info, [], verbose}).
-decorate({?MODULE, info, [], verbose}).
i2() -> 2.

-decorate({?MODULE, info_tag, [tag1], verbose}).
it1() -> 1.

-decorate({?MODULE, info_tag, [tag1], verbose}).
-decorate({?MODULE, info_tag, [tag2], verbose}).
it2() -> 2.

%% =============================================================================
%%% Tests
%% =============================================================================

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

w1_test() ->
?assertEqual(w1(), {wrap, 1}).

w2_test() ->
?assertEqual(w2(), {wrap, {wrap, 2}}).

t1_test() ->
?assertEqual(t1(), {tag1, 1}).

t2_test() ->
?assertEqual(t2(), {tag1, {tag2, 2}}).

i1_test() ->
?assertEqual(i1(), {i1, 1}).

i2_test() ->
?assertEqual(i2(), {i2, {i2, 2}}).

it1_test() ->
?assertEqual(it1(), {{tag1, it1}, 1}).

it2_test() ->
?assertEqual(it2(), {{tag1, it2}, {{tag2, it2}, 2}}).

-endif.

0 comments on commit 9e2c192

Please sign in to comment.