run-tests 2.7 KB
Newer Older
1
2
#! /bin/sh

3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Copyright (C) 2000, 2001, 2002, 2004, 2005, 2011, 2012  Niels Möller
#
# This program 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 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

19
20
21
failed=0
all=0

22
debug='no'
23
testflags=''
24

25
26
27
28
29
30
if [ -z "$srcdir" ] ; then
  srcdir=`pwd`
fi

export srcdir

31
32
33
34
35
36
37
if [ -n "$TEST_SHLIB_DIR" ] ; then
  # Prepend to LD_LIBRARY_PATH, if it is alredy set.
  LD_LIBRARY_PATH="${TEST_SHLIB_DIR}${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
  # For MACOS
  DYLD_LIBRARY_PATH="$TEST_SHLIB_DIR"
  # For Windows
  PATH="${TEST_SHLIB_DIR}:${PATH}"
38
39
40
  # For Wine
  WINEPATH="${TEST_SHLIB_DIR}"

41
42
43
  export LD_LIBRARY_PATH
  export DYLD_LIBRARY_PATH
  export PATH
44
  export WINEPATH
45
46
fi

47
# When used in make rules, we sometimes get the filenames VPATH
48
# expanded, but usually not.
49
find_program () {
50
51
52
53
54
55
56
57
58
59
60
61
    case "$1" in
	*/*)
	  echo "$1"
	  ;;
	*)
	  if [ -x "$1" ] ; then
	      echo "./$1"
	  else
	      echo "$srcdir/$1"
	  fi
	  ;;
    esac
62
63
64
65
66
67
68
69
70
71
72
73
}

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

test_program () {
74
75
  testname=`basename "$1" .exe`
  testname=`basename "$testname" -test`
76
77
78
  if [ -z "$EMULATOR" ] || head -1 "$1" | grep '^#!' > /dev/null; then
    "$1" $testflags
  else
79
    $EMULATOR "$1" $testflags
80
  fi
81
82
  case "$?" in
      0)
83
	echo PASS: $testname
84
85
86
	all=`expr $all + 1`
	;;
      77)
87
	echo SKIP: $testname
88
89
      ;;
      *)
90
	echo FAIL: $testname
91
92
93
94
95
96
97
98
	failed=`expr $failed + 1`
	all=`expr $all + 1`
	;;
  esac
}

env_program `find_program setup-env`

99
100
101
102
103
104
while test $# != 0
do
  case "$1" in
  --debug)
    debug=yes
    ;;
105
106
107
  -v)
    testflags='-v'
    ;;
108
  -*)
109
    echo >&2 'Unknown option `'"$1'"
110
111
112
113
114
115
116
117
    exit 1
    ;;
  *)
    break
    ;;
  esac
  shift
done
118

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
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"

135
136
137
if [ "x$debug" = xno ] ; then
  env_program `find_program teardown-env`
fi
138
139

[ "$failed" -eq 0 ]