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. This script must be run in the build directory.
6
7# Set the C locale, so that sort(1) behaves predictably.
8
9LC_ALL=C
10export LC_ALL
11
12# Remove any non-default colouring and aliases that the caller may have set.
13
14unset PCREGREP_COLOUR PCREGREP_COLOR
15unset cp ls mv rm
16
17# Remember the current (build) directory, set the program to be tested, and
18# valgrind settings when requested.
19
20builddir=`pwd`
21pcregrep=$builddir/pcregrep
22
23valgrind=
24while [ $# -gt 0 ] ; do
25  case $1 in
26    valgrind) valgrind="valgrind -q --leak-check=no --smc-check=all";;
27    *) echo "RunGrepTest: Unknown argument $1"; exit 1;;
28  esac
29  shift
30done
31
32echo " "
33pcregrep_version=`$pcregrep -V`
34if [ "$valgrind" = "" ] ; then
35  echo "Testing $pcregrep_version"
36else
37  echo "Testing $pcregrep_version using valgrind"
38fi
39
40# Set up a suitable "diff" command for comparison. Some systems have a diff
41# that lacks a -u option. Try to deal with this; better do the test for the -b
42# option as well.
43
44cf="diff"
45diff -b  /dev/null /dev/null 2>/dev/null && cf="diff -b"
46diff -u  /dev/null /dev/null 2>/dev/null && cf="diff -u"
47diff -ub /dev/null /dev/null 2>/dev/null && cf="diff -ub"
48
49# If this test is being run from "make check", $srcdir will be set. If not, set
50# it to the current or parent directory, whichever one contains the test data.
51# Subsequently, we run most of the pcregrep tests in the source directory so
52# that the file names in the output are always the same.
53
54if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
55  if [ -d "./testdata" ] ; then
56    srcdir=.
57  elif [ -d "../testdata" ] ; then
58    srcdir=..
59  else
60    echo "Cannot find the testdata directory"
61    exit 1
62  fi
63fi
64
65# Check for the availability of UTF-8 support
66
67./pcretest -C utf >/dev/null
68utf8=$?
69
70echo "Testing pcregrep main features"
71
72echo "---------------------------- Test 1 ------------------------------" >testtrygrep
73(cd $srcdir; $valgrind $pcregrep PATTERN ./testdata/grepinput) >>testtrygrep
74echo "RC=$?" >>testtrygrep
75
76echo "---------------------------- Test 2 ------------------------------" >>testtrygrep
77(cd $srcdir; $valgrind $pcregrep '^PATTERN' ./testdata/grepinput) >>testtrygrep
78echo "RC=$?" >>testtrygrep
79
80echo "---------------------------- Test 3 ------------------------------" >>testtrygrep
81(cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput) >>testtrygrep
82echo "RC=$?" >>testtrygrep
83
84echo "---------------------------- Test 4 ------------------------------" >>testtrygrep
85(cd $srcdir; $valgrind $pcregrep -ic PATTERN ./testdata/grepinput) >>testtrygrep
86echo "RC=$?" >>testtrygrep
87
88echo "---------------------------- Test 5 ------------------------------" >>testtrygrep
89(cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
90echo "RC=$?" >>testtrygrep
91
92echo "---------------------------- Test 6 ------------------------------" >>testtrygrep
93(cd $srcdir; $valgrind $pcregrep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
94echo "RC=$?" >>testtrygrep
95
96echo "---------------------------- Test 7 ------------------------------" >>testtrygrep
97(cd $srcdir; $valgrind $pcregrep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
98echo "RC=$?" >>testtrygrep
99
100echo "---------------------------- Test 8 ------------------------------" >>testtrygrep
101(cd $srcdir; $valgrind $pcregrep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
102echo "RC=$?" >>testtrygrep
103
104echo "---------------------------- Test 9 ------------------------------" >>testtrygrep
105(cd $srcdir; $valgrind $pcregrep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
106echo "RC=$?" >>testtrygrep
107
108echo "---------------------------- Test 10 -----------------------------" >>testtrygrep
109(cd $srcdir; $valgrind $pcregrep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
110echo "RC=$?" >>testtrygrep
111
112echo "---------------------------- Test 11 -----------------------------" >>testtrygrep
113(cd $srcdir; $valgrind $pcregrep -vn pattern ./testdata/grepinputx) >>testtrygrep
114echo "RC=$?" >>testtrygrep
115
116echo "---------------------------- Test 12 -----------------------------" >>testtrygrep
117(cd $srcdir; $valgrind $pcregrep -ix pattern ./testdata/grepinputx) >>testtrygrep
118echo "RC=$?" >>testtrygrep
119
120echo "---------------------------- Test 13 -----------------------------" >>testtrygrep
121echo seventeen >testtemp1grep
122(cd $srcdir; $valgrind $pcregrep -f./testdata/greplist -f $builddir/testtemp1grep ./testdata/grepinputx) >>testtrygrep
123echo "RC=$?" >>testtrygrep
124
125echo "---------------------------- Test 14 -----------------------------" >>testtrygrep
126(cd $srcdir; $valgrind $pcregrep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
127echo "RC=$?" >>testtrygrep
128
129echo "---------------------------- Test 15 -----------------------------" >>testtrygrep
130(cd $srcdir; $valgrind $pcregrep 'abc^*' ./testdata/grepinput) 2>>testtrygrep >>testtrygrep
131echo "RC=$?" >>testtrygrep
132
133echo "---------------------------- Test 16 -----------------------------" >>testtrygrep
134(cd $srcdir; $valgrind $pcregrep abc ./testdata/grepinput ./testdata/nonexistfile) 2>>testtrygrep >>testtrygrep
135echo "RC=$?" >>testtrygrep
136
137echo "---------------------------- Test 17 -----------------------------" >>testtrygrep
138(cd $srcdir; $valgrind $pcregrep -M 'the\noutput' ./testdata/grepinput) >>testtrygrep
139echo "RC=$?" >>testtrygrep
140
141echo "---------------------------- Test 18 -----------------------------" >>testtrygrep
142(cd $srcdir; $valgrind $pcregrep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtrygrep
143echo "RC=$?" >>testtrygrep
144
145echo "---------------------------- Test 19 -----------------------------" >>testtrygrep
146(cd $srcdir; $valgrind $pcregrep -Mix 'Pattern' ./testdata/grepinputx) >>testtrygrep
147echo "RC=$?" >>testtrygrep
148
149echo "---------------------------- Test 20 -----------------------------" >>testtrygrep
150(cd $srcdir; $valgrind $pcregrep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtrygrep
151echo "RC=$?" >>testtrygrep
152
153echo "---------------------------- Test 21 -----------------------------" >>testtrygrep
154(cd $srcdir; $valgrind $pcregrep -nA3 'four' ./testdata/grepinputx) >>testtrygrep
155echo "RC=$?" >>testtrygrep
156
157echo "---------------------------- Test 22 -----------------------------" >>testtrygrep
158(cd $srcdir; $valgrind $pcregrep -nB3 'four' ./testdata/grepinputx) >>testtrygrep
159echo "RC=$?" >>testtrygrep
160
161echo "---------------------------- Test 23 -----------------------------" >>testtrygrep
162(cd $srcdir; $valgrind $pcregrep -C3 'four' ./testdata/grepinputx) >>testtrygrep
163echo "RC=$?" >>testtrygrep
164
165echo "---------------------------- Test 24 -----------------------------" >>testtrygrep
166(cd $srcdir; $valgrind $pcregrep -A9 'four' ./testdata/grepinputx) >>testtrygrep
167echo "RC=$?" >>testtrygrep
168
169echo "---------------------------- Test 25 -----------------------------" >>testtrygrep
170(cd $srcdir; $valgrind $pcregrep -nB9 'four' ./testdata/grepinputx) >>testtrygrep
171echo "RC=$?" >>testtrygrep
172
173echo "---------------------------- Test 26 -----------------------------" >>testtrygrep
174(cd $srcdir; $valgrind $pcregrep -A9 -B9 'four' ./testdata/grepinputx) >>testtrygrep
175echo "RC=$?" >>testtrygrep
176
177echo "---------------------------- Test 27 -----------------------------" >>testtrygrep
178(cd $srcdir; $valgrind $pcregrep -A10 'four' ./testdata/grepinputx) >>testtrygrep
179echo "RC=$?" >>testtrygrep
180
181echo "---------------------------- Test 28 -----------------------------" >>testtrygrep
182(cd $srcdir; $valgrind $pcregrep -nB10 'four' ./testdata/grepinputx) >>testtrygrep
183echo "RC=$?" >>testtrygrep
184
185echo "---------------------------- Test 29 -----------------------------" >>testtrygrep
186(cd $srcdir; $valgrind $pcregrep -C12 -B10 'four' ./testdata/grepinputx) >>testtrygrep
187echo "RC=$?" >>testtrygrep
188
189echo "---------------------------- Test 30 -----------------------------" >>testtrygrep
190(cd $srcdir; $valgrind $pcregrep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
191echo "RC=$?" >>testtrygrep
192
193echo "---------------------------- Test 31 -----------------------------" >>testtrygrep
194(cd $srcdir; $valgrind $pcregrep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
195echo "RC=$?" >>testtrygrep
196
197echo "---------------------------- Test 32 -----------------------------" >>testtrygrep
198(cd $srcdir; $valgrind $pcregrep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
199echo "RC=$?" >>testtrygrep
200
201echo "---------------------------- Test 33 -----------------------------" >>testtrygrep
202(cd $srcdir; $valgrind $pcregrep 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
203echo "RC=$?" >>testtrygrep
204
205echo "---------------------------- Test 34 -----------------------------" >>testtrygrep
206(cd $srcdir; $valgrind $pcregrep -s 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
207echo "RC=$?" >>testtrygrep
208
209echo "---------------------------- Test 35 -----------------------------" >>testtrygrep
210(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --include grepinput8 --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
211echo "RC=$?" >>testtrygrep
212
213echo "---------------------------- Test 36 -----------------------------" >>testtrygrep
214(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude 'grepinput$' --exclude=grepinput8 --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
215echo "RC=$?" >>testtrygrep
216
217echo "---------------------------- Test 37 -----------------------------" >>testtrygrep
218(cd $srcdir; $valgrind $pcregrep  '^(a+)*\d' ./testdata/grepinput) >>testtrygrep 2>teststderrgrep
219echo "RC=$?" >>testtrygrep
220echo "======== STDERR ========" >>testtrygrep
221cat teststderrgrep >>testtrygrep
222
223echo "---------------------------- Test 38 ------------------------------" >>testtrygrep
224(cd $srcdir; $valgrind $pcregrep '>\x00<' ./testdata/grepinput) >>testtrygrep
225echo "RC=$?" >>testtrygrep
226
227echo "---------------------------- Test 39 ------------------------------" >>testtrygrep
228(cd $srcdir; $valgrind $pcregrep -A1 'before the binary zero' ./testdata/grepinput) >>testtrygrep
229echo "RC=$?" >>testtrygrep
230
231echo "---------------------------- Test 40 ------------------------------" >>testtrygrep
232(cd $srcdir; $valgrind $pcregrep -B1 'after the binary zero' ./testdata/grepinput) >>testtrygrep
233echo "RC=$?" >>testtrygrep
234
235echo "---------------------------- Test 41 ------------------------------" >>testtrygrep
236(cd $srcdir; $valgrind $pcregrep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
237echo "RC=$?" >>testtrygrep
238
239echo "---------------------------- Test 42 ------------------------------" >>testtrygrep
240(cd $srcdir; $valgrind $pcregrep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
241echo "RC=$?" >>testtrygrep
242
243echo "---------------------------- Test 43 ------------------------------" >>testtrygrep
244(cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtrygrep
245echo "RC=$?" >>testtrygrep
246
247echo "---------------------------- Test 44 ------------------------------" >>testtrygrep
248(cd $srcdir; $valgrind $pcregrep -on -e before -ezero -e after ./testdata/grepinput) >>testtrygrep
249echo "RC=$?" >>testtrygrep
250
251echo "---------------------------- Test 45 ------------------------------" >>testtrygrep
252(cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtrygrep
253echo "RC=$?" >>testtrygrep
254
255echo "---------------------------- Test 46 ------------------------------" >>testtrygrep
256(cd $srcdir; $valgrind $pcregrep -eabc -e '(unclosed' ./testdata/grepinput) 2>>testtrygrep >>testtrygrep
257echo "RC=$?" >>testtrygrep
258
259echo "---------------------------- Test 47 ------------------------------" >>testtrygrep
260(cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
261elephant" ./testdata/grepinput) >>testtrygrep
262echo "RC=$?" >>testtrygrep
263
264echo "---------------------------- Test 48 ------------------------------" >>testtrygrep
265(cd $srcdir; $valgrind $pcregrep -F "AB.VE
266elephant" ./testdata/grepinput) >>testtrygrep
267echo "RC=$?" >>testtrygrep
268
269echo "---------------------------- Test 49 ------------------------------" >>testtrygrep
270(cd $srcdir; $valgrind $pcregrep -F -e DATA -e "AB.VE
271elephant" ./testdata/grepinput) >>testtrygrep
272echo "RC=$?" >>testtrygrep
273
274echo "---------------------------- Test 50 ------------------------------" >>testtrygrep
275(cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtrygrep
276echo "RC=$?" >>testtrygrep
277
278echo "---------------------------- Test 51 ------------------------------" >>testtrygrep
279(cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtrygrep
280echo "RC=$?" >>testtrygrep
281
282echo "---------------------------- Test 52 ------------------------------" >>testtrygrep
283(cd $srcdir; $valgrind $pcregrep --colour=always jumps ./testdata/grepinputv) >>testtrygrep
284echo "RC=$?" >>testtrygrep
285
286echo "---------------------------- Test 53 ------------------------------" >>testtrygrep
287(cd $srcdir; $valgrind $pcregrep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
288echo "RC=$?" >>testtrygrep
289
290echo "---------------------------- Test 54 ------------------------------" >>testtrygrep
291(cd $srcdir; $valgrind $pcregrep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
292echo "RC=$?" >>testtrygrep
293
294echo "---------------------------- Test 55 -----------------------------" >>testtrygrep
295(cd $srcdir; $valgrind $pcregrep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtrygrep
296echo "RC=$?" >>testtrygrep
297
298echo "---------------------------- Test 56 -----------------------------" >>testtrygrep
299(cd $srcdir; $valgrind $pcregrep -c lazy ./testdata/grepinput*) >>testtrygrep
300echo "RC=$?" >>testtrygrep
301
302echo "---------------------------- Test 57 -----------------------------" >>testtrygrep
303(cd $srcdir; $valgrind $pcregrep -c -l lazy ./testdata/grepinput*) >>testtrygrep
304echo "RC=$?" >>testtrygrep
305
306echo "---------------------------- Test 58 -----------------------------" >>testtrygrep
307(cd $srcdir; $valgrind $pcregrep --regex=PATTERN ./testdata/grepinput) >>testtrygrep
308echo "RC=$?" >>testtrygrep
309
310echo "---------------------------- Test 59 -----------------------------" >>testtrygrep
311(cd $srcdir; $valgrind $pcregrep --regexp=PATTERN ./testdata/grepinput) >>testtrygrep
312echo "RC=$?" >>testtrygrep
313
314echo "---------------------------- Test 60 -----------------------------" >>testtrygrep
315(cd $srcdir; $valgrind $pcregrep --regex PATTERN ./testdata/grepinput) >>testtrygrep
316echo "RC=$?" >>testtrygrep
317
318echo "---------------------------- Test 61 -----------------------------" >>testtrygrep
319(cd $srcdir; $valgrind $pcregrep --regexp PATTERN ./testdata/grepinput) >>testtrygrep
320echo "RC=$?" >>testtrygrep
321
322echo "---------------------------- Test 62 -----------------------------" >>testtrygrep
323(cd $srcdir; $valgrind $pcregrep --match-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
324echo "RC=$?" >>testtrygrep
325
326echo "---------------------------- Test 63 -----------------------------" >>testtrygrep
327(cd $srcdir; $valgrind $pcregrep --recursion-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
328echo "RC=$?" >>testtrygrep
329
330echo "---------------------------- Test 64 ------------------------------" >>testtrygrep
331(cd $srcdir; $valgrind $pcregrep -o1 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
332echo "RC=$?" >>testtrygrep
333
334echo "---------------------------- Test 65 ------------------------------" >>testtrygrep
335(cd $srcdir; $valgrind $pcregrep -o2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
336echo "RC=$?" >>testtrygrep
337
338echo "---------------------------- Test 66 ------------------------------" >>testtrygrep
339(cd $srcdir; $valgrind $pcregrep -o3 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
340echo "RC=$?" >>testtrygrep
341
342echo "---------------------------- Test 67 ------------------------------" >>testtrygrep
343(cd $srcdir; $valgrind $pcregrep -o12 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
344echo "RC=$?" >>testtrygrep
345
346echo "---------------------------- Test 68 ------------------------------" >>testtrygrep
347(cd $srcdir; $valgrind $pcregrep --only-matching=2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
348echo "RC=$?" >>testtrygrep
349
350echo "---------------------------- Test 69 -----------------------------" >>testtrygrep
351(cd $srcdir; $valgrind $pcregrep -vn --colour=always pattern ./testdata/grepinputx) >>testtrygrep
352echo "RC=$?" >>testtrygrep
353
354echo "---------------------------- Test 70 -----------------------------" >>testtrygrep
355(cd $srcdir; $valgrind $pcregrep --color=always -M "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
356echo "RC=$?" >>testtrygrep
357
358echo "---------------------------- Test 71 -----------------------------" >>testtrygrep
359(cd $srcdir; $valgrind $pcregrep -o "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
360echo "RC=$?" >>testtrygrep
361
362echo "---------------------------- Test 72 -----------------------------" >>testtrygrep
363(cd $srcdir; $valgrind $pcregrep --color=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
364echo "RC=$?" >>testtrygrep
365
366echo "---------------------------- Test 73 -----------------------------" >>testtrygrep
367(cd $srcdir; $valgrind $pcregrep -o --colour=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
368echo "RC=$?" >>testtrygrep
369
370echo "---------------------------- Test 74 -----------------------------" >>testtrygrep
371(cd $srcdir; $valgrind $pcregrep -o "^01|02|^03" ./testdata/grepinput) >>testtrygrep
372echo "RC=$?" >>testtrygrep
373
374echo "---------------------------- Test 75 -----------------------------" >>testtrygrep
375(cd $srcdir; $valgrind $pcregrep --color=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
376echo "RC=$?" >>testtrygrep
377
378echo "---------------------------- Test 76 -----------------------------" >>testtrygrep
379(cd $srcdir; $valgrind $pcregrep -o --colour=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
380echo "RC=$?" >>testtrygrep
381
382echo "---------------------------- Test 77 -----------------------------" >>testtrygrep
383(cd $srcdir; $valgrind $pcregrep -o "^01|^02|03" ./testdata/grepinput) >>testtrygrep
384echo "RC=$?" >>testtrygrep
385
386echo "---------------------------- Test 78 -----------------------------" >>testtrygrep
387(cd $srcdir; $valgrind $pcregrep --color=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
388echo "RC=$?" >>testtrygrep
389
390echo "---------------------------- Test 79 -----------------------------" >>testtrygrep
391(cd $srcdir; $valgrind $pcregrep -o --colour=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
392echo "RC=$?" >>testtrygrep
393
394echo "---------------------------- Test 80 -----------------------------" >>testtrygrep
395(cd $srcdir; $valgrind $pcregrep -o "\b01|\b02" ./testdata/grepinput) >>testtrygrep
396echo "RC=$?" >>testtrygrep
397
398echo "---------------------------- Test 81 -----------------------------" >>testtrygrep
399(cd $srcdir; $valgrind $pcregrep --color=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
400echo "RC=$?" >>testtrygrep
401
402echo "---------------------------- Test 82 -----------------------------" >>testtrygrep
403(cd $srcdir; $valgrind $pcregrep -o --colour=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
404echo "RC=$?" >>testtrygrep
405
406echo "---------------------------- Test 83 -----------------------------" >>testtrygrep
407(cd $srcdir; $valgrind $pcregrep --buffer-size=100 "^a" ./testdata/grepinput3) >>testtrygrep 2>&1
408echo "RC=$?" >>testtrygrep
409
410echo "---------------------------- Test 84 -----------------------------" >>testtrygrep
411echo testdata/grepinput3 >testtemp1grep
412(cd $srcdir; $valgrind $pcregrep --file-list ./testdata/grepfilelist --file-list $builddir/testtemp1grep "fox|complete|t7") >>testtrygrep 2>&1
413echo "RC=$?" >>testtrygrep
414
415echo "---------------------------- Test 85 -----------------------------" >>testtrygrep
416(cd $srcdir; $valgrind $pcregrep --file-list=./testdata/grepfilelist "dolor" ./testdata/grepinput3) >>testtrygrep 2>&1
417echo "RC=$?" >>testtrygrep
418
419echo "---------------------------- Test 86 -----------------------------" >>testtrygrep
420(cd $srcdir; $valgrind $pcregrep "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
421echo "RC=$?" >>testtrygrep
422
423echo "---------------------------- Test 87 -----------------------------" >>testtrygrep
424(cd $srcdir; $valgrind $pcregrep "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
425echo "RC=$?" >>testtrygrep
426
427echo "---------------------------- Test 88 -----------------------------" >>testtrygrep
428(cd $srcdir; $valgrind $pcregrep -v "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
429echo "RC=$?" >>testtrygrep
430
431echo "---------------------------- Test 89 -----------------------------" >>testtrygrep
432(cd $srcdir; $valgrind $pcregrep -I "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
433echo "RC=$?" >>testtrygrep
434
435echo "---------------------------- Test 90 -----------------------------" >>testtrygrep
436(cd $srcdir; $valgrind $pcregrep --binary-files=without-match "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
437echo "RC=$?" >>testtrygrep
438
439echo "---------------------------- Test 91 -----------------------------" >>testtrygrep
440(cd $srcdir; $valgrind $pcregrep -a "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
441echo "RC=$?" >>testtrygrep
442
443echo "---------------------------- Test 92 -----------------------------" >>testtrygrep
444(cd $srcdir; $valgrind $pcregrep --binary-files=text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
445echo "RC=$?" >>testtrygrep
446
447echo "---------------------------- Test 93 -----------------------------" >>testtrygrep
448(cd $srcdir; $valgrind $pcregrep --text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
449echo "RC=$?" >>testtrygrep
450
451echo "---------------------------- Test 94 -----------------------------" >>testtrygrep
452(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --include grepinput8 'fox' ./testdata/grepinput* | sort) >>testtrygrep
453echo "RC=$?" >>testtrygrep
454
455echo "---------------------------- Test 95 -----------------------------" >>testtrygrep
456(cd $srcdir; $valgrind $pcregrep --file-list ./testdata/grepfilelist --exclude grepinputv "fox|complete") >>testtrygrep 2>&1
457echo "RC=$?" >>testtrygrep
458
459echo "---------------------------- Test 96 -----------------------------" >>testtrygrep
460(cd $srcdir; $valgrind $pcregrep -L -r --include-dir=testdata --exclude '^(?!grepinput)' 'fox' ./test* | sort) >>testtrygrep
461echo "RC=$?" >>testtrygrep
462
463echo "---------------------------- Test 97 -----------------------------" >>testtrygrep
464echo "grepinput$" >testtemp1grep
465echo "grepinput8" >>testtemp1grep
466(cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
467echo "RC=$?" >>testtrygrep
468
469echo "---------------------------- Test 98 -----------------------------" >>testtrygrep
470echo "grepinput$" >testtemp1grep
471echo "grepinput8" >>testtemp1grep
472(cd $srcdir; $valgrind $pcregrep -L -r --exclude=grepinput3 --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
473echo "RC=$?" >>testtrygrep
474
475echo "---------------------------- Test 99 -----------------------------" >>testtrygrep
476echo "grepinput$" >testtemp1grep
477echo "grepinput8" >testtemp2grep
478(cd $srcdir; $valgrind $pcregrep -L -r --include grepinput --exclude-from $builddir/testtemp1grep --exclude-from=$builddir/testtemp2grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
479echo "RC=$?" >>testtrygrep
480
481echo "---------------------------- Test 100 ------------------------------" >>testtrygrep
482(cd $srcdir; $valgrind $pcregrep -Ho2 --only-matching=1 -o3 '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
483echo "RC=$?" >>testtrygrep
484
485echo "---------------------------- Test 101 ------------------------------" >>testtrygrep
486(cd $srcdir; $valgrind $pcregrep -o3 -Ho2 -o12 --only-matching=1 -o3 --colour=always --om-separator='|' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
487echo "RC=$?" >>testtrygrep
488
489echo "---------------------------- Test 102 -----------------------------" >>testtrygrep
490(cd $srcdir; $valgrind $pcregrep -n "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
491echo "RC=$?" >>testtrygrep
492
493echo "---------------------------- Test 103 -----------------------------" >>testtrygrep
494(cd $srcdir; $valgrind $pcregrep --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
495echo "RC=$?" >>testtrygrep
496
497echo "---------------------------- Test 104 -----------------------------" >>testtrygrep
498(cd $srcdir; $valgrind $pcregrep -n --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
499echo "RC=$?" >>testtrygrep
500
501echo "---------------------------- Test 105 -----------------------------" >>testtrygrep
502(cd $srcdir; $valgrind $pcregrep --colour=always "ipsum|" ./testdata/grepinput3) >>testtrygrep 2>&1
503echo "RC=$?" >>testtrygrep
504
505echo "---------------------------- Test 106 -----------------------------" >>testtrygrep
506(cd $srcdir; echo "a" | $valgrind $pcregrep -M "|a" ) >>testtrygrep 2>&1
507echo "RC=$?" >>testtrygrep
508
509echo "---------------------------- Test 107 -----------------------------" >>testtrygrep
510echo "a" >testtemp1grep
511echo "aaaaa" >>testtemp1grep
512(cd $srcdir; $valgrind $pcregrep  --line-offsets '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
513echo "RC=$?" >>testtrygrep
514
515echo "---------------------------- Test 108 ------------------------------" >>testtrygrep
516(cd $srcdir; $valgrind $pcregrep -lq PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
517echo "RC=$?" >>testtrygrep
518
519echo "---------------------------- Test 109 -----------------------------" >>testtrygrep
520(cd $srcdir; $valgrind $pcregrep -cq lazy ./testdata/grepinput*) >>testtrygrep
521echo "RC=$?" >>testtrygrep
522
523# Now compare the results.
524
525$cf $srcdir/testdata/grepoutput testtrygrep
526if [ $? != 0 ] ; then exit 1; fi
527
528
529# These tests require UTF-8 support
530
531if [ $utf8 -ne 0 ] ; then
532  echo "Testing pcregrep UTF-8 features"
533
534  echo "---------------------------- Test U1 ------------------------------" >testtrygrep
535  (cd $srcdir; $valgrind $pcregrep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtrygrep
536  echo "RC=$?" >>testtrygrep
537
538  echo "---------------------------- Test U2 ------------------------------" >>testtrygrep
539  (cd $srcdir; $valgrind $pcregrep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtrygrep
540  echo "RC=$?" >>testtrygrep
541
542  $cf $srcdir/testdata/grepoutput8 testtrygrep
543  if [ $? != 0 ] ; then exit 1; fi
544
545else
546  echo "Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library"
547fi
548
549
550# We go to some contortions to try to ensure that the tests for the various
551# newline settings will work in environments where the normal newline sequence
552# is not \n. Do not use exported files, whose line endings might be changed.
553# Instead, create an input file using printf so that its contents are exactly
554# what we want. Note the messy fudge to get printf to write a string that
555# starts with a hyphen. These tests are run in the build directory.
556
557echo "Testing pcregrep newline settings"
558printf "abc\rdef\r\nghi\njkl" >testNinputgrep
559
560printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtrygrep
561$valgrind $pcregrep -n -N CR "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
562
563printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtrygrep
564$valgrind $pcregrep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
565
566printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtrygrep
567pattern=`printf 'def\rjkl'`
568$valgrind $pcregrep -n --newline=cr -F "$pattern" testNinputgrep >>testtrygrep
569
570printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtrygrep
571$valgrind $pcregrep -n --newline=crlf -F -f $srcdir/testdata/greppatN4 testNinputgrep >>testtrygrep
572
573printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtrygrep
574$valgrind $pcregrep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
575
576printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtrygrep
577$valgrind $pcregrep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
578
579$cf $srcdir/testdata/grepoutputN testtrygrep
580if [ $? != 0 ] ; then exit 1; fi
581
582exit 0
583
584# End
585