Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/external_decorator' into develop
- Loading branch information
Showing
3 changed files
with
104 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
%% -*- erlang -*- | ||
{erl_opts, [debug_info, warnings_as_errors]}. | ||
{erl_opts, [debug_info]}. | ||
{cover_enabled, true}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |