run-tests 1.57 KB
Newer Older
1 2 3 4 5
#! /bin/sh

failed=0
all=0

6
debug='no'
7
testflags=''
8

9 10 11 12 13 14
if [ -z "$srcdir" ] ; then
  srcdir=`pwd`
fi

export srcdir

15 16
# When used in make rules, we sometimes get the filenames VPATH
# expanded, but usually not. 
17
find_program () {
18 19 20 21 22 23 24 25 26 27 28 29
    case "$1" in
	*/*)
	  echo "$1"
	  ;;
	*)
	  if [ -x "$1" ] ; then
	      echo "./$1"
	  else
	      echo "$srcdir/$1"
	  fi
	  ;;
    esac
30 31 32 33 34 35 36 37 38 39 40 41
}

env_program () {
  if [ -x "$1" ] ; then
    if "$1"; then : ; else
      echo FAIL: $1
      exit 1
    fi
  fi
}

test_program () {
42 43
  testname=`basename "$1" .exe`
  testname=`basename "$testname" -test`
44 45 46 47 48
  if [ -z "$EMULATOR" ] || head -1 "$1" | grep '^#!' > /dev/null; then
    "$1" $testflags
  else
    "$EMULATOR" "$1" $testflags
  fi
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  case "$?" in
      0)
    	echo PASS: $testname
	all=`expr $all + 1`
	;;
      77)
      	echo SKIP: $testname
      ;;
      *)
    	echo FAIL: $testname
	failed=`expr $failed + 1`
	all=`expr $all + 1`
	;;
  esac
}

env_program `find_program setup-env`

67 68 69 70 71 72
while test $# != 0
do
  case "$1" in
  --debug)
    debug=yes
    ;;
73 74 75
  -v)
    testflags='-v'
    ;;
76 77 78 79 80 81 82 83 84 85 86
  -*)
    echo >&2 'Unknown option `'"$1'" 
    exit 1
    ;;
  *)
    break
    ;;
  esac
  shift
done
  
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
if [ $# -eq 0 ] ; then
  for f in *-test; do test_program "./$f"; done
else
  for f in "$@" ; do test_program `find_program "$f"`; done
fi

if [ $failed -eq 0 ] ; then
  banner="All $all tests passed"
else
  banner="$failed of $all tests failed"
fi
dashes=`echo "$banner" | sed s/./=/g`
echo "$dashes"
echo "$banner"
echo "$dashes"

103 104 105
if [ "x$debug" = xno ] ; then
  env_program `find_program teardown-env`
fi
106 107 108

[ "$failed" -eq 0 ]