File: testall.in

package info (click to toggle)
regina-normal 7.4.1-1.1
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 154,244 kB
  • sloc: cpp: 295,026; xml: 9,992; sh: 1,344; python: 1,225; perl: 616; ansic: 138; makefile: 26
file content (174 lines) | stat: -rwxr-xr-x 6,082 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
#
# Regina - A Normal Surface Theory Calculator
# Python Test Suite Runner
#
# Copyright (c) 2007-2025, Ben Burton
# For further details contact Ben Burton (bab@debian.org).
#
# Usage: testall
#
# Runs the entire Python test suite.  This script searches for files
# named *.test in or beneath the current directory, runs them through
# regina-python, and compares the results byte-by-byte with the
# corresponding *.out files.  Any mismatches are considered to be test
# failures.
#
# If the output is expected to differ between pybind11 2.x.y (used with
# Python 3.11 and earlier) vs pybind11 3.x.y (used with Python 3.12 and
# later), there should instead be two output files: *.out.v2 and *.out.v3.
# If *.out is present, this will take priority over *.out.v2 and/or *.out.v3.
#
# This script MUST be run from the python/testsuite directory in the
# build tree.  It runs regina-python directly out of the build tree.
# It does not require regina to be installed on the system (and indeed
# it ignores any installation that it might find).
#
# Because tests might need to access other files within the source tree
# (which might not be the same as the build tree), the corresponding
# python/testsuite directory within the source tree will be passed as an
# argument to each test script.
#
# 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.
#
# As an exception, when this program is distributed through (i) the
# App Store by Apple Inc.; (ii) the Mac App Store by Apple Inc.; or
# (iii) Google Play by Google Inc., then that store may impose any
# digital rights management, device limits and/or redistribution
# restrictions that are required by its terms of service.
#
# 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, see <https://www.gnu.org/licenses/>.

set -e

# To see the output, you need to run:
#     make test ARGS="-V"

executable=../regina-python
testdir='@BASH_CMAKE_SOURCE_DIR@/python/testsuite'
testoutdir=`mktemp -d -t regina.XXX`
pybind11_version='@REGINA_PYBIND11_VERSION@'

echo "---------------------------------------"
echo "Test suite for Regina's python bindings"
echo "---------------------------------------"
echo

if ! test -f ../../CMakeCache.txt -a -f "$executable"; then
	echo "ERROR: You do not appear to be within the python/testsuite directory"
	echo "       in the build tree.  This script must be run from directly"
	echo "       within the build tree (where you ran cmake)."
	echo "       Please change into the python/testsuite directory in the"
	echo "       build tree and try again."
	exit 1
fi

# Clobber environment variables that the user might already have set.
export REGINA_VERBOSITY=
export REGINA_PYLIBDIR=
export REGINA_HOME=

broken=
found=

# We need to loop through all files $testdir/*.test .
# Because $testdir may contain spaces, we use a slightly tortured loop
# with the source 'find' statement at the end (not the beginning).
# See http://mywiki.wooledge.org/BashFAQ/020 for details.
#
# Note that both "find -print0" and "sort -z" (which are part of our machinery
# to handle spaces correctly) are implemented in both GNU and BSD utilities.
#
while IFS= read -r -d $'\0' i; do
	found=1
	testname=`basename "$i"`
	expected="${i/.test/.out}"
	if [ ! -e "$expected" ]; then
		expected="$expected.v$pybind11_version"
	fi
	observed="$testoutdir/${testname/.test/.out}"
	filter="$testdir/${testname/.test/.filter}"

	# Run the test.
	#
	# Since we have "set -e", we need "&& dummy=" to prevent this line to just
	# exit the bash script when the test has non-zero exit code.
	# We use && as opposed to || in order to preserve the exit code from
	# the first command.
	#
	# The code that unsets TERM fixes an issue seen some years ago on
	# Fedora, where (as a result of a more exotic TERM setting) unprintable
	# characters were being dumped at the beginning of the python output.
	#
	if [ -e "$filter" ]; then
		echo -n "Running $testname (with filter) ... "
		TERM= PYTHONIOENCODING=utf8 \
			"$executable" "$i" "$testdir" | "$filter" > "$observed" 2>&1 && dummy=
	else
		echo -n "Running $testname ... "
		TERM= PYTHONIOENCODING=utf8 \
			"$executable" "$i" "$testdir" > "$observed" 2>&1 && dummy=
	fi

	# Catch exitcode.
	exitcode=$?

	# Branch based on exit code.
	if [ "$exitcode" -ne 0 ];  then
		echo "FAILED (exit code $exitcode)"
		echo "    Output was:"
		echo "        ..."
		tail -n 5 $observed | sed -e 's/^/        /'
		broken=1
	else
		if ! ( diff --strip-trailing-cr "$expected" "$observed" > /dev/null ); then
			echo "FAILED (output differs from expected)"
			echo "    Diff was:"
			diff --strip-trailing-cr -u \
				--label 'Expected output' --label 'Actual output' \
				"$expected" "$observed" | head -n200 | sed -e 's/^/        /'
			echo "        ..."
			broken=1
		else
			echo "ok"
			rm -f "$observed"
		fi
	fi
done < <(find "$testdir" -name "*.test" -print0 | sort -z)

if ! test -n "$found"; then
	echo "ERROR: No tests were found!"
	echo
	echo "       Please check your installation, and please ensure that"
	echo "       you are running this script from within the python/testsuite"
	echo "       directory of the build tree."
	echo
	echo "       Note that the build tree might not be the same as the source"
	echo "       tree.  The build tree is where you ran the configure script."
	exit 1
fi

if test -n "$broken"; then
	echo
	echo "One or more tests failed."
	echo "Please see the list above for details."
	echo
	echo "The full output file(s) produced by Regina are in the directory:"
	echo "    $testoutdir"
	exit 1
else
	rmdir "$testoutdir"
fi

echo
echo "All tests passed!"
exit 0