Permalink
Browse files

Migrating tests to eunit (#134)

  • Loading branch information...
1 parent 3f40f41 commit 1a250bf55770e1009af3b3f878862cf866677833 @kaos kaos committed Feb 28, 2014
View
@@ -9,3 +9,4 @@ tests/src/erlydtl_extension_testparser.erl
tests/output
deps
.emacs*
+.eunit
View
@@ -33,6 +33,7 @@ test: compile compile_test
sources_parser_unittests:run_tests(), \
halt(0) \
catch throw:failed -> halt(1) end"
+ @$(REBAR) eunit
check: test dialyze
View
@@ -8,4 +8,9 @@
[raw]}
]}.
-{pre_hooks, [{compile, "make -C $REBAR_DEPS_DIR/merl all"}]}.
+{pre_hooks,
+ [{compile, "make -C $REBAR_DEPS_DIR/merl all"},
+ {eunit,
+ "erlc -I include/erlydtl_preparser.hrl -o test"
+ " test/erlydtl_extension_testparser.yrl"}
+ ]}.
View
@@ -0,0 +1 @@
+erlydtl_extension_testparser.erl
@@ -0,0 +1,70 @@
+%%%-------------------------------------------------------------------
+%%% File: erlydtl_eunit_testrunner.erl
+%%% @author Andreas Stenius <kaos@astekk.se>
+%%% @copyright 2014 Andreas Stenius
+%%% @doc
+%%% Test suite runner for erlydtl
+%%% @end
+%%%
+%%% The MIT License
+%%%
+%%% Copyright (c) 2014 Andreas Stenius
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in
+%%% all copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+%%% THE SOFTWARE.
+%%%
+%%% @since 2014 by Andreas Stenius
+%%%-------------------------------------------------------------------
+-module(erlydtl_eunit_testrunner).
+-author('Andreas Stenius <kaos@astekk.se>').
+
+-export([run_test/1, run_compile/1, run_render/1]).
+
+-include_lib("eunit/include/eunit.hrl").
+
+-define(noimport,).
+-include("testrunner.hrl").
+
+
+run_test(T) ->
+ case run_compile(T) of
+ ok -> run_render(T);
+ error_ok -> ok
+ end.
+
+run_compile(T) ->
+ case erlydtl:compile(
+ T#test.source, T#test.module,
+ [{vars, T#test.compile_vars}|T#test.compile_opts]) of
+ {ok, M, W} ->
+ ?assertEqual(T#test.module, M),
+ ?assertEqual(T#test.warnings, W);
+ {error, E, W} ->
+ ?assertEqual(T#test.errors, E),
+ ?assertEqual(T#test.warnings, W),
+ error_ok
+ end.
+
+run_render(T) ->
+ case (T#test.module):render(T#test.render_vars, T#test.render_opts) of
+ {ok, O} ->
+ ?assertEqual(T#test.output, iolist_to_binary(O));
+ RenderOutput ->
+ ?assertEqual(T#test.output, RenderOutput),
+ error_ok
+ end.
@@ -0,0 +1,153 @@
+%%% -*- mode: erlang -*- ------------------------------------------------------------------
+%%% File: erlydtl_parser.erl
+%%% @author Andreas Stenius <kaos@astekk.se>
+%%% @copyright 2013 Andreas Stenius
+%%% @doc Sample extension grammar
+%%% @reference See <a href="http://erlydtl.googlecode.com" target="_top">http://erlydtl.googlecode.com</a> for more information
+%%% @end
+%%%
+%%% The MIT License
+%%%
+%%% Copyright (c) 2013 Andreas Stenius
+%%%
+%%% Permission is hereby granted, free of charge, to any person obtaining a copy
+%%% of this software and associated documentation files (the "Software"), to deal
+%%% in the Software without restriction, including without limitation the rights
+%%% to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+%%% copies of the Software, and to permit persons to whom the Software is
+%%% furnished to do so, subject to the following conditions:
+%%%
+%%% The above copyright notice and this permission notice shall be included in
+%%% all copies or substantial portions of the Software.
+%%%
+%%% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+%%% IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+%%% FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+%%% AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+%%% LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+%%% OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+%%% THE SOFTWARE.
+%%%
+%%% @since 2013-06-20 by Andreas Stenius
+%%%-------------------------------------------------------------------
+
+Nonterminals
+ Extensions
+ Literal
+
+ ValueExpressionBraced
+
+ ValueExpression
+ Value
+ Variable
+.
+
+Terminals
+ %% "new" terminals that are partially parsed tokens from the erlydtl parser:
+ variable
+
+ %% standard scanner tokens:
+
+ %% and_keyword
+ %% as_keyword
+ %% autoescape_keyword
+ %% block_keyword
+ %% blocktrans_keyword
+ %% by_keyword
+ %% call_keyword
+ %% close_tag
+ close_var
+ %% comment_keyword
+ %% cycle_keyword
+ %% elif_keyword
+ %% else_keyword
+ %% empty_keyword
+ %% endautoescape_keyword
+ %% endblock_keyword
+ %% endblocktrans_keyword
+ %% endcomment_keyword
+ %% endfilter_keyword
+ %% endfor_keyword
+ %% endif_keyword
+ %% endifchanged_keyword
+ %% endifequal_keyword
+ %% endifnotequal_keyword
+ %% endregroup_keyword
+ %% endspaceless_keyword
+ %% endwith_keyword
+ %% extends_keyword
+ %% filter_keyword
+ %% firstof_keyword
+ %% for_keyword
+ identifier
+ %% if_keyword
+ %% ifchanged_keyword
+ %% ifequal_keyword
+ %% ifnotequal_keyword
+ %% in_keyword
+ %% include_keyword
+ %% noop_keyword
+ %% not_keyword
+ %% now_keyword
+ number_literal
+ %% only_keyword
+ or_keyword
+ %% open_tag
+ open_var
+ %% parsed_keyword
+ %% regroup_keyword
+ %% reversed_keyword
+ %% spaceless_keyword
+ %% ssi_keyword
+ string_literal
+ %% string
+ %% templatetag_keyword
+ %% openblock_keyword
+ %% closeblock_keyword
+ %% openvariable_keyword
+ %% closevariable_keyword
+ %% openbrace_keyword
+ %% closebrace_keyword
+ %% opencomment_keyword
+ %% closecomment_keyword
+ %% trans_keyword
+ %% widthratio_keyword
+ %% with_keyword
+ %% ',' '|' '=' ':'
+ '.'
+ %% '==' '!='
+ %% '>=' '<='
+ %% '>' '<'
+ %% '(' ')'
+ %% '_'
+.
+
+Rootsymbol
+ Extensions.
+
+%% Operator precedences for the E non terminal
+Left 100 or_keyword.
+%Left 110 and_keyword.
+%Nonassoc 300 '==' '!=' '>=' '<=' '>' '<'.
+%Unary 600 Unot.
+
+Extensions -> ValueExpressionBraced : ['$1'].
+
+ValueExpressionBraced -> open_var ValueExpression close_var : '$2'.
+
+ValueExpression -> Value or_keyword Value : {extension, {value_or, {'$1', '$3'}}}.
+
+%Value -> Value '|' Filter : {apply_filter, '$1', '$3'}.
+%Value -> '_' '(' Value ')' : {trans, '$3'}.
+Value -> Variable : '$1'.
+Value -> Literal : '$1'.
+
+Variable -> identifier : {variable, '$1'}.
+Variable -> variable : '$1'.
+Variable -> Variable '.' identifier : {attribute, {'$3', '$1'}}.
+
+Literal -> string_literal : '$1'.
+Literal -> number_literal : '$1'.
+
+
+%% vim: syntax=erlang
View
@@ -0,0 +1,14 @@
+-module(erlydtl_lib_test1).
+-behaviour(erlydtl_library).
+
+-export([version/0, inventory/1, reverse/1]).
+
+version() -> 1.
+
+inventory(filters) -> [reverse];
+inventory(tags) -> [].
+
+reverse(String) when is_list(String) ->
+ lists:reverse(String);
+reverse(String) when is_binary(String) ->
+ reverse(binary_to_list(String)).
@@ -0,0 +1,9 @@
+-module(erlydtl_lib_testversion).
+-behaviour(erlydtl_library).
+
+-export([version/0, inventory/1]).
+
+version() -> invalid.
+
+inventory(filters) -> [];
+inventory(tags) -> [].
Oops, something went wrong.

0 comments on commit 1a250bf

Please sign in to comment.