| 1 |
#!/usr/bin/env bash |
| 2 |
# THIS FILE IS PART OF THE CYLC WORKFLOW ENGINE. |
| 3 |
# Copyright (C) NIWA & British Crown (Met Office) & Contributors. |
| 4 |
# |
| 5 |
# This program is free software: you can redistribute it and/or modify |
| 6 |
# it under the terms of the GNU General Public License as published by |
| 7 |
# the Free Software Foundation, either version 3 of the License, or |
| 8 |
# (at your option) any later version. |
| 9 |
# |
| 10 |
# This program is distributed in the hope that it will be useful, |
| 11 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
# GNU General Public License for more details. |
| 14 |
# |
| 15 |
# You should have received a copy of the GNU General Public License |
| 16 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
#------------------------------------------------------------------------------ |
| 18 |
# Test Jinja2 errors |
| 19 |
# Ensure parsec can pull out the context lines even when they are behind |
| 20 |
# an include statement |
| 21 |
|
| 22 |
. "$(dirname "$0")/test_header" |
| 23 |
set_test_number 10 |
| 24 |
|
| 25 |
sub_tabs() { |
| 26 |
sed -i 's/\t/ /g' "${TEST_NAME}.stderr" |
| 27 |
} |
| 28 |
|
| 29 |
purge_workflow() { |
| 30 |
if ((FAILURES != 0)); then |
| 31 |
exit |
| 32 |
fi |
| 33 |
purge |
| 34 |
} |
| 35 |
|
| 36 |
#------------------------------------------------------------------------------ |
| 37 |
# Test syntax error in flow.cylc |
| 38 |
install_workflow "${TEST_NAME_BASE}" badsyntax |
| 39 |
|
| 40 |
TEST_NAME="${TEST_NAME_BASE}-badsyntax" |
| 41 |
run_fail "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" |
| 42 |
|
| 43 |
sub_tabs |
| 44 |
cmp_ok "${TEST_NAME}.stderr" <<__HERE__ |
| 45 |
Jinja2Error: Expected an expression, got 'end of statement block' |
| 46 |
File ${WORKFLOW_RUN_DIR}/flow.cylc |
| 47 |
#!Jinja2 |
| 48 |
# line before |
| 49 |
{% set x = %} <-- TemplateSyntaxError |
| 50 |
__HERE__ |
| 51 |
|
| 52 |
purge_workflow |
| 53 |
|
| 54 |
#------------------------------------------------------------------------------ |
| 55 |
# Test syntax error in an include file |
| 56 |
install_workflow "${TEST_NAME_BASE}" include-badsyntax |
| 57 |
|
| 58 |
TEST_NAME="${TEST_NAME_BASE}-include-badsyntax" |
| 59 |
run_fail "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" |
| 60 |
|
| 61 |
sub_tabs |
| 62 |
cmp_ok "${TEST_NAME}.stderr" <<__HERE__ |
| 63 |
Jinja2Error: unexpected char '"' at 142 |
| 64 |
Error in file "runtime-bad.cylc" |
| 65 |
File ${WORKFLOW_RUN_DIR}/runtime-bad.cylc |
| 66 |
[[FAM]] |
| 67 |
[[[environment]]] |
| 68 |
TITLE="member" |
| 69 |
{%- for num in ["0","1","2","3",4"] %} <-- TemplateSyntaxError |
| 70 |
File ${WORKFLOW_RUN_DIR}/flow.cylc |
| 71 |
[[graph]] |
| 72 |
R1 = "a => FAM" |
| 73 |
[runtime] |
| 74 |
{% include 'runtime-bad.cylc' %} <-- TemplateSyntaxError |
| 75 |
__HERE__ |
| 76 |
|
| 77 |
purge_workflow |
| 78 |
|
| 79 |
#------------------------------------------------------------------------------ |
| 80 |
# Test syntax error in an include file (included using the Cylc built-in |
| 81 |
# %include keyword) |
| 82 |
install_workflow "${TEST_NAME_BASE}" cylc-include-badsyntax |
| 83 |
|
| 84 |
TEST_NAME="${TEST_NAME_BASE}-cylc-include-badsyntax" |
| 85 |
run_fail "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" |
| 86 |
|
| 87 |
sub_tabs |
| 88 |
cmp_ok "${TEST_NAME}.stderr" <<__HERE__ |
| 89 |
Jinja2Error: Encountered unknown tag 'end'. |
| 90 |
Jinja was looking for the following tags: 'elif' or 'else' or 'endif'. |
| 91 |
The innermost block that needs to be closed is 'if'. |
| 92 |
File ${WORKFLOW_RUN_DIR}/flow.cylc |
| 93 |
# This is a bit of graph configuration. |
| 94 |
{% if true %} |
| 95 |
R1 = foo |
| 96 |
{% end if % <-- TemplateSyntaxError |
| 97 |
__HERE__ |
| 98 |
|
| 99 |
purge_workflow |
| 100 |
|
| 101 |
#------------------------------------------------------------------------------ |
| 102 |
# Test missing include file |
| 103 |
install_workflow "${TEST_NAME_BASE}" include-missing |
| 104 |
|
| 105 |
TEST_NAME="${TEST_NAME_BASE}-include-missing" |
| 106 |
run_fail "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" |
| 107 |
|
| 108 |
sub_tabs |
| 109 |
cmp_ok "${TEST_NAME}.stderr" <<__HERE__ |
| 110 |
Jinja2Error: runtime.cylc |
| 111 |
File ${WORKFLOW_RUN_DIR}/flow.cylc |
| 112 |
[[graph]] |
| 113 |
R1 = "a => FAM" |
| 114 |
[runtime] |
| 115 |
{% include 'runtime.cylc' %} <-- TemplateNotFound |
| 116 |
__HERE__ |
| 117 |
|
| 118 |
purge_workflow |
| 119 |
|
| 120 |
#------------------------------------------------------------------------------ |
| 121 |
# Test incomplete loop |
| 122 |
install_workflow "${TEST_NAME_BASE}" include-incomplete |
| 123 |
|
| 124 |
TEST_NAME="${TEST_NAME_BASE}-include-incomplete" |
| 125 |
run_fail "${TEST_NAME}" cylc validate "${WORKFLOW_NAME}" |
| 126 |
|
| 127 |
sub_tabs |
| 128 |
cmp_ok "${TEST_NAME}.stderr" << __HERE__ |
| 129 |
Jinja2Error: Unexpected end of template. |
| 130 |
Error in file "runtime-incomplete.cylc" |
| 131 |
Jinja was looking for the following tags: 'endfor' or 'else'. The |
| 132 |
innermost block that needs to be closed is 'for'. |
| 133 |
File ${WORKFLOW_RUN_DIR}/runtime-incomplete.cylc |
| 134 |
{%- for num in range(5) %} |
| 135 |
[[member_{{ num }}]] |
| 136 |
inherit = FAM |
| 137 |
script = echo I am \$TITLE {{ num }} <-- TemplateSyntaxError |
| 138 |
File ${WORKFLOW_RUN_DIR}/flow.cylc |
| 139 |
[[graph]] |
| 140 |
R1 = "a => FAM" |
| 141 |
[runtime] |
| 142 |
{% include 'runtime-incomplete.cylc' %} <-- TemplateSyntaxError |
| 143 |
__HERE__ |
| 144 |
|
| 145 |
purge_workflow |