1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/pcre/RunTest Tue Jul 28 17:51:34 2009 -0400
1.3 @@ -0,0 +1,292 @@
1.4 +#! /bin/sh
1.5 +
1.6 +# Run PCRE tests.
1.7 +
1.8 +valgrind=
1.9 +
1.10 +# Set up a suitable "diff" command for comparison. Some systems
1.11 +# have a diff that lacks a -u option. Try to deal with this.
1.12 +
1.13 +if diff -u /dev/null /dev/null; then cf="diff -u"; else cf="diff"; fi
1.14 +
1.15 +# Find the test data
1.16 +
1.17 +testdata=testdata
1.18 +if [ -n "$srcdir" -a -d "$srcdir" ] ; then
1.19 + testdata="$srcdir/testdata"
1.20 +fi
1.21 +
1.22 +# Find which optional facilities are available
1.23 +
1.24 +case `./pcretest -C | ./pcregrep 'Internal link size'` in
1.25 + *2) link_size=2;;
1.26 + *3) link_size=3;;
1.27 + *4) link_size=4;;
1.28 + *) echo "Failed to find internal link size"; exit 1;;
1.29 +esac
1.30 +
1.31 +./pcretest -C | ./pcregrep 'No UTF-8 support' >/dev/null
1.32 +utf8=$?
1.33 +
1.34 +./pcretest -C | ./pcregrep 'No Unicode properties support' >/dev/null
1.35 +ucp=$?
1.36 +
1.37 +# Select which tests to run; for those that are explicitly requested, check
1.38 +# that the necessary optional facilities are available.
1.39 +
1.40 +do1=no
1.41 +do2=no
1.42 +do3=no
1.43 +do4=no
1.44 +do5=no
1.45 +do6=no
1.46 +do7=no
1.47 +do8=no
1.48 +do9=no
1.49 +do10=no
1.50 +
1.51 +while [ $# -gt 0 ] ; do
1.52 + case $1 in
1.53 + 1) do1=yes;;
1.54 + 2) do2=yes;;
1.55 + 3) do3=yes;;
1.56 + 4) do4=yes;;
1.57 + 5) do5=yes;;
1.58 + 6) do6=yes;;
1.59 + 7) do7=yes;;
1.60 + 8) do8=yes;;
1.61 + 9) do9=yes;;
1.62 + 10) do10=yes;;
1.63 + valgrind) valgrind="valgrind -q";;
1.64 + *) echo "Unknown test number $1"; exit 1;;
1.65 + esac
1.66 + shift
1.67 +done
1.68 +
1.69 +if [ $utf8 -eq 0 ] ; then
1.70 + if [ $do4 = yes ] ; then
1.71 + echo "Can't run test 4 because UTF-8 support is not configured"
1.72 + exit 1
1.73 + fi
1.74 + if [ $do5 = yes ] ; then
1.75 + echo "Can't run test 5 because UTF-8 support is not configured"
1.76 + exit 1
1.77 + fi
1.78 + if [ $do8 = yes ] ; then
1.79 + echo "Can't run test 8 because UTF-8 support is not configured"
1.80 + exit 1
1.81 + fi
1.82 +fi
1.83 +
1.84 +if [ $ucp -eq 0 ] ; then
1.85 + if [ $do6 = yes ] ; then
1.86 + echo "Can't run test 6 because Unicode property support is not configured"
1.87 + exit 1
1.88 + fi
1.89 + if [ $do9 = yes ] ; then
1.90 + echo "Can't run test 9 because Unicode property support is not configured"
1.91 + exit 1
1.92 + fi
1.93 + if [ $do10 = yes ] ; then
1.94 + echo "Can't run test 10 because Unicode property support is not configured"
1.95 + exit 1
1.96 + fi
1.97 +fi
1.98 +
1.99 +if [ $link_size -ne 2 ] ; then
1.100 + if [ $do10 = yes ] ; then
1.101 + echo "Can't run test 10 because the link size ($link_size) is not 2"
1.102 + exit 1
1.103 + fi
1.104 +fi
1.105 +
1.106 +# If no specific tests were requested, select all that are relevant.
1.107 +
1.108 +if [ $do1 = no -a $do2 = no -a $do3 = no -a $do4 = no -a \
1.109 + $do5 = no -a $do6 = no -a $do7 = no -a $do8 = no -a \
1.110 + $do9 = no -a $do10 = no ] ; then
1.111 + do1=yes
1.112 + do2=yes
1.113 + do3=yes
1.114 + if [ $utf8 -ne 0 ] ; then do4=yes; fi
1.115 + if [ $utf8 -ne 0 ] ; then do5=yes; fi
1.116 + if [ $utf8 -ne 0 -a $ucp -ne 0 ] ; then do6=yes; fi
1.117 + do7=yes
1.118 + if [ $utf8 -ne 0 ] ; then do8=yes; fi
1.119 + if [ $utf8 -ne 0 -a $ucp -ne 0 ] ; then do9=yes; fi
1.120 + if [ $link_size -eq 2 -a $ucp -ne 0 ] ; then do10=yes; fi
1.121 +fi
1.122 +
1.123 +# Show which release
1.124 +
1.125 +echo ""
1.126 +echo PCRE C library tests
1.127 +./pcretest /dev/null
1.128 +
1.129 +# Primary test, Perl-compatible
1.130 +
1.131 +if [ $do1 = yes ] ; then
1.132 + echo "Test 1: main functionality (Perl compatible)"
1.133 + $valgrind ./pcretest -q $testdata/testinput1 testtry
1.134 + if [ $? = 0 ] ; then
1.135 + $cf $testdata/testoutput1 testtry
1.136 + if [ $? != 0 ] ; then exit 1; fi
1.137 + else exit 1
1.138 + fi
1.139 + echo "OK"
1.140 +fi
1.141 +
1.142 +# PCRE tests that are not Perl-compatible - API & error tests, mostly
1.143 +
1.144 +if [ $do2 = yes ] ; then
1.145 + echo "Test 2: API and error handling (not Perl compatible)"
1.146 + $valgrind ./pcretest -q $testdata/testinput2 testtry
1.147 + if [ $? = 0 ] ; then
1.148 + $cf $testdata/testoutput2 testtry
1.149 + if [ $? != 0 ] ; then exit 1; fi
1.150 + else
1.151 + echo " "
1.152 + echo "** Test 2 requires a lot of stack. If it has crashed with a"
1.153 + echo "** segmentation fault, it may be that you do not have enough"
1.154 + echo "** stack available by default. Please see the 'pcrestack' man"
1.155 + echo "** page for a discussion of PCRE's stack usage."
1.156 + echo " "
1.157 + exit 1
1.158 + fi
1.159 + echo "OK"
1.160 +fi
1.161 +
1.162 +# Locale-specific tests, provided that either the "fr_FR" or the "french"
1.163 +# locale is available. The former is the Unix-like standard; the latter is
1.164 +# for Windows.
1.165 +
1.166 +if [ $do3 = yes ] ; then
1.167 + locale -a | grep '^fr_FR$' >/dev/null
1.168 + if [ $? -eq 0 ] ; then
1.169 + locale=fr_FR
1.170 + infile=$testdata/testinput3
1.171 + outfile=$testdata/testoutput3
1.172 + else
1.173 + locale -a | grep '^french$' >/dev/null
1.174 + if [ $? -eq 0 ] ; then
1.175 + locale=french
1.176 + sed 's/fr_FR/french/' $testdata/testinput3 >test3input
1.177 + sed 's/fr_FR/french/' $testdata/testoutput3 >test3output
1.178 + infile=test3input
1.179 + outfile=test3output
1.180 + else
1.181 + locale=
1.182 + fi
1.183 + fi
1.184 +
1.185 + if [ "$locale" != "" ] ; then
1.186 + echo "Test 3: locale-specific features (using '$locale' locale)"
1.187 + $valgrind ./pcretest -q $infile testtry
1.188 + if [ $? = 0 ] ; then
1.189 + $cf $outfile testtry
1.190 + if [ $? != 0 ] ; then
1.191 + echo " "
1.192 + echo "Locale test did not run entirely successfully."
1.193 + echo "This usually means that there is a problem with the locale"
1.194 + echo "settings rather than a bug in PCRE."
1.195 + else
1.196 + echo "OK"
1.197 + fi
1.198 + else exit 1
1.199 + fi
1.200 + else
1.201 + echo "Cannot test locale-specific features - neither the 'fr_FR' nor the"
1.202 + echo "'french' locale exists, or the \"locale\" command is not available"
1.203 + echo "to check for them."
1.204 + echo " "
1.205 + fi
1.206 +fi
1.207 +
1.208 +# Additional tests for UTF8 support
1.209 +
1.210 +if [ $do4 = yes ] ; then
1.211 + echo "Test 4: UTF-8 support (Perl compatible)"
1.212 + $valgrind ./pcretest -q $testdata/testinput4 testtry
1.213 + if [ $? = 0 ] ; then
1.214 + $cf $testdata/testoutput4 testtry
1.215 + if [ $? != 0 ] ; then exit 1; fi
1.216 + else exit 1
1.217 + fi
1.218 + echo "OK"
1.219 +fi
1.220 +
1.221 +if [ $do5 = yes ] ; then
1.222 + echo "Test 5: API and internals for UTF-8 support (not Perl compatible)"
1.223 + $valgrind ./pcretest -q $testdata/testinput5 testtry
1.224 + if [ $? = 0 ] ; then
1.225 + $cf $testdata/testoutput5 testtry
1.226 + if [ $? != 0 ] ; then exit 1; fi
1.227 + else exit 1
1.228 + fi
1.229 + echo "OK"
1.230 +fi
1.231 +
1.232 +if [ $do6 = yes ] ; then
1.233 + echo "Test 6: Unicode property support"
1.234 + $valgrind ./pcretest -q $testdata/testinput6 testtry
1.235 + if [ $? = 0 ] ; then
1.236 + $cf $testdata/testoutput6 testtry
1.237 + if [ $? != 0 ] ; then exit 1; fi
1.238 + else exit 1
1.239 + fi
1.240 + echo "OK"
1.241 +fi
1.242 +
1.243 +# Tests for DFA matching support
1.244 +
1.245 +if [ $do7 = yes ] ; then
1.246 + echo "Test 7: DFA matching"
1.247 + $valgrind ./pcretest -q -dfa $testdata/testinput7 testtry
1.248 + if [ $? = 0 ] ; then
1.249 + $cf $testdata/testoutput7 testtry
1.250 + if [ $? != 0 ] ; then exit 1; fi
1.251 + else exit 1
1.252 + fi
1.253 + echo "OK"
1.254 +fi
1.255 +
1.256 +if [ $do8 = yes ] ; then
1.257 + echo "Test 8: DFA matching with UTF-8"
1.258 + $valgrind ./pcretest -q -dfa $testdata/testinput8 testtry
1.259 + if [ $? = 0 ] ; then
1.260 + $cf $testdata/testoutput8 testtry
1.261 + if [ $? != 0 ] ; then exit 1; fi
1.262 + else exit 1
1.263 + fi
1.264 + echo "OK"
1.265 +fi
1.266 +
1.267 +if [ $do9 = yes ] ; then
1.268 + echo "Test 9: DFA matching with Unicode properties"
1.269 + $valgrind ./pcretest -q -dfa $testdata/testinput9 testtry
1.270 + if [ $? = 0 ] ; then
1.271 + $cf $testdata/testoutput9 testtry
1.272 + if [ $? != 0 ] ; then exit 1; fi
1.273 + else exit 1
1.274 + fi
1.275 + echo "OK"
1.276 +fi
1.277 +
1.278 +# Test of internal offsets and code sizes. This test is run only when there
1.279 +# is Unicode property support and the link size is 2. The actual tests are
1.280 +# mostly the same as in some of the above, but in this test we inspect some
1.281 +# offsets and sizes that require a known link size. This is a doublecheck for
1.282 +# the maintainer, just in case something changes unexpectely.
1.283 +
1.284 +if [ $do10 = yes ] ; then
1.285 + echo "Test 10: Internal offsets and code size tests"
1.286 + $valgrind ./pcretest -q $testdata/testinput10 testtry
1.287 + if [ $? = 0 ] ; then
1.288 + $cf $testdata/testoutput10 testtry
1.289 + if [ $? != 0 ] ; then exit 1; fi
1.290 + else exit 1
1.291 + fi
1.292 + echo "OK"
1.293 +fi
1.294 +
1.295 +# End