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