this repo has no description
1#!/bin/bash 2# vim: ft=sh ts=4 sw=4 et 3# 4# usage: run-tests <prog> <suffix> [<dirname> ...] 5# 6# Find the test cases in <dirname> ... and subdirectories thereof and run 7# them with 'run-test <prog> <testcase>'. Failing test cases are summarised 8# in a FAILURES.<prog> file. 9# 10# A test case is either <model><suffix> or <model>.<testid>.dzn 11# where there is a corresponding <model><suffix> file. 12# 13# Note that if a model file does not contain a comment of the form 14# 'RUNS ON <prog>' then the test case will be skipped. Ignored test 15# cases are summarised in an IGNORED.<prog> file. 16 17# If the environment variable FORCE_DELAY is set then a small delay 18# will be introduced between each test case. This is useful for 19# avoid resource limits on Mac OS X, usually indicated by the following 20# error message: 21# 22# fork: Resource temporarily unavailable 23 24# Uncomment the next line for debugging: 25# set -x 26 27# The name of this program as invoked. 28# 29THIS=$(basename $0) 30 31THISDIR="$(pwd)" 32 33# 34if [ $# -lt 2 ] 35then 36 echo "usage: $THIS <prog> <suffix> [<dirname> ...]" >&2 37 exit 1 38fi 39 40PROG=$1 41SUFFIX=$2 42shift 2 43DIRS=$@ 44[ -z "$DIRS" ] && DIRS=. 45BASEPROG=$(basename $PROG) 46FAILURES="$(pwd)/FAILURES.$BASEPROG" 47IGNORES="$(pwd)/IGNORED.$BASEPROG" 48RUNSONREGEX="\<RUNS *ON *$BASEPROG\>" 49 50# Clear out any old IGNORES and FAILURES files. 51# 52rm -f "$IGNORES" "$FAILURES" 53 54NTESTS=0 55NFAIL=0 56 57# Find all applicable test cases. 58# 59for FILENAME in $(find $DIRS -name '*'$SUFFIX -o -name '*.dzn' | sort) 60do 61 62 # Return to the directory where we began. 63 # 64 cd "$THISDIR" >/dev/null 2>&1 65 66 # cd to the directory of the problem file. 67 # 68 DIR=$(dirname $FILENAME) 69 if [ -n "$DIR" ] 70 then 71 cd $DIR >/dev/null 2>&1 72 FILENAME=$(basename $FILENAME) 73 fi 74 75 # Skip this file if there's a corresponding .dzn file or 76 # it is a .dzn file, but doesn't have the corresponding $SUFFIX file. 77 # 78 case $FILENAME in 79 *.dzn) 80 # Ignore .dzn files that don't have a model file with 81 # the right suffix. 82 MODELNAME=$(echo $FILENAME | sed 's/[.].*//')$SUFFIX 83 if [ ! -e $MODELNAME ] 84 then 85 continue 86 fi 87 MODELFILE=$MODELNAME 88 ;; 89 *) 90 # Ignore model files that have one or more .dzn files. 91 BASENAME=$(basename $FILENAME $SUFFIX) 92 if ls $BASENAME'*.dzn' >/dev/null 2>&1 93 then 94 continue 95 fi 96 MODELFILE=$FILENAME 97 ;; 98 esac 99 100 # Ignore model files that don't contain the 101 # string 'RUNS ON $BASEPROG'. 102 if ! grep -q "$RUNSONREGEX" $MODELFILE 103 then 104 echo "$DIR/$FILENAME" >> "$IGNORES" 105 continue 106 fi 107 108 # Run the test. 109 # 110 PASSFAIL=fail 111 run-test $PROG $FILENAME && PASSFAIL=pass 112 113 NTESTS=$((NTESTS+1)) 114 115 if test $FORCE_DELAY 116 then 117 sleep 1 118 fi 119 120 # Return to the directory where we began. 121 # 122 cd "$THISDIR" >/dev/null 2>&1 123 124 if [ $PASSFAIL = "fail" ] 125 then 126 NFAIL=$((NFAIL+1)) 127 echo "$DIR/$FILENAME ($PROG)" >> "$FAILURES" 128 fi 129 130done 131 132if [ -e "$FAILURES" ] 133then 134 echo "$(basename $FAILURES):" 135 cat "$FAILURES" 136 echo "$((100-$NFAIL*100/$NTESTS))"% of tests succeeded 137else 138 echo "All tests passed." 139fi