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