From fc8f7eec23e8e95fc9a4a483bb69a1ee6866069d Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Wed, 23 Oct 2013 00:01:49 +0200 Subject: Added some tests --- test.php | 18 ++++++++++++++++++ tests/dump_ast.php | 5 +++++ tests/mktest.sh | 15 +++++++++++++++ tests/run_all.sh | 21 +++++++++++++++++++++ tests/test.php | 23 +++++++++++++++++++++++ tests/test_loop/.gitignore | 3 +++ tests/test_loop/code.php | 5 +++++ tests/test_loop/test.tpl | 3 +++ tests/test_loop/want | 11 +++++++++++ tests/test_simple/.gitignore | 3 +++ tests/test_simple/code.php | 5 +++++ tests/test_simple/test.tpl | 1 + tests/test_simple/want | 1 + 13 files changed, 114 insertions(+) create mode 100644 test.php create mode 100644 tests/dump_ast.php create mode 100755 tests/mktest.sh create mode 100755 tests/run_all.sh create mode 100644 tests/test.php create mode 100644 tests/test_loop/.gitignore create mode 100644 tests/test_loop/code.php create mode 100644 tests/test_loop/test.tpl create mode 100644 tests/test_loop/want create mode 100644 tests/test_simple/.gitignore create mode 100644 tests/test_simple/code.php create mode 100644 tests/test_simple/test.tpl create mode 100644 tests/test_simple/want diff --git a/test.php b/test.php new file mode 100644 index 0000000..c9a72ed --- /dev/null +++ b/test.php @@ -0,0 +1,18 @@ +rewrite($file); + echo "Could not parse:\n"; + echo $e->getMessage(); + echo "\n"; + exit(1); +} + +echo "~~~~~~~~~~~\n"; +var_dump($ast); \ No newline at end of file diff --git a/tests/dump_ast.php b/tests/dump_ast.php new file mode 100644 index 0000000..418fbc8 --- /dev/null +++ b/tests/dump_ast.php @@ -0,0 +1,5 @@ + "$1/code.php" + +echo 'have +*.ast +*.transc.php' > "$1/.gitignore" diff --git a/tests/run_all.sh b/tests/run_all.sh new file mode 100755 index 0000000..75909d1 --- /dev/null +++ b/tests/run_all.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +r=0 +for t in test_*; do + cd $t + php ../test.php > have + echo -n "$t: " + if cmp want have; then + echo "OK" + rm *.transc.php + else + echo "FAILED" + for tpl in *.tpl; do + php ../dump_ast.php < $tpl > $tpl.ast + done + r=1 + fi + cd .. +done + +exit $r \ No newline at end of file diff --git a/tests/test.php b/tests/test.php new file mode 100644 index 0000000..41713dc --- /dev/null +++ b/tests/test.php @@ -0,0 +1,23 @@ +exectemplate("test.tpl"); diff --git a/tests/test_loop/.gitignore b/tests/test_loop/.gitignore new file mode 100644 index 0000000..de2a41b --- /dev/null +++ b/tests/test_loop/.gitignore @@ -0,0 +1,3 @@ +have +*.ast +*.transc.php diff --git a/tests/test_loop/code.php b/tests/test_loop/code.php new file mode 100644 index 0000000..de8c553 --- /dev/null +++ b/tests/test_loop/code.php @@ -0,0 +1,5 @@ + +$i + \ No newline at end of file diff --git a/tests/test_loop/want b/tests/test_loop/want new file mode 100644 index 0000000..30b148d --- /dev/null +++ b/tests/test_loop/want @@ -0,0 +1,11 @@ +10 +9 +8 +7 +6 +5 +4 +3 +2 +1 +0 diff --git a/tests/test_simple/.gitignore b/tests/test_simple/.gitignore new file mode 100644 index 0000000..de2a41b --- /dev/null +++ b/tests/test_simple/.gitignore @@ -0,0 +1,3 @@ +have +*.ast +*.transc.php diff --git a/tests/test_simple/code.php b/tests/test_simple/code.php new file mode 100644 index 0000000..4c0babc --- /dev/null +++ b/tests/test_simple/code.php @@ -0,0 +1,5 @@ +vars["foo"] = "World"; +} diff --git a/tests/test_simple/test.tpl b/tests/test_simple/test.tpl new file mode 100644 index 0000000..30a4f22 --- /dev/null +++ b/tests/test_simple/test.tpl @@ -0,0 +1 @@ +Hello $foo! \ No newline at end of file diff --git a/tests/test_simple/want b/tests/test_simple/want new file mode 100644 index 0000000..c57eff5 --- /dev/null +++ b/tests/test_simple/want @@ -0,0 +1 @@ +Hello World! \ No newline at end of file -- cgit v1.2.3-54-g00ecf