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