diff options
author | Adrian Thurston <thurston@complang.org> | 2013-03-17 14:09:50 -0400 |
---|---|---|
committer | Adrian Thurston <thurston@complang.org> | 2013-03-17 14:09:50 -0400 |
commit | 4850ad1ce13aab0d6269a80a28c42503362b182e (patch) | |
tree | 1a579ad1ef4a7535582a7dd839f01c2ba3e8a749 /test | |
parent | dc0b967dc383976e77ca2cf703b1d27f6271b076 (diff) | |
download | colm-4850ad1ce13aab0d6269a80a28c42503362b182e.tar.gz |
moving to a combined test case format
The test case sections are extracted from the test case file. Added a script
combine.sh for helping with the conversion.
Diffstat (limited to 'test')
-rw-r--r-- | test/.gitignore | 6 | ||||
-rwxr-xr-x | test/combine.sh | 29 | ||||
-rwxr-xr-x | test/runtests.sh | 125 |
3 files changed, 107 insertions, 53 deletions
diff --git a/test/.gitignore b/test/.gitignore index dcdd7c5b..033897db 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,7 +1,3 @@ -/*.diff -/*.c -/*.bin -/*.out -/*.log /Makefile.in /Makefile +/working diff --git a/test/combine.sh b/test/combine.sh new file mode 100755 index 00000000..2c4739ff --- /dev/null +++ b/test/combine.sh @@ -0,0 +1,29 @@ +#!/bin/bash +# + +for fn in $@; do + [ -f $fn ] || continue + ( + echo '##### LM #####'; + cat $fn + + if [ -f ${fn%.lm}.args ]; then + echo '##### ARGS #####'; + cat ${fn%.lm}.args + fi + + if [ -f ${fn%.lm}.in ]; then + echo '##### IN #####'; + cat ${fn%.lm}.in + fi + + if [ -f ${fn%.lm}.exp ]; then + echo '##### EXP #####'; + cat ${fn%.lm}.exp + fi + + ) \ + > ${fn%.lm}.tst; + cat ${fn%.lm}.tst > $fn; + rm ${fn%.lm}.tst; +done diff --git a/test/runtests.sh b/test/runtests.sh index 69ed79d6..f1b53b2a 100755 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -1,23 +1,25 @@ #!/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. +# Test cases contain sections giving the program, input and expected output. + +###### COLM ##### +# colm program +###### ARGS ##### +# program arguments +###### IN ##### +# program input +###### EXP ##### +# expected output + ####################################### -cd `dirname $0` +WORKING=working +COLM=../colm/colm +ERRORS=0 +cd `dirname $0` +test -d $WORKING || mkdir $WORKING function die() { @@ -33,15 +35,6 @@ function sig_exit() 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 @@ -65,17 +58,48 @@ else TEST_PAT='*.lm' fi +function section +{ + local section=$1 + local in=$2 + local out=$3 + + awk -vsection=$section ' + /#+ *[a-zA-Z]+ *#+/ { + gsub( "[ #\n]", "", $0 ); + if ( $0 == section ) + in_section = 1 + else + in_section = 0 + next; + } + + in_section { + print $0 + } + ' $in > $out + + [ -s $out ] || rm $out +} + 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 + ROOT=${TST/.lm} + LM=$WORKING/$ROOT.lm + ARGS=$WORKING/$ROOT.args + IN=$WORKING/$ROOT.in + EXP=$WORKING/$ROOT.exp + + section LM $TST $LM + section ARGS $TST $ARGS + section IN $TST $IN + section EXP $TST $EXP + + BIN=$WORKING/$ROOT.bin + OUT=$WORKING/$ROOT.out + DIFF=$WORKING/$ROOT.diff + LOG=$WORKING/$ROOT.log cmdargs="" if [ -f $ARGS ]; then @@ -84,12 +108,17 @@ function runtests() echo -n "running test $TST ... " + if [ '!' -f $LM ]; then + echo "FAILED: no colm program" + ERRORS=$(( ERRORS + 1 )) + continue + fi + # Check for expected output. if [ '!' -f $EXP ]; then - echo "FAILED no expected output" - errors=$(( errors + 1 )) + echo "FAILED: no expected output" + ERRORS=$(( ERRORS + 1 )) continue - fi if [ "$verbose" = true ]; then @@ -98,48 +127,48 @@ function runtests() fi # Compilation. - $COLM $TST &> $LOG + $COLM $LM &> $LOG if [ $? != 0 ]; then - echo "FAILED compilation" - errors=$(( errors + 1 )) + echo "FAILED: compilation error" + ERRORS=$(( ERRORS + 1 )) continue fi if [ "$verbose" = true ]; then - if [ -f $INP ]; then - echo "${VALGRIND}./$BIN $cmdargs < $INP > $OUT 2>> $LOG" + if [ -f $IN ]; then + echo "${VALGRIND}./$BIN $cmdargs < $IN > $OUT 2>> $LOG" else echo "${VALGRIND}./$BIN $cmdargs > $OUT 2>>$LOG" fi fi # Execution - if [ -f $INP ]; then - ${VALGRIND}./$BIN $cmdargs < $INP > $OUT 2>> $LOG + if [ -f $IN ]; then + ${VALGRIND}./$BIN $cmdargs < $IN > $OUT 2>> $LOG else ${VALGRIND}./$BIN $cmdargs > $OUT 2>>$LOG fi if [ $? != 0 ]; then - echo "FAILED execution" - errors=$(( errors + 1 )) + echo "FAILED: execution error" + ERRORS=$(( ERRORS + 1 )) continue fi # Diff of output diff -u $EXP $OUT > $DIFF if [ $? != 0 ]; then - echo "FAILED output diff" - errors=$(( errors + 1 )) + echo "FAILED: output differs from expected output" + ERRORS=$(( ERRORS + 1 )) continue fi echo ok done - if [ $errors != 0 ]; then - [ $errors != 1 ] && plural="s"; + if [ $ERRORS != 0 ]; then + [ $ERRORS != 1 ] && plural="s"; echo - echo "TESTING FAILED: $errors failure$plural" + echo "TESTING FAILED: $ERRORS failure$plural" echo EXIT=1 fi |