Browse Source

Test error case for missing template from extends tag.

Fixes #60.
Andreas Stenius 11 years ago
parent
commit
3a8c835fbf
3 changed files with 14 additions and 7 deletions
  1. 2 2
      tests/input/custom_call
  2. 3 0
      tests/input/extends3
  3. 9 5
      tests/src/erlydtl_functional_tests.erl

+ 2 - 2
tests/input/custom_call

@@ -1,7 +1,7 @@
 >>>> before custom call tag 'comment'
 >>>> before custom call tag 'comment'
-{% call example_for_preset %}
+{% call functional_test_for_preset %}
 >>>> after custom call tag 'comment'
 >>>> after custom call tag 'comment'
 
 
 >>>> before custom call tag 'if'
 >>>> before custom call tag 'if'
-{% call example_if with var1 %}
+{% call functional_test_if with var1 %}
 >>>> after custom call tag 'if'
 >>>> after custom call tag 'if'

+ 3 - 0
tests/input/extends3

@@ -0,0 +1,3 @@
+{% extends "imaginary" %}
+{% block title %}replacing the base title{% endblock %}
+{% block content %}replacing the base content - variable: {{ test_var }} after variable {% endblock %}

+ 9 - 5
tests/src/erlydtl_functional_tests.erl

@@ -48,7 +48,7 @@ test_list() ->
         "custom_tag", "custom_tag1", "custom_tag2", "custom_tag3",
         "custom_tag", "custom_tag1", "custom_tag2", "custom_tag3",
         "custom_call", 
         "custom_call", 
         "include_template", "include_path", "ssi",
         "include_template", "include_path", "ssi",
-        "extends_path", "extends_path2", "trans", "extends2" ].
+        "extends_path", "extends_path2", "trans", "extends2", "extends3" ].
 
 
 setup_compile("for_list_preset") ->
 setup_compile("for_list_preset") ->
     CompileVars = [{fruit_list, [["apple", "apples"], ["banana", "bananas"], ["coconut", "coconuts"]]}],
     CompileVars = [{fruit_list, [["apple", "apples"], ["banana", "bananas"], ["coconut", "coconuts"]]}],
@@ -75,7 +75,11 @@ setup_compile("var_preset") ->
     CompileVars = [{preset_var1, "preset-var1"}, {preset_var2, "preset-var2"}],
     CompileVars = [{preset_var1, "preset-var1"}, {preset_var2, "preset-var2"}],
     {ok, CompileVars};
     {ok, CompileVars};
 setup_compile("extends2") ->
 setup_compile("extends2") ->
-    {error, []};
+    {{error, "The extends tag must be at the very top of the template"}, []};
+setup_compile("extends3") ->
+    File = templates_dir("input/imaginary"),
+    Error = {0, functional_test_extends3, "Failed to read file"},
+    {{error, {File, [Error]}}, []}; %% Huh?! what kind of error message is that!?
 setup_compile(_) ->
 setup_compile(_) ->
     {ok, []}.
     {ok, []}.
 
 
@@ -235,7 +239,7 @@ fold_tests() ->
 
 
 test_compile_render(Name) ->  
 test_compile_render(Name) ->  
     File = filename:join([templates_docroot(), Name]),
     File = filename:join([templates_docroot(), Name]),
-    Module = "example_" ++ Name,
+    Module = "functional_test_" ++ Name,
     io:format(" Template: ~p, ... ", [Name]),
     io:format(" Template: ~p, ... ", [Name]),
     case setup_compile(Name) of
     case setup_compile(Name) of
         {CompileStatus, CompileVars} ->
         {CompileStatus, CompileVars} ->
@@ -251,8 +255,8 @@ test_compile_render(Name) ->
                             io:format("missing error"),
                             io:format("missing error"),
                             {error, "compiling should have failed :" ++ File}
                             {error, "compiling should have failed :" ++ File}
                     end;
                     end;
-                {error, Err} ->
-                    if CompileStatus =:= error -> io:format("ok");
+                {error, _}=Err ->
+                    if CompileStatus =:= Err -> io:format("ok");
                        true -> 
                        true -> 
                             io:format("failed"),
                             io:format("failed"),
                             {compile_error, io_lib:format("~p", [Err])}
                             {compile_error, io_lib:format("~p", [Err])}