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"
20 while [ $# -gt 0 ] ; do
22 valgrind) valgrind="valgrind -q --leak-check=no";;
23 *) echo "Unknown argument $1"; exit 1;;
28 # If PCRE has been built in a directory other than the source directory, and
29 # this test is being run from "make check" as usual, then $(srcdir) will be
30 # set. If not, set it to the current directory. We then arrange to run the
31 # pcregrep command in the source directory so that the file names that appear
32 # in the output are always the same.
34 if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
38 # Check for the availability of UTF-8 support
40 ./pcretest -C | ./pcregrep "No UTF-8 support" >/dev/null
43 echo "---------------------------- Test 1 ------------------------------" >testtry
44 (cd $srcdir; $valgrind $pcregrep PATTERN ./testdata/grepinput) >>testtry
46 echo "---------------------------- Test 2 ------------------------------" >>testtry
47 (cd $srcdir; $valgrind $pcregrep '^PATTERN' ./testdata/grepinput) >>testtry
49 echo "---------------------------- Test 3 ------------------------------" >>testtry
50 (cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput) >>testtry
52 echo "---------------------------- Test 4 ------------------------------" >>testtry
53 (cd $srcdir; $valgrind $pcregrep -ic PATTERN ./testdata/grepinput) >>testtry
55 echo "---------------------------- Test 5 ------------------------------" >>testtry
56 (cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
58 echo "---------------------------- Test 6 ------------------------------" >>testtry
59 (cd $srcdir; $valgrind $pcregrep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
61 echo "---------------------------- Test 7 ------------------------------" >>testtry
62 (cd $srcdir; $valgrind $pcregrep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
64 echo "---------------------------- Test 8 ------------------------------" >>testtry
65 (cd $srcdir; $valgrind $pcregrep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
67 echo "---------------------------- Test 9 ------------------------------" >>testtry
68 (cd $srcdir; $valgrind $pcregrep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
69 echo "RC=$?" >>testtry
71 echo "---------------------------- Test 10 -----------------------------" >>testtry
72 (cd $srcdir; $valgrind $pcregrep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
73 echo "RC=$?" >>testtry
75 echo "---------------------------- Test 11 -----------------------------" >>testtry
76 (cd $srcdir; $valgrind $pcregrep -vn pattern ./testdata/grepinputx) >>testtry
78 echo "---------------------------- Test 12 -----------------------------" >>testtry
79 (cd $srcdir; $valgrind $pcregrep -ix pattern ./testdata/grepinputx) >>testtry
81 echo "---------------------------- Test 13 -----------------------------" >>testtry
82 (cd $srcdir; $valgrind $pcregrep -f./testdata/greplist ./testdata/grepinputx) >>testtry
84 echo "---------------------------- Test 14 -----------------------------" >>testtry
85 (cd $srcdir; $valgrind $pcregrep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtry
87 echo "---------------------------- Test 15 -----------------------------" >>testtry
88 (cd $srcdir; $valgrind $pcregrep 'abc^*' ./testdata/grepinput) 2>>testtry >>testtry
90 echo "---------------------------- Test 16 -----------------------------" >>testtry
91 (cd $srcdir; $valgrind $pcregrep abc ./testdata/grepinput ./testdata/nonexistfile) 2>>testtry >>testtry
93 echo "---------------------------- Test 17 -----------------------------" >>testtry
94 (cd $srcdir; $valgrind $pcregrep -M 'the\noutput' ./testdata/grepinput) >>testtry
96 echo "---------------------------- Test 18 -----------------------------" >>testtry
97 (cd $srcdir; $valgrind $pcregrep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtry
99 echo "---------------------------- Test 19 -----------------------------" >>testtry
100 (cd $srcdir; $valgrind $pcregrep -Mix 'Pattern' ./testdata/grepinputx) >>testtry
102 echo "---------------------------- Test 20 -----------------------------" >>testtry
103 (cd $srcdir; $valgrind $pcregrep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtry
105 echo "---------------------------- Test 21 -----------------------------" >>testtry
106 (cd $srcdir; $valgrind $pcregrep -nA3 'four' ./testdata/grepinputx) >>testtry
108 echo "---------------------------- Test 22 -----------------------------" >>testtry
109 (cd $srcdir; $valgrind $pcregrep -nB3 'four' ./testdata/grepinputx) >>testtry
111 echo "---------------------------- Test 23 -----------------------------" >>testtry
112 (cd $srcdir; $valgrind $pcregrep -C3 'four' ./testdata/grepinputx) >>testtry
114 echo "---------------------------- Test 24 -----------------------------" >>testtry
115 (cd $srcdir; $valgrind $pcregrep -A9 'four' ./testdata/grepinputx) >>testtry
117 echo "---------------------------- Test 25 -----------------------------" >>testtry
118 (cd $srcdir; $valgrind $pcregrep -nB9 'four' ./testdata/grepinputx) >>testtry
120 echo "---------------------------- Test 26 -----------------------------" >>testtry
121 (cd $srcdir; $valgrind $pcregrep -A9 -B9 'four' ./testdata/grepinputx) >>testtry
123 echo "---------------------------- Test 27 -----------------------------" >>testtry
124 (cd $srcdir; $valgrind $pcregrep -A10 'four' ./testdata/grepinputx) >>testtry
126 echo "---------------------------- Test 28 -----------------------------" >>testtry
127 (cd $srcdir; $valgrind $pcregrep -nB10 'four' ./testdata/grepinputx) >>testtry
129 echo "---------------------------- Test 29 -----------------------------" >>testtry
130 (cd $srcdir; $valgrind $pcregrep -C12 -B10 'four' ./testdata/grepinputx) >>testtry
132 echo "---------------------------- Test 30 -----------------------------" >>testtry
133 (cd $srcdir; $valgrind $pcregrep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
135 echo "---------------------------- Test 31 -----------------------------" >>testtry
136 (cd $srcdir; $valgrind $pcregrep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
138 echo "---------------------------- Test 32 -----------------------------" >>testtry
139 (cd $srcdir; $valgrind $pcregrep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtry
141 echo "---------------------------- Test 33 -----------------------------" >>testtry
142 (cd $srcdir; $valgrind $pcregrep 'fox' ./testdata/grepnonexist) >>testtry 2>&1
143 echo "RC=$?" >>testtry
145 echo "---------------------------- Test 34 -----------------------------" >>testtry
146 (cd $srcdir; $valgrind $pcregrep -s 'fox' ./testdata/grepnonexist) >>testtry 2>&1
147 echo "RC=$?" >>testtry
149 echo "---------------------------- Test 35 -----------------------------" >>testtry
150 (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --exclude_dir='^\.' 'fox' ./testdata) >>testtry
151 echo "RC=$?" >>testtry
153 echo "---------------------------- Test 36 -----------------------------" >>testtry
154 (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude 'grepinput$' --exclude_dir='^\.' 'fox' ./testdata | sort) >>testtry
155 echo "RC=$?" >>testtry
157 echo "---------------------------- Test 37 -----------------------------" >>testtry
158 (cd $srcdir; $valgrind $pcregrep '^(a+)*\d' ./testdata/grepinput) >>testtry 2>teststderr
159 echo "RC=$?" >>testtry
160 echo "======== STDERR ========" >>testtry
161 cat teststderr >>testtry
163 echo "---------------------------- Test 38 ------------------------------" >>testtry
164 (cd $srcdir; $valgrind $pcregrep '>\x00<' ./testdata/grepinput) >>testtry
166 echo "---------------------------- Test 39 ------------------------------" >>testtry
167 (cd $srcdir; $valgrind $pcregrep -A1 'before the binary zero' ./testdata/grepinput) >>testtry
169 echo "---------------------------- Test 40 ------------------------------" >>testtry
170 (cd $srcdir; $valgrind $pcregrep -B1 'after the binary zero' ./testdata/grepinput) >>testtry
172 echo "---------------------------- Test 41 ------------------------------" >>testtry
173 (cd $srcdir; $valgrind $pcregrep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtry
175 echo "---------------------------- Test 41 ------------------------------" >>testtry
176 (cd $srcdir; $valgrind $pcregrep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtry
178 echo "---------------------------- Test 42 ------------------------------" >>testtry
179 (cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtry
181 echo "---------------------------- Test 43 ------------------------------" >>testtry
182 (cd $srcdir; $valgrind $pcregrep -on -e before -e zero -e after ./testdata/grepinput) >>testtry
184 echo "---------------------------- Test 44 ------------------------------" >>testtry
185 (cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtry
187 echo "---------------------------- Test 45 ------------------------------" >>testtry
188 (cd $srcdir; $valgrind $pcregrep -e abc -e '(unclosed' ./testdata/grepinput) 2>>testtry >>testtry
190 echo "---------------------------- Test 46 ------------------------------" >>testtry
191 (cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
192 elephant" ./testdata/grepinput) >>testtry
194 echo "---------------------------- Test 47 ------------------------------" >>testtry
195 (cd $srcdir; $valgrind $pcregrep -F "AB.VE
196 elephant" ./testdata/grepinput) >>testtry
198 echo "---------------------------- Test 48 ------------------------------" >>testtry
199 (cd $srcdir; $valgrind $pcregrep -F -e DATA -e "AB.VE
200 elephant" ./testdata/grepinput) >>testtry
202 echo "---------------------------- Test 49 ------------------------------" >>testtry
203 (cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtry
205 echo "---------------------------- Test 50 ------------------------------" >>testtry
206 (cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtry
208 echo "---------------------------- Test 51 ------------------------------" >>testtry
209 (cd $srcdir; $valgrind $pcregrep --colour=always jumps ./testdata/grepinputv) >>testtry
211 echo "---------------------------- Test 52 ------------------------------" >>testtry
212 (cd $srcdir; $valgrind $pcregrep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
214 echo "---------------------------- Test 53 ------------------------------" >>testtry
215 (cd $srcdir; $valgrind $pcregrep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
217 # Now compare the results.
219 $cf $srcdir/testdata/grepoutput testtry
220 if [ $? != 0 ] ; then exit 1; fi
223 # These tests require UTF-8 support
225 if [ $utf8 -ne 0 ] ; then
226 echo "Testing pcregrep UTF-8 features"
228 echo "---------------------------- Test U1 ------------------------------" >testtry
229 (cd $srcdir; $valgrind $pcregrep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtry
231 echo "---------------------------- Test U2 ------------------------------" >>testtry
232 (cd $srcdir; $valgrind $pcregrep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtry
234 $cf $srcdir/testdata/grepoutput8 testtry
235 if [ $? != 0 ] ; then exit 1; fi
238 echo "Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library"
242 # We go to some contortions to try to ensure that the tests for the various
243 # newline settings will work in environments where the normal newline sequence
244 # is not \n. Do not use exported files, whose line endings might be changed.
245 # Instead, create an input file using printf so that its contents are exactly
246 # what we want. Note the messy fudge to get printf to write a string that
247 # starts with a hyphen.
249 echo "Testing pcregrep newline settings"
250 printf "abc\rdef\r\nghi\njkl" >testNinput
252 printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtry
253 $valgrind $pcregrep -n -N CR "^(abc|def|ghi|jkl)" testNinput >>testtry
255 printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtry
256 $valgrind $pcregrep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinput >>testtry
258 printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtry
259 pattern=`printf 'def\rjkl'`
260 $valgrind $pcregrep -n --newline=cr -F "$pattern" testNinput >>testtry
262 printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtry
263 pattern=`printf 'xxx\r\njkl'`
264 $valgrind $pcregrep -n --newline=crlf -F "$pattern" testNinput >>testtry
266 printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtry
267 $valgrind $pcregrep -n --newline=any "^(abc|def|ghi|jkl)" testNinput >>testtry
269 printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtry
270 $valgrind $pcregrep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinput >>testtry
272 $cf $srcdir/testdata/grepoutputN testtry
273 if [ $? != 0 ] ; then exit 1; fi