| 1 |
#! /bin/sh
|
| 2 |
|
| 3 |
# Run pcregrep tests. The assumption is that the PCRE tests check the library
|
| 4 |
# itself. What we are checking here is the file handling and options that are
|
| 5 |
# supported by pcregrep.
|
| 6 |
|
| 7 |
# Set the C locale, so that sort(1) behaves predictably.
|
| 8 |
LC_ALL=C
|
| 9 |
export LC_ALL
|
| 10 |
|
| 11 |
pcregrep=`pwd`/pcregrep
|
| 12 |
|
| 13 |
echo " "
|
| 14 |
echo "Testing pcregrep"
|
| 15 |
$pcregrep -V
|
| 16 |
|
| 17 |
valgrind=
|
| 18 |
while [ $# -gt 0 ] ; do
|
| 19 |
case $1 in
|
| 20 |
valgrind) valgrind="valgrind -q --leak-check=no";;
|
| 21 |
*) echo "Unknown argument $1"; exit 1;;
|
| 22 |
esac
|
| 23 |
shift
|
| 24 |
done
|
| 25 |
|
| 26 |
cf="diff -ub"
|
| 27 |
|
| 28 |
# Set up a suitable "diff" command for comparison. Some systems have a diff
|
| 29 |
# that lacks a -u option. Try to deal with this; better do the test for the -b
|
| 30 |
# option as well.
|
| 31 |
|
| 32 |
if diff -u /dev/null /dev/null; then
|
| 33 |
if diff -ub /dev/null /dev/null; then cf="diff -ub"; else cf="diff -u"; fi
|
| 34 |
else
|
| 35 |
if diff -b /dev/null /dev/null; then cf="diff -b"; else cf="diff"; fi
|
| 36 |
fi
|
| 37 |
|
| 38 |
# If PCRE has been built in a directory other than the source directory, and
|
| 39 |
# this test is being run from "make check" as usual, then $(srcdir) will be
|
| 40 |
# set. If not, set it to the current directory. We then arrange to run the
|
| 41 |
# pcregrep command in the source directory so that the file names that appear
|
| 42 |
# in the output are always the same.
|
| 43 |
|
| 44 |
if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
|
| 45 |
srcdir=.
|
| 46 |
fi
|
| 47 |
|
| 48 |
# Check for the availability of UTF-8 support
|
| 49 |
|
| 50 |
./pcretest -C | ./pcregrep "No UTF-8 support" >/dev/null
|
| 51 |
utf8=$?
|
| 52 |
|
| 53 |
echo "---------------------------- Test 1 ------------------------------" >testtry
|
| 54 |
(cd $srcdir; $valgrind $pcregrep PATTERN ./testdata/grepinput) >>testtry
|
| 55 |
|
| 56 |
echo "---------------------------- Test 2 ------------------------------" >>testtry
|
| 57 |
(cd $srcdir; $valgrind $pcregrep '^PATTERN' ./testdata/grepinput) >>testtry
|
| 58 |
|
| 59 |
echo "---------------------------- Test 3 ------------------------------" >>testtry
|
| 60 |
(cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput) >>testtry
|
| 61 |
|
| 62 |
echo "---------------------------- Test 4 ------------------------------" >>testtry
|
| 63 |
(cd $srcdir; $valgrind $pcregrep -ic PATTERN ./testdata/grepinput) >>testtry
|
| 64 |
|
| 65 |
echo "---------------------------- Test 5 ------------------------------" >>testtry
|
| 66 |
(cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 67 |
|
| 68 |
echo "---------------------------- Test 6 ------------------------------" >>testtry
|
| 69 |
(cd $srcdir; $valgrind $pcregrep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 70 |
|
| 71 |
echo "---------------------------- Test 7 ------------------------------" >>testtry
|
| 72 |
(cd $srcdir; $valgrind $pcregrep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 73 |
|
| 74 |
echo "---------------------------- Test 8 ------------------------------" >>testtry
|
| 75 |
(cd $srcdir; $valgrind $pcregrep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 76 |
|
| 77 |
echo "---------------------------- Test 9 ------------------------------" >>testtry
|
| 78 |
(cd $srcdir; $valgrind $pcregrep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 79 |
echo "RC=$?" >>testtry
|
| 80 |
|
| 81 |
echo "---------------------------- Test 10 -----------------------------" >>testtry
|
| 82 |
(cd $srcdir; $valgrind $pcregrep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 83 |
echo "RC=$?" >>testtry
|
| 84 |
|
| 85 |
echo "---------------------------- Test 11 -----------------------------" >>testtry
|
| 86 |
(cd $srcdir; $valgrind $pcregrep -vn pattern ./testdata/grepinputx) >>testtry
|
| 87 |
|
| 88 |
echo "---------------------------- Test 12 -----------------------------" >>testtry
|
| 89 |
(cd $srcdir; $valgrind $pcregrep -ix pattern ./testdata/grepinputx) >>testtry
|
| 90 |
|
| 91 |
echo "---------------------------- Test 13 -----------------------------" >>testtry
|
| 92 |
(cd $srcdir; $valgrind $pcregrep -f./testdata/greplist ./testdata/grepinputx) >>testtry
|
| 93 |
|
| 94 |
echo "---------------------------- Test 14 -----------------------------" >>testtry
|
| 95 |
(cd $srcdir; $valgrind $pcregrep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 96 |
|
| 97 |
echo "---------------------------- Test 15 -----------------------------" >>testtry
|
| 98 |
(cd $srcdir; $valgrind $pcregrep 'abc^*' ./testdata/grepinput) 2>>testtry >>testtry
|
| 99 |
|
| 100 |
echo "---------------------------- Test 16 -----------------------------" >>testtry
|
| 101 |
(cd $srcdir; $valgrind $pcregrep abc ./testdata/grepinput ./testdata/nonexistfile) 2>>testtry >>testtry
|
| 102 |
|
| 103 |
echo "---------------------------- Test 17 -----------------------------" >>testtry
|
| 104 |
(cd $srcdir; $valgrind $pcregrep -M 'the\noutput' ./testdata/grepinput) >>testtry
|
| 105 |
|
| 106 |
echo "---------------------------- Test 18 -----------------------------" >>testtry
|
| 107 |
(cd $srcdir; $valgrind $pcregrep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtry
|
| 108 |
|
| 109 |
echo "---------------------------- Test 19 -----------------------------" >>testtry
|
| 110 |
(cd $srcdir; $valgrind $pcregrep -Mix 'Pattern' ./testdata/grepinputx) >>testtry
|
| 111 |
|
| 112 |
echo "---------------------------- Test 20 -----------------------------" >>testtry
|
| 113 |
(cd $srcdir; $valgrind $pcregrep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtry
|
| 114 |
|
| 115 |
echo "---------------------------- Test 21 -----------------------------" >>testtry
|
| 116 |
(cd $srcdir; $valgrind $pcregrep -nA3 'four' ./testdata/grepinputx) >>testtry
|
| 117 |
|
| 118 |
echo "---------------------------- Test 22 -----------------------------" >>testtry
|
| 119 |
(cd $srcdir; $valgrind $pcregrep -nB3 'four' ./testdata/grepinputx) >>testtry
|
| 120 |
|
| 121 |
echo "---------------------------- Test 23 -----------------------------" >>testtry
|
| 122 |
(cd $srcdir; $valgrind $pcregrep -C3 'four' ./testdata/grepinputx) >>testtry
|
| 123 |
|
| 124 |
echo "---------------------------- Test 24 -----------------------------" >>testtry
|
| 125 |
(cd $srcdir; $valgrind $pcregrep -A9 'four' ./testdata/grepinputx) >>testtry
|
| 126 |
|
| 127 |
echo "---------------------------- Test 25 -----------------------------" >>testtry
|
| 128 |
(cd $srcdir; $valgrind $pcregrep -nB9 'four' ./testdata/grepinputx) >>testtry
|
| 129 |
|
| 130 |
echo "---------------------------- Test 26 -----------------------------" >>testtry
|
| 131 |
(cd $srcdir; $valgrind $pcregrep -A9 -B9 'four' ./testdata/grepinputx) >>testtry
|
| 132 |
|
| 133 |
echo "---------------------------- Test 27 -----------------------------" >>testtry
|
| 134 |
(cd $srcdir; $valgrind $pcregrep -A10 'four' ./testdata/grepinputx) >>testtry
|
| 135 |
|
| 136 |
echo "---------------------------- Test 28 -----------------------------" >>testtry
|
| 137 |
(cd $srcdir; $valgrind $pcregrep -nB10 'four' ./testdata/grepinputx) >>testtry
|
| 138 |
|
| 139 |
echo "---------------------------- Test 29 -----------------------------" >>testtry
|
| 140 |
(cd $srcdir; $valgrind $pcregrep -C12 -B10 'four' ./testdata/grepinputx) >>testtry
|
| 141 |
|
| 142 |
echo "---------------------------- Test 30 -----------------------------" >>testtry
|
| 143 |
(cd $srcdir; $valgrind $pcregrep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 144 |
|
| 145 |
echo "---------------------------- Test 31 -----------------------------" >>testtry
|
| 146 |
(cd $srcdir; $valgrind $pcregrep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 147 |
|
| 148 |
echo "---------------------------- Test 32 -----------------------------" >>testtry
|
| 149 |
(cd $srcdir; $valgrind $pcregrep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtry
|
| 150 |
|
| 151 |
echo "---------------------------- Test 33 -----------------------------" >>testtry
|
| 152 |
(cd $srcdir; $valgrind $pcregrep 'fox' ./testdata/grepnonexist) >>testtry 2>&1
|
| 153 |
echo "RC=$?" >>testtry
|
| 154 |
|
| 155 |
echo "---------------------------- Test 34 -----------------------------" >>testtry
|
| 156 |
(cd $srcdir; $valgrind $pcregrep -s 'fox' ./testdata/grepnonexist) >>testtry 2>&1
|
| 157 |
echo "RC=$?" >>testtry
|
| 158 |
|
| 159 |
echo "---------------------------- Test 35 -----------------------------" >>testtry
|
| 160 |
(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --exclude_dir='^\.' 'fox' ./testdata) >>testtry
|
| 161 |
echo "RC=$?" >>testtry
|
| 162 |
|
| 163 |
echo "---------------------------- Test 36 -----------------------------" >>testtry
|
| 164 |
(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude 'grepinput$' --exclude_dir='^\.' 'fox' ./testdata | sort) >>testtry
|
| 165 |
echo "RC=$?" >>testtry
|
| 166 |
|
| 167 |
echo "---------------------------- Test 37 -----------------------------" >>testtry
|
| 168 |
(cd $srcdir; $valgrind $pcregrep '^(a+)*\d' ./testdata/grepinput) >>testtry 2>teststderr
|
| 169 |
echo "RC=$?" >>testtry
|
| 170 |
echo "======== STDERR ========" >>testtry
|
| 171 |
cat teststderr >>testtry
|
| 172 |
|
| 173 |
echo "---------------------------- Test 38 ------------------------------" >>testtry
|
| 174 |
(cd $srcdir; $valgrind $pcregrep '>\x00<' ./testdata/grepinput) >>testtry
|
| 175 |
|
| 176 |
echo "---------------------------- Test 39 ------------------------------" >>testtry
|
| 177 |
(cd $srcdir; $valgrind $pcregrep -A1 'before the binary zero' ./testdata/grepinput) >>testtry
|
| 178 |
|
| 179 |
echo "---------------------------- Test 40 ------------------------------" >>testtry
|
| 180 |
(cd $srcdir; $valgrind $pcregrep -B1 'after the binary zero' ./testdata/grepinput) >>testtry
|
| 181 |
|
| 182 |
echo "---------------------------- Test 41 ------------------------------" >>testtry
|
| 183 |
(cd $srcdir; $valgrind $pcregrep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtry
|
| 184 |
|
| 185 |
echo "---------------------------- Test 41 ------------------------------" >>testtry
|
| 186 |
(cd $srcdir; $valgrind $pcregrep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtry
|
| 187 |
|
| 188 |
echo "---------------------------- Test 42 ------------------------------" >>testtry
|
| 189 |
(cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtry
|
| 190 |
|
| 191 |
echo "---------------------------- Test 43 ------------------------------" >>testtry
|
| 192 |
(cd $srcdir; $valgrind $pcregrep -on -e before -ezero -e after ./testdata/grepinput) >>testtry
|
| 193 |
|
| 194 |
echo "---------------------------- Test 44 ------------------------------" >>testtry
|
| 195 |
(cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtry
|
| 196 |
|
| 197 |
echo "---------------------------- Test 45 ------------------------------" >>testtry
|
| 198 |
(cd $srcdir; $valgrind $pcregrep -eabc -e '(unclosed' ./testdata/grepinput) 2>>testtry >>testtry
|
| 199 |
|
| 200 |
echo "---------------------------- Test 46 ------------------------------" >>testtry
|
| 201 |
(cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
|
| 202 |
elephant" ./testdata/grepinput) >>testtry
|
| 203 |
|
| 204 |
echo "---------------------------- Test 47 ------------------------------" >>testtry
|
| 205 |
(cd $srcdir; $valgrind $pcregrep -F "AB.VE
|
| 206 |
elephant" ./testdata/grepinput) >>testtry
|
| 207 |
|
| 208 |
echo "---------------------------- Test 48 ------------------------------" >>testtry
|
| 209 |
(cd $srcdir; $valgrind $pcregrep -F -e DATA -e "AB.VE
|
| 210 |
elephant" ./testdata/grepinput) >>testtry
|
| 211 |
|
| 212 |
echo "---------------------------- Test 49 ------------------------------" >>testtry
|
| 213 |
(cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtry
|
| 214 |
|
| 215 |
echo "---------------------------- Test 50 ------------------------------" >>testtry
|
| 216 |
(cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtry
|
| 217 |
|
| 218 |
echo "---------------------------- Test 51 ------------------------------" >>testtry
|
| 219 |
(cd $srcdir; $valgrind $pcregrep --colour=always jumps ./testdata/grepinputv) >>testtry
|
| 220 |
|
| 221 |
echo "---------------------------- Test 52 ------------------------------" >>testtry
|
| 222 |
(cd $srcdir; $valgrind $pcregrep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
|
| 223 |
|
| 224 |
echo "---------------------------- Test 53 ------------------------------" >>testtry
|
| 225 |
(cd $srcdir; $valgrind $pcregrep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
|
| 226 |
|
| 227 |
echo "---------------------------- Test 54 -----------------------------" >>testtry
|
| 228 |
(cd $srcdir; $valgrind $pcregrep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtry
|
| 229 |
|
| 230 |
echo "---------------------------- Test 55 -----------------------------" >>testtry
|
| 231 |
(cd $srcdir; $valgrind $pcregrep -c lazy ./testdata/grepinput*) >>testtry
|
| 232 |
|
| 233 |
echo "---------------------------- Test 56 -----------------------------" >>testtry
|
| 234 |
(cd $srcdir; $valgrind $pcregrep -c -l lazy ./testdata/grepinput*) >>testtry
|
| 235 |
|
| 236 |
echo "---------------------------- Test 57 -----------------------------" >>testtry
|
| 237 |
(cd $srcdir; $valgrind $pcregrep --regex=PATTERN ./testdata/grepinput) >>testtry
|
| 238 |
|
| 239 |
echo "---------------------------- Test 58 -----------------------------" >>testtry
|
| 240 |
(cd $srcdir; $valgrind $pcregrep --regexp=PATTERN ./testdata/grepinput) >>testtry
|
| 241 |
|
| 242 |
echo "---------------------------- Test 59 -----------------------------" >>testtry
|
| 243 |
(cd $srcdir; $valgrind $pcregrep --regex PATTERN ./testdata/grepinput) >>testtry
|
| 244 |
|
| 245 |
echo "---------------------------- Test 60 -----------------------------" >>testtry
|
| 246 |
(cd $srcdir; $valgrind $pcregrep --regexp PATTERN ./testdata/grepinput) >>testtry
|
| 247 |
|
| 248 |
echo "---------------------------- Test 61 -----------------------------" >>testtry
|
| 249 |
(cd $srcdir; $valgrind $pcregrep --match-limit=1000 -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtry 2>&1
|
| 250 |
|
| 251 |
echo "---------------------------- Test 62 -----------------------------" >>testtry
|
| 252 |
(cd $srcdir; $valgrind $pcregrep --recursion-limit=1000 -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtry 2>&1
|
| 253 |
|
| 254 |
# Now compare the results.
|
| 255 |
|
| 256 |
$cf $srcdir/testdata/grepoutput testtry
|
| 257 |
if [ $? != 0 ] ; then exit 1; fi
|
| 258 |
|
| 259 |
|
| 260 |
# These tests require UTF-8 support
|
| 261 |
|
| 262 |
if [ $utf8 -ne 0 ] ; then
|
| 263 |
echo "Testing pcregrep UTF-8 features"
|
| 264 |
|
| 265 |
echo "---------------------------- Test U1 ------------------------------" >testtry
|
| 266 |
(cd $srcdir; $valgrind $pcregrep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtry
|
| 267 |
|
| 268 |
echo "---------------------------- Test U2 ------------------------------" >>testtry
|
| 269 |
(cd $srcdir; $valgrind $pcregrep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtry
|
| 270 |
|
| 271 |
$cf $srcdir/testdata/grepoutput8 testtry
|
| 272 |
if [ $? != 0 ] ; then exit 1; fi
|
| 273 |
|
| 274 |
else
|
| 275 |
echo "Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library"
|
| 276 |
fi
|
| 277 |
|
| 278 |
|
| 279 |
# We go to some contortions to try to ensure that the tests for the various
|
| 280 |
# newline settings will work in environments where the normal newline sequence
|
| 281 |
# is not \n. Do not use exported files, whose line endings might be changed.
|
| 282 |
# Instead, create an input file using printf so that its contents are exactly
|
| 283 |
# what we want. Note the messy fudge to get printf to write a string that
|
| 284 |
# starts with a hyphen.
|
| 285 |
|
| 286 |
echo "Testing pcregrep newline settings"
|
| 287 |
printf "abc\rdef\r\nghi\njkl" >testNinput
|
| 288 |
|
| 289 |
printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtry
|
| 290 |
$valgrind $pcregrep -n -N CR "^(abc|def|ghi|jkl)" testNinput >>testtry
|
| 291 |
|
| 292 |
printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtry
|
| 293 |
$valgrind $pcregrep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinput >>testtry
|
| 294 |
|
| 295 |
printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtry
|
| 296 |
pattern=`printf 'def\rjkl'`
|
| 297 |
$valgrind $pcregrep -n --newline=cr -F "$pattern" testNinput >>testtry
|
| 298 |
|
| 299 |
printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtry
|
| 300 |
pattern=`printf 'xxx\r\njkl'`
|
| 301 |
$valgrind $pcregrep -n --newline=crlf -F "$pattern" testNinput >>testtry
|
| 302 |
|
| 303 |
printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtry
|
| 304 |
$valgrind $pcregrep -n --newline=any "^(abc|def|ghi|jkl)" testNinput >>testtry
|
| 305 |
|
| 306 |
printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtry
|
| 307 |
$valgrind $pcregrep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinput >>testtry
|
| 308 |
|
| 309 |
$cf $srcdir/testdata/grepoutputN testtry
|
| 310 |
if [ $? != 0 ] ; then exit 1; fi
|
| 311 |
|
| 312 |
exit 0
|
| 313 |
|
| 314 |
# End
|