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