1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/tools/pcre/RunGrepTest Tue Jul 28 17:51:34 2009 -0400
1.3 @@ -0,0 +1,280 @@
1.4 +#! /bin/sh
1.5 +
1.6 +# Run pcregrep tests. The assumption is that the PCRE tests check the library
1.7 +# itself. What we are checking here is the file handling and options that are
1.8 +# supported by pcregrep.
1.9 +
1.10 +# Set the C locale, so that sort(1) behaves predictably.
1.11 +LC_ALL=C
1.12 +export LC_ALL
1.13 +
1.14 +pcregrep=`pwd`/pcregrep
1.15 +
1.16 +echo " "
1.17 +echo "Testing pcregrep"
1.18 +$pcregrep -V
1.19 +
1.20 +cf="diff -ub"
1.21 +valgrind=
1.22 +
1.23 +while [ $# -gt 0 ] ; do
1.24 + case $1 in
1.25 + valgrind) valgrind="valgrind -q --leak-check=no";;
1.26 + *) echo "Unknown argument $1"; exit 1;;
1.27 + esac
1.28 + shift
1.29 +done
1.30 +
1.31 +# If PCRE has been built in a directory other than the source directory, and
1.32 +# this test is being run from "make check" as usual, then $(srcdir) will be
1.33 +# set. If not, set it to the current directory. We then arrange to run the
1.34 +# pcregrep command in the source directory so that the file names that appear
1.35 +# in the output are always the same.
1.36 +
1.37 +if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
1.38 + srcdir=.
1.39 +fi
1.40 +
1.41 +# Check for the availability of UTF-8 support
1.42 +
1.43 +./pcretest -C | ./pcregrep "No UTF-8 support" >/dev/null
1.44 +utf8=$?
1.45 +
1.46 +echo "---------------------------- Test 1 ------------------------------" >testtry
1.47 +(cd $srcdir; $valgrind $pcregrep PATTERN ./testdata/grepinput) >>testtry
1.48 +
1.49 +echo "---------------------------- Test 2 ------------------------------" >>testtry
1.50 +(cd $srcdir; $valgrind $pcregrep '^PATTERN' ./testdata/grepinput) >>testtry
1.51 +
1.52 +echo "---------------------------- Test 3 ------------------------------" >>testtry
1.53 +(cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput) >>testtry
1.54 +
1.55 +echo "---------------------------- Test 4 ------------------------------" >>testtry
1.56 +(cd $srcdir; $valgrind $pcregrep -ic PATTERN ./testdata/grepinput) >>testtry
1.57 +
1.58 +echo "---------------------------- Test 5 ------------------------------" >>testtry
1.59 +(cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.60 +
1.61 +echo "---------------------------- Test 6 ------------------------------" >>testtry
1.62 +(cd $srcdir; $valgrind $pcregrep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.63 +
1.64 +echo "---------------------------- Test 7 ------------------------------" >>testtry
1.65 +(cd $srcdir; $valgrind $pcregrep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.66 +
1.67 +echo "---------------------------- Test 8 ------------------------------" >>testtry
1.68 +(cd $srcdir; $valgrind $pcregrep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.69 +
1.70 +echo "---------------------------- Test 9 ------------------------------" >>testtry
1.71 +(cd $srcdir; $valgrind $pcregrep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.72 +echo "RC=$?" >>testtry
1.73 +
1.74 +echo "---------------------------- Test 10 -----------------------------" >>testtry
1.75 +(cd $srcdir; $valgrind $pcregrep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.76 +echo "RC=$?" >>testtry
1.77 +
1.78 +echo "---------------------------- Test 11 -----------------------------" >>testtry
1.79 +(cd $srcdir; $valgrind $pcregrep -vn pattern ./testdata/grepinputx) >>testtry
1.80 +
1.81 +echo "---------------------------- Test 12 -----------------------------" >>testtry
1.82 +(cd $srcdir; $valgrind $pcregrep -ix pattern ./testdata/grepinputx) >>testtry
1.83 +
1.84 +echo "---------------------------- Test 13 -----------------------------" >>testtry
1.85 +(cd $srcdir; $valgrind $pcregrep -f./testdata/greplist ./testdata/grepinputx) >>testtry
1.86 +
1.87 +echo "---------------------------- Test 14 -----------------------------" >>testtry
1.88 +(cd $srcdir; $valgrind $pcregrep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.89 +
1.90 +echo "---------------------------- Test 15 -----------------------------" >>testtry
1.91 +(cd $srcdir; $valgrind $pcregrep 'abc^*' ./testdata/grepinput) 2>>testtry >>testtry
1.92 +
1.93 +echo "---------------------------- Test 16 -----------------------------" >>testtry
1.94 +(cd $srcdir; $valgrind $pcregrep abc ./testdata/grepinput ./testdata/nonexistfile) 2>>testtry >>testtry
1.95 +
1.96 +echo "---------------------------- Test 17 -----------------------------" >>testtry
1.97 +(cd $srcdir; $valgrind $pcregrep -M 'the\noutput' ./testdata/grepinput) >>testtry
1.98 +
1.99 +echo "---------------------------- Test 18 -----------------------------" >>testtry
1.100 +(cd $srcdir; $valgrind $pcregrep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtry
1.101 +
1.102 +echo "---------------------------- Test 19 -----------------------------" >>testtry
1.103 +(cd $srcdir; $valgrind $pcregrep -Mix 'Pattern' ./testdata/grepinputx) >>testtry
1.104 +
1.105 +echo "---------------------------- Test 20 -----------------------------" >>testtry
1.106 +(cd $srcdir; $valgrind $pcregrep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtry
1.107 +
1.108 +echo "---------------------------- Test 21 -----------------------------" >>testtry
1.109 +(cd $srcdir; $valgrind $pcregrep -nA3 'four' ./testdata/grepinputx) >>testtry
1.110 +
1.111 +echo "---------------------------- Test 22 -----------------------------" >>testtry
1.112 +(cd $srcdir; $valgrind $pcregrep -nB3 'four' ./testdata/grepinputx) >>testtry
1.113 +
1.114 +echo "---------------------------- Test 23 -----------------------------" >>testtry
1.115 +(cd $srcdir; $valgrind $pcregrep -C3 'four' ./testdata/grepinputx) >>testtry
1.116 +
1.117 +echo "---------------------------- Test 24 -----------------------------" >>testtry
1.118 +(cd $srcdir; $valgrind $pcregrep -A9 'four' ./testdata/grepinputx) >>testtry
1.119 +
1.120 +echo "---------------------------- Test 25 -----------------------------" >>testtry
1.121 +(cd $srcdir; $valgrind $pcregrep -nB9 'four' ./testdata/grepinputx) >>testtry
1.122 +
1.123 +echo "---------------------------- Test 26 -----------------------------" >>testtry
1.124 +(cd $srcdir; $valgrind $pcregrep -A9 -B9 'four' ./testdata/grepinputx) >>testtry
1.125 +
1.126 +echo "---------------------------- Test 27 -----------------------------" >>testtry
1.127 +(cd $srcdir; $valgrind $pcregrep -A10 'four' ./testdata/grepinputx) >>testtry
1.128 +
1.129 +echo "---------------------------- Test 28 -----------------------------" >>testtry
1.130 +(cd $srcdir; $valgrind $pcregrep -nB10 'four' ./testdata/grepinputx) >>testtry
1.131 +
1.132 +echo "---------------------------- Test 29 -----------------------------" >>testtry
1.133 +(cd $srcdir; $valgrind $pcregrep -C12 -B10 'four' ./testdata/grepinputx) >>testtry
1.134 +
1.135 +echo "---------------------------- Test 30 -----------------------------" >>testtry
1.136 +(cd $srcdir; $valgrind $pcregrep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.137 +
1.138 +echo "---------------------------- Test 31 -----------------------------" >>testtry
1.139 +(cd $srcdir; $valgrind $pcregrep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.140 +
1.141 +echo "---------------------------- Test 32 -----------------------------" >>testtry
1.142 +(cd $srcdir; $valgrind $pcregrep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtry
1.143 +
1.144 +echo "---------------------------- Test 33 -----------------------------" >>testtry
1.145 +(cd $srcdir; $valgrind $pcregrep 'fox' ./testdata/grepnonexist) >>testtry 2>&1
1.146 +echo "RC=$?" >>testtry
1.147 +
1.148 +echo "---------------------------- Test 34 -----------------------------" >>testtry
1.149 +(cd $srcdir; $valgrind $pcregrep -s 'fox' ./testdata/grepnonexist) >>testtry 2>&1
1.150 +echo "RC=$?" >>testtry
1.151 +
1.152 +echo "---------------------------- Test 35 -----------------------------" >>testtry
1.153 +(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --exclude_dir='^\.' 'fox' ./testdata) >>testtry
1.154 +echo "RC=$?" >>testtry
1.155 +
1.156 +echo "---------------------------- Test 36 -----------------------------" >>testtry
1.157 +(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude 'grepinput$' --exclude_dir='^\.' 'fox' ./testdata | sort) >>testtry
1.158 +echo "RC=$?" >>testtry
1.159 +
1.160 +echo "---------------------------- Test 37 -----------------------------" >>testtry
1.161 +(cd $srcdir; $valgrind $pcregrep '^(a+)*\d' ./testdata/grepinput) >>testtry 2>teststderr
1.162 +echo "RC=$?" >>testtry
1.163 +echo "======== STDERR ========" >>testtry
1.164 +cat teststderr >>testtry
1.165 +
1.166 +echo "---------------------------- Test 38 ------------------------------" >>testtry
1.167 +(cd $srcdir; $valgrind $pcregrep '>\x00<' ./testdata/grepinput) >>testtry
1.168 +
1.169 +echo "---------------------------- Test 39 ------------------------------" >>testtry
1.170 +(cd $srcdir; $valgrind $pcregrep -A1 'before the binary zero' ./testdata/grepinput) >>testtry
1.171 +
1.172 +echo "---------------------------- Test 40 ------------------------------" >>testtry
1.173 +(cd $srcdir; $valgrind $pcregrep -B1 'after the binary zero' ./testdata/grepinput) >>testtry
1.174 +
1.175 +echo "---------------------------- Test 41 ------------------------------" >>testtry
1.176 +(cd $srcdir; $valgrind $pcregrep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtry
1.177 +
1.178 +echo "---------------------------- Test 41 ------------------------------" >>testtry
1.179 +(cd $srcdir; $valgrind $pcregrep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtry
1.180 +
1.181 +echo "---------------------------- Test 42 ------------------------------" >>testtry
1.182 +(cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtry
1.183 +
1.184 +echo "---------------------------- Test 43 ------------------------------" >>testtry
1.185 +(cd $srcdir; $valgrind $pcregrep -on -e before -e zero -e after ./testdata/grepinput) >>testtry
1.186 +
1.187 +echo "---------------------------- Test 44 ------------------------------" >>testtry
1.188 +(cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtry
1.189 +
1.190 +echo "---------------------------- Test 45 ------------------------------" >>testtry
1.191 +(cd $srcdir; $valgrind $pcregrep -e abc -e '(unclosed' ./testdata/grepinput) 2>>testtry >>testtry
1.192 +
1.193 +echo "---------------------------- Test 46 ------------------------------" >>testtry
1.194 +(cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
1.195 +elephant" ./testdata/grepinput) >>testtry
1.196 +
1.197 +echo "---------------------------- Test 47 ------------------------------" >>testtry
1.198 +(cd $srcdir; $valgrind $pcregrep -F "AB.VE
1.199 +elephant" ./testdata/grepinput) >>testtry
1.200 +
1.201 +echo "---------------------------- Test 48 ------------------------------" >>testtry
1.202 +(cd $srcdir; $valgrind $pcregrep -F -e DATA -e "AB.VE
1.203 +elephant" ./testdata/grepinput) >>testtry
1.204 +
1.205 +echo "---------------------------- Test 49 ------------------------------" >>testtry
1.206 +(cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtry
1.207 +
1.208 +echo "---------------------------- Test 50 ------------------------------" >>testtry
1.209 +(cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtry
1.210 +
1.211 +echo "---------------------------- Test 51 ------------------------------" >>testtry
1.212 +(cd $srcdir; $valgrind $pcregrep --colour=always jumps ./testdata/grepinputv) >>testtry
1.213 +
1.214 +echo "---------------------------- Test 52 ------------------------------" >>testtry
1.215 +(cd $srcdir; $valgrind $pcregrep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
1.216 +
1.217 +echo "---------------------------- Test 53 ------------------------------" >>testtry
1.218 +(cd $srcdir; $valgrind $pcregrep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
1.219 +
1.220 +echo "---------------------------- Test 54 -----------------------------" >>testtry
1.221 +(cd $srcdir; $valgrind $pcregrep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtry
1.222 +
1.223 +# Now compare the results.
1.224 +
1.225 +$cf $srcdir/testdata/grepoutput testtry
1.226 +if [ $? != 0 ] ; then exit 1; fi
1.227 +
1.228 +
1.229 +# These tests require UTF-8 support
1.230 +
1.231 +if [ $utf8 -ne 0 ] ; then
1.232 + echo "Testing pcregrep UTF-8 features"
1.233 +
1.234 + echo "---------------------------- Test U1 ------------------------------" >testtry
1.235 + (cd $srcdir; $valgrind $pcregrep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtry
1.236 +
1.237 + echo "---------------------------- Test U2 ------------------------------" >>testtry
1.238 + (cd $srcdir; $valgrind $pcregrep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtry
1.239 +
1.240 + $cf $srcdir/testdata/grepoutput8 testtry
1.241 + if [ $? != 0 ] ; then exit 1; fi
1.242 +
1.243 +else
1.244 + echo "Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library"
1.245 +fi
1.246 +
1.247 +
1.248 +# We go to some contortions to try to ensure that the tests for the various
1.249 +# newline settings will work in environments where the normal newline sequence
1.250 +# is not \n. Do not use exported files, whose line endings might be changed.
1.251 +# Instead, create an input file using printf so that its contents are exactly
1.252 +# what we want. Note the messy fudge to get printf to write a string that
1.253 +# starts with a hyphen.
1.254 +
1.255 +echo "Testing pcregrep newline settings"
1.256 +printf "abc\rdef\r\nghi\njkl" >testNinput
1.257 +
1.258 +printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtry
1.259 +$valgrind $pcregrep -n -N CR "^(abc|def|ghi|jkl)" testNinput >>testtry
1.260 +
1.261 +printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtry
1.262 +$valgrind $pcregrep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinput >>testtry
1.263 +
1.264 +printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtry
1.265 +pattern=`printf 'def\rjkl'`
1.266 +$valgrind $pcregrep -n --newline=cr -F "$pattern" testNinput >>testtry
1.267 +
1.268 +printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtry
1.269 +pattern=`printf 'xxx\r\njkl'`
1.270 +$valgrind $pcregrep -n --newline=crlf -F "$pattern" testNinput >>testtry
1.271 +
1.272 +printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtry
1.273 +$valgrind $pcregrep -n --newline=any "^(abc|def|ghi|jkl)" testNinput >>testtry
1.274 +
1.275 +printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtry
1.276 +$valgrind $pcregrep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinput >>testtry
1.277 +
1.278 +$cf $srcdir/testdata/grepoutputN testtry
1.279 +if [ $? != 0 ] ; then exit 1; fi
1.280 +
1.281 +exit 0
1.282 +
1.283 +# End