diff options
author | Adrian Thurston <thurston@complang.org> | 2012-05-27 10:38:52 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2012-05-27 10:38:52 -0400 |
commit | 2d0c6b38fbf746197f249416d523a7118ec5a37c (patch) | |
tree | 14c45b9d619db770a95195cd0e59cc8b3475d6b5 | |
parent | 7b5854a931b1ee0ee539292f74f9bd8e6703680e (diff) | |
download | colm-2d0c6b38fbf746197f249416d523a7118ec5a37c.tar.gz |
added shell script test harness
Added a shell script test harness that executes all the lm tests in the current
directory. Doesn't require any makefile generation, TESTS file, etc. The shell
script be easily programmed to add extra steps during testing, such as pre/post
execution, linking, etc. Just the better way to go.
-rw-r--r-- | test/.gitignore | 1 | ||||
-rw-r--r-- | test/Makefile.am | 14 | ||||
-rwxr-xr-x | test/runtests.sh | 161 |
3 files changed, 166 insertions, 10 deletions
diff --git a/test/.gitignore b/test/.gitignore index 7f071c97..dcdd7c5b 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -2,5 +2,6 @@ /*.c /*.bin /*.out +/*.log /Makefile.in /Makefile diff --git a/test/Makefile.am b/test/Makefile.am index c983fc9a..774d0dac 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1,6 +1,6 @@ -TESTS = runtests.mk +TESTS = runtests.sh -TEST_CASES = \ +EXTRA_DIST = runtests.sh \ ambig1.lm \ backtrack1.lm \ backtrack2.lm \ @@ -79,9 +79,7 @@ TEST_CASES = \ concat2.lm \ ignore1.lm \ ignore2.lm \ - ignore3.lm - -INPUT = \ + ignore3.lm \ ambig1.in \ accum1.in \ accum2.in \ @@ -147,9 +145,7 @@ INPUT = \ concat2.in \ ignore1.in \ ignore2.in \ - ignore3.in - -EXPECTED_OUTPUT = \ + ignore3.in \ ambig1.exp \ accum1.exp \ accum2.exp \ @@ -229,5 +225,3 @@ EXPECTED_OUTPUT = \ ignore1.exp \ ignore2.exp \ ignore3.exp - -EXTRA_DIST = genmf TESTS runtests.mk $(TEST_CASES) $(INPUT) $(EXPECTED_OUTPUT) diff --git a/test/runtests.sh b/test/runtests.sh new file mode 100755 index 00000000..3b141891 --- /dev/null +++ b/test/runtests.sh @@ -0,0 +1,161 @@ +#!/bin/bash +# + +# Test files have the extention 'tst'. They contain sections giving config +# data, function names, SQL code and expected output. + +# ##### FNC ##### +# Function name. +# ##### CNF ##### +# Configuration data. +# ##### SQL ##### +# SQL code to run ahead of the test. +# ##### PCY ##### +# Policy to use for the test. +# ##### EXP ##### +# Expected Output. +####################################### + +cd `dirname $0` + + +function die() +{ + echo + echo "$@" + echo + exit 1 +} + +function sig_exit() +{ + echo + exit 1; +} + +errors=0 + +#trap sig_exit SIGINT +#trap sig_exit SIGQUIT + +COLM=../colm/colm + +[ -d $DATA ] || die "error: data directory not found" + +# Parse args. +while getopts vdm opt; do + case $opt in + v) + verbose=true; + ;; + d) + diff=true; + ;; + m) + VALGRIND="valgrind --leak-check=full --show-reachable=yes --suppressions=../dpi.supp" + ;; + esac +done +shift $(($OPTIND - 1)) + +# The files to process. If none given then glob all functions and pcap test confs. +if [ $# != 0 ]; then + TEST_PAT="$*" +else + TEST_PAT='*.lm' +fi + +function runtests() +{ + for TST in $TEST_PAT; do + INP=${TST/.lm}.in + EXP=${TST/.lm}.exp + ARGS=${TST/.lm}.args + + BIN=${TST/.lm}.bin + OUT=${TST/.lm}.out + DIFF=${TST/.lm}.diff + LOG=${TST/.lm}.log + + cmdargs="" + if [ -f $ARGS ]; then + cmdargs=`cat $ARGS` + fi + + echo -n "running test $TST ... " + if [ "$verbose" = true ]; then + echo + echo command here + echo -n ... + fi + + # Check for expected output. + if [ '!' -f $EXP ]; then + echo "FAILED no expected output" + errors=$(( errors + 1 )) + continue + + fi + + # Compilation. + $COLM $TST &> $LOG + if [ $? != 0 ]; then + echo "FAILED compilation" + errors=$(( errors + 1 )) + continue + fi + + + # Execution + if [ -f $INP ]; then + ./$BIN $cmdargs < $INP > $OUT 2>> $LOG + else + ./$BIN $cmdargs > $OUT + fi + if [ $? != 0 ]; then + echo "FAILED execution" + errors=$(( errors + 1 )) + continue + fi + + # Diff of output + diff -u $EXP $OUT > $DIFF + if [ $? != 0 ]; then + echo "FAILED output diff" + errors=$(( errors + 1 )) + continue + fi + + echo ok + done + + if [ $errors != 0 ]; then + [ $errors != 1 ] && plural="s"; + echo + echo "TESTING FAILED: $errors failure$plural" + echo + EXIT=1 + fi +} + +function diffs() +{ + for TST in $TEST_PAT; do + EXP=${TST/.*}.exp + OUT=${TST/.*}.out + + [ -f $EXP ] || die "error: the expected output file $EXP was not found" + diff -u $EXP $OUT + done +} + +[ -d $workingdir ] || mkdir $workingdir + +runtests; + +if [ "$diff" = true ]; then + diffs; +fi + +exit $EXIT; + |