-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from PowerDNS/templates-nested-if
Templates: support nested @if statements
- Loading branch information
Showing
9 changed files
with
219 additions
and
31 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
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
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
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,14 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
cd testdata | ||
|
||
if ! diff -u test-expected.txt <(../templating.sh test-template.txt) ; then | ||
echo | ||
echo "FAILED" | ||
exit 1 | ||
fi | ||
|
||
echo "PASSED" | ||
|
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,51 @@ | ||
Lines can start with @INCLUDE, @EVAL or @EXEC for special processing, they | ||
have no effect when not at the start of a line. | ||
|
||
|
||
Direct @INCLUDE: | ||
[Include file 1 start] | ||
value of FOO in include is also 123 | ||
[Include file 1 end] | ||
|
||
|
||
The value of FOO is 123 | ||
|
||
Empty @EXEC: | ||
@EXEC | ||
|
||
Conditional include in @EXEC: | ||
[Second include start] | ||
Hello world! | ||
[Second include end] | ||
|
||
|
||
This line is only printed if $FOO = "123", which is the case. | ||
Nested IF that is true. | ||
In between IFs. | ||
Last line of first IF. | ||
|
||
Triple nested IF that is true. | ||
Also true. | ||
Second level. | ||
First level. | ||
|
||
|
||
true1 | ||
true1 | ||
|
||
true1 | ||
true2 | ||
true2 | ||
true1 | ||
|
||
# Test @IF with extra indenting after the @ | ||
|
||
true1 | ||
true2 | ||
true2 | ||
Other directives also get indenting | ||
true1 | ||
|
||
|
||
Other lines are printed unchanged. | ||
|
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,3 @@ | ||
[Include file 1 start] | ||
@EVAL value of FOO in include is also $FOO | ||
[Include file 1 end] |
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,3 @@ | ||
[Second include start] | ||
@EXEC echo "Hello world!" | ||
[Second include end] |
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,90 @@ | ||
Lines can start with @INCLUDE, @EVAL or @EXEC for special processing, they | ||
have no effect when not at the start of a line. | ||
|
||
@EXEC FOO=123 | ||
|
||
Direct @INCLUDE: | ||
@INCLUDE test-template-include1.txt | ||
|
||
@EVAL The value of FOO is $FOO | ||
|
||
Empty @EXEC: | ||
@EXEC | ||
|
||
Conditional include in @EXEC: | ||
@EXEC [ "$FOO" = "123" ] && include test-template-include2.txt | ||
|
||
@IF [ "$FOO" = "123" ] | ||
This line is only printed if $FOO = "123", which is the case. | ||
@IF true | ||
Nested IF that is true. | ||
@ENDIF | ||
In between IFs. | ||
@IF [ "$FOO" = "wrong" ] | ||
THIS WILL NEVER BE PRINTED. | ||
@ENDIF | ||
Last line of first IF. | ||
@ENDIF | ||
|
||
@IF true | ||
@IF true | ||
@IF true | ||
Triple nested IF that is true. | ||
@ENDIF | ||
@IF true | ||
Also true. | ||
@ENDIF | ||
Second level. | ||
@ENDIF | ||
First level. | ||
@ENDIF | ||
|
||
@IF false | ||
@IF true | ||
@IF true | ||
Triple nested IF that is FALSE. | ||
@ENDIF | ||
@ENDIF | ||
@ENDIF | ||
|
||
@IF true | ||
true1 | ||
@IF false | ||
false2 | ||
@IF true | ||
Triple nested IF that is FALSE. | ||
@ENDIF | ||
false2 MUST NOT APPEAR, BUG! | ||
@ENDIF | ||
true1 | ||
@ENDIF | ||
|
||
@IF true | ||
true1 | ||
@IF true | ||
true2 | ||
@IF false | ||
Triple nested IF that is FALSE. | ||
@ENDIF | ||
true2 | ||
@ENDIF | ||
true1 | ||
@ENDIF | ||
|
||
# Test @IF with extra indenting after the @ | ||
|
||
@IF true | ||
true1 | ||
@ IF true | ||
true2 | ||
@ IF false | ||
Triple nested IF that is FALSE. | ||
@ ENDIF | ||
true2 | ||
@ EXEC echo "Other directives also get indenting" | ||
@ ENDIF | ||
true1 | ||
@ENDIF | ||
|
||
|
||
Other lines are printed unchanged. |
10 changes: 5 additions & 5 deletions
10
tests/test-centos-8-reproducible.sh → tests/test-rocky-8-reproducible.sh
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