Flex/Bison based compiler and interpreter written in C++ (using Boost)
File detail
Source code
#!/bin/bash
# Copyright (C) 2008 Kamil Dudka <xdudka00@stud.fit.vutbr.cz>
#
# This file is part of vyp08 (compiler and interpreter of VYP08 language).
#
# vyp08 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 3 of the License, or
# any later version.
#
# vyp08 is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with vyp08. If not, see <http://www.gnu.org/licenses/>.
VYP08=./vyp08 # vyp08 binary
DATA=../data # data directory
SRC="$DATA/$1.vyp08" # source code of VYP08 program
INPUT="$DATA/$1.in" # program input (if any)
OUTPUT="$1.out" # program output
OUT_OK="$DATA/$OUTPUT" # program expected output (if any)
# determine if test is expected to fail or not (upon test name)
FAIL_OK=0
echo "$1" | egrep "^test(-[0-9]+)?-err" && FAIL_OK=1
# turn on bash verbose output
set -x
# test source code (in VYP08 language) not found
test -e $SRC || exit -1
# run test
FAIL=0
if test -e $INPUT; then
# use given input
$VYP08 $SRC <$INPUT >$OUTPUT || FAIL=1
else
# no input
$VYP08 $SRC >$OUTPUT || FAIL=1
fi
# compare exit code with its expected value
test "$FAIL" -eq "$FAIL_OK" || exit -1
# compare program output with the expected one
if test -e $OUT_OK; then
diff $OUTPUT $OUT_OK 1>&2 || exit -1
fi
# cleanup and exit (on success)
rm -f $OUTPUT
exit 0