---
src/compiler/Makefile | 14 ++++++++++++
src/compiler/test/Common | 52 ++++++++++++++++++++++++++++++++++++++++++++++
src/compiler/test/arith | 49 +++++++++++++++++++++++++++++++++++++++++++
src/compiler/test/error | 23 ++++++++++++++++++++
4 files changed, 138 insertions(+), 0 deletions(-)
create mode 100755 src/compiler/test/Common
create mode 100755 src/compiler/test/arith
create mode 100755 src/compiler/test/error
diff --git a/src/compiler/Makefile b/src/compiler/Makefile
index 4090428..9575ed4 100644
--- a/src/compiler/Makefile
+++ b/src/compiler/Makefile
@@ -1,9 +1,23 @@
.PHONY: all clean
+.PHONY: test tests valgrind
all:
$(MAKE) -C ptest
+# ----- Tests -----------------------------------------------------------------
+
+test tests: all
+ LANG= sh -c \
+ 'passed=0 && cd test && \
+ for n in [a-z]*; do \
+ [ $$n != core ] && SCRIPT=$$n . ./$$n; done; \
+ echo "Passed all $$passed tests"'
+
+valgrind:
+ VALGRIND="valgrind -q" $(MAKE) tests
+
# ----- Cleanup ---------------------------------------------------------------
clean:
$(MAKE) -C ptest clean
+ rm -f test/core
diff --git a/src/compiler/test/Common b/src/compiler/test/Common
new file mode 100755
index 0000000..c06f95f
--- /dev/null
+++ b/src/compiler/test/Common
@@ -0,0 +1,52 @@
+#!/bin/sh
+#
+# Common - Elements shared by all regression tests for the FNP parser
+#
+# Written 2010, 2011 by Werner Almesberger
+# Copyright 2010, 2011 Werner Almesberger
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+
+
+ptest()
+{
+ echo -n "$1: " 1>&2
+ shift
+ $VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 || {
+ echo FAILED "($SCRIPT)" 1>&2
+ cat _out
+ rm -f _out
+ exit 1
+ }
+}
+
+
+ptest_fail()
+{
+ echo -n "$1: " 1>&2
+ shift
+ $VALGRIND ${PTST:-../ptest/ptest} "$@" >_out 2>&1 && {
+ echo FAILED "($SCRIPT)" 1>&2
+ cat _out
+ rm -f _out
+ exit 1
+ }
+}
+
+
+expect()
+{
+ diff -u - "$@" _out >_diff || {
+ echo FAILED "($SCRIPT)" 1>&2
+ cat _diff 1>&2
+ rm -f _out _diff
+ exit 1
+ }
+ echo PASSED 1>&2
+ rm -f _out _diff
+ passed=`expr ${passed:-0} + 1`
+}
diff --git a/src/compiler/test/arith b/src/compiler/test/arith
new file mode 100755
index 0000000..0969d7d
--- /dev/null
+++ b/src/compiler/test/arith
@@ -0,0 +1,49 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+ptest "arithmetic: x = a+b" <<EOF
+x = a+b
+EOF
+expect <<EOF
+x = (+ a b)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "arithmetic: x = a-b" <<EOF
+x = a-b
+EOF
+expect <<EOF
+x = (- a b)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "arithmetic: x = a*b" <<EOF
+x = a*b
+EOF
+expect <<EOF
+x = (* a b)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "arithmetic: x = a/b" <<EOF
+x = a/b
+EOF
+expect <<EOF
+x = (/ a b)
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest "arithmetic: x = a%b" <<EOF
+x = a/b
+EOF
+expect <<EOF
+x = (/ a b)
+EOF
+
+###############################################################################
diff --git a/src/compiler/test/error b/src/compiler/test/error
new file mode 100755
index 0000000..4aed73f
--- /dev/null
+++ b/src/compiler/test/error
@@ -0,0 +1,23 @@
+#!/bin/sh
+. ./Common
+
+###############################################################################
+
+ptest_fail "syntax error: x = backtick" <<EOF
+x = \`
+EOF
+expect <<EOF
+FPVM: scan error
+EOF
+
+#------------------------------------------------------------------------------
+
+ptest_fail "syntax error: x = a b" <<EOF
+x = a b
+EOF
+expect <<EOF
+x = a
+FPVM: parse error
+EOF
+
+###############################################################################
--
1.7.1
_______________________________________________
http://lists.milkymist.org/listinfo.cgi/devel-milkymist.org
IRC: #milkymist@Freenode