/[pcre]/code/trunk/RunGrepTest
ViewVC logotype

Contents of /code/trunk/RunGrepTest

Parent Directory Parent Directory | Revision Log Revision Log


Revision 437 - (show annotations) (download)
Sun Sep 6 16:34:42 2009 UTC (5 years, 1 month ago) by ph10
File size: 14689 byte(s)
Add test for diff -u to RunGrepTest.

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 LC_ALL=C
9 export LC_ALL
10
11 pcregrep=`pwd`/pcregrep
12
13 echo " "
14 echo "Testing pcregrep"
15 $pcregrep -V
16
17 valgrind=
18 while [ $# -gt 0 ] ; do
19 case $1 in
20 valgrind) valgrind="valgrind -q --leak-check=no";;
21 *) echo "Unknown argument $1"; exit 1;;
22 esac
23 shift
24 done
25
26 cf="diff -ub"
27
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
30 # option as well.
31
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
34 else
35 if diff -b /dev/null /dev/null; then cf="diff -b"; else cf="diff"; fi
36 fi
37
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.
43
44 if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
45 srcdir=.
46 fi
47
48 # Check for the availability of UTF-8 support
49
50 ./pcretest -C | ./pcregrep "No UTF-8 support" >/dev/null
51 utf8=$?
52
53 echo "---------------------------- Test 1 ------------------------------" >testtry
54 (cd $srcdir; $valgrind $pcregrep PATTERN ./testdata/grepinput) >>testtry
55
56 echo "---------------------------- Test 2 ------------------------------" >>testtry
57 (cd $srcdir; $valgrind $pcregrep '^PATTERN' ./testdata/grepinput) >>testtry
58
59 echo "---------------------------- Test 3 ------------------------------" >>testtry
60 (cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput) >>testtry
61
62 echo "---------------------------- Test 4 ------------------------------" >>testtry
63 (cd $srcdir; $valgrind $pcregrep -ic PATTERN ./testdata/grepinput) >>testtry
64
65 echo "---------------------------- Test 5 ------------------------------" >>testtry
66 (cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
67
68 echo "---------------------------- Test 6 ------------------------------" >>testtry
69 (cd $srcdir; $valgrind $pcregrep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
70
71 echo "---------------------------- Test 7 ------------------------------" >>testtry
72 (cd $srcdir; $valgrind $pcregrep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
73
74 echo "---------------------------- Test 8 ------------------------------" >>testtry
75 (cd $srcdir; $valgrind $pcregrep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
76
77 echo "---------------------------- Test 9 ------------------------------" >>testtry
78 (cd $srcdir; $valgrind $pcregrep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
79 echo "RC=$?" >>testtry
80
81 echo "---------------------------- Test 10 -----------------------------" >>testtry
82 (cd $srcdir; $valgrind $pcregrep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtry
83 echo "RC=$?" >>testtry
84
85 echo "---------------------------- Test 11 -----------------------------" >>testtry
86 (cd $srcdir; $valgrind $pcregrep -vn pattern ./testdata/grepinputx) >>testtry
87
88 echo "---------------------------- Test 12 -----------------------------" >>testtry
89 (cd $srcdir; $valgrind $pcregrep -ix pattern ./testdata/grepinputx) >>testtry
90
91 echo "---------------------------- Test 13 -----------------------------" >>testtry
92 (cd $srcdir; $valgrind $pcregrep -f./testdata/greplist ./testdata/grepinputx) >>testtry
93
94 echo "---------------------------- Test 14 -----------------------------" >>testtry
95 (cd $srcdir; $valgrind $pcregrep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtry
96
97 echo "---------------------------- Test 15 -----------------------------" >>testtry
98 (cd $srcdir; $valgrind $pcregrep 'abc^*' ./testdata/grepinput) 2>>testtry >>testtry
99
100 echo "---------------------------- Test 16 -----------------------------" >>testtry
101 (cd $srcdir; $valgrind $pcregrep abc ./testdata/grepinput ./testdata/nonexistfile) 2>>testtry >>testtry
102
103 echo "---------------------------- Test 17 -----------------------------" >>testtry
104 (cd $srcdir; $valgrind $pcregrep -M 'the\noutput' ./testdata/grepinput) >>testtry
105
106 echo "---------------------------- Test 18 -----------------------------" >>testtry
107 (cd $srcdir; $valgrind $pcregrep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtry
108
109 echo "---------------------------- Test 19 -----------------------------" >>testtry
110 (cd $srcdir; $valgrind $pcregrep -Mix 'Pattern' ./testdata/grepinputx) >>testtry
111
112 echo "---------------------------- Test 20 -----------------------------" >>testtry
113 (cd $srcdir; $valgrind $pcregrep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtry
114
115 echo "---------------------------- Test 21 -----------------------------" >>testtry
116 (cd $srcdir; $valgrind $pcregrep -nA3 'four' ./testdata/grepinputx) >>testtry
117
118 echo "---------------------------- Test 22 -----------------------------" >>testtry
119 (cd $srcdir; $valgrind $pcregrep -nB3 'four' ./testdata/grepinputx) >>testtry
120
121 echo "---------------------------- Test 23 -----------------------------" >>testtry
122 (cd $srcdir; $valgrind $pcregrep -C3 'four' ./testdata/grepinputx) >>testtry
123
124 echo "---------------------------- Test 24 -----------------------------" >>testtry
125 (cd $srcdir; $valgrind $pcregrep -A9 'four' ./testdata/grepinputx) >>testtry
126
127 echo "---------------------------- Test 25 -----------------------------" >>testtry
128 (cd $srcdir; $valgrind $pcregrep -nB9 'four' ./testdata/grepinputx) >>testtry
129
130 echo "---------------------------- Test 26 -----------------------------" >>testtry
131 (cd $srcdir; $valgrind $pcregrep -A9 -B9 'four' ./testdata/grepinputx) >>testtry
132
133 echo "---------------------------- Test 27 -----------------------------" >>testtry
134 (cd $srcdir; $valgrind $pcregrep -A10 'four' ./testdata/grepinputx) >>testtry
135
136 echo "---------------------------- Test 28 -----------------------------" >>testtry
137 (cd $srcdir; $valgrind $pcregrep -nB10 'four' ./testdata/grepinputx) >>testtry
138
139 echo "---------------------------- Test 29 -----------------------------" >>testtry
140 (cd $srcdir; $valgrind $pcregrep -C12 -B10 'four' ./testdata/grepinputx) >>testtry
141
142 echo "---------------------------- Test 30 -----------------------------" >>testtry
143 (cd $srcdir; $valgrind $pcregrep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
144
145 echo "---------------------------- Test 31 -----------------------------" >>testtry
146 (cd $srcdir; $valgrind $pcregrep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtry
147
148 echo "---------------------------- Test 32 -----------------------------" >>testtry
149 (cd $srcdir; $valgrind $pcregrep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtry
150
151 echo "---------------------------- Test 33 -----------------------------" >>testtry
152 (cd $srcdir; $valgrind $pcregrep 'fox' ./testdata/grepnonexist) >>testtry 2>&1
153 echo "RC=$?" >>testtry
154
155 echo "---------------------------- Test 34 -----------------------------" >>testtry
156 (cd $srcdir; $valgrind $pcregrep -s 'fox' ./testdata/grepnonexist) >>testtry 2>&1
157 echo "RC=$?" >>testtry
158
159 echo "---------------------------- Test 35 -----------------------------" >>testtry
160 (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --exclude_dir='^\.' 'fox' ./testdata) >>testtry
161 echo "RC=$?" >>testtry
162
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
166
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
172
173 echo "---------------------------- Test 38 ------------------------------" >>testtry
174 (cd $srcdir; $valgrind $pcregrep '>\x00<' ./testdata/grepinput) >>testtry
175
176 echo "---------------------------- Test 39 ------------------------------" >>testtry
177 (cd $srcdir; $valgrind $pcregrep -A1 'before the binary zero' ./testdata/grepinput) >>testtry
178
179 echo "---------------------------- Test 40 ------------------------------" >>testtry
180 (cd $srcdir; $valgrind $pcregrep -B1 'after the binary zero' ./testdata/grepinput) >>testtry
181
182 echo "---------------------------- Test 41 ------------------------------" >>testtry
183 (cd $srcdir; $valgrind $pcregrep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtry
184
185 echo "---------------------------- Test 41 ------------------------------" >>testtry
186 (cd $srcdir; $valgrind $pcregrep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtry
187
188 echo "---------------------------- Test 42 ------------------------------" >>testtry
189 (cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtry
190
191 echo "---------------------------- Test 43 ------------------------------" >>testtry
192 (cd $srcdir; $valgrind $pcregrep -on -e before -ezero -e after ./testdata/grepinput) >>testtry
193
194 echo "---------------------------- Test 44 ------------------------------" >>testtry
195 (cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtry
196
197 echo "---------------------------- Test 45 ------------------------------" >>testtry
198 (cd $srcdir; $valgrind $pcregrep -eabc -e '(unclosed' ./testdata/grepinput) 2>>testtry >>testtry
199
200 echo "---------------------------- Test 46 ------------------------------" >>testtry
201 (cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
202 elephant" ./testdata/grepinput) >>testtry
203
204 echo "---------------------------- Test 47 ------------------------------" >>testtry
205 (cd $srcdir; $valgrind $pcregrep -F "AB.VE
206 elephant" ./testdata/grepinput) >>testtry
207
208 echo "---------------------------- Test 48 ------------------------------" >>testtry
209 (cd $srcdir; $valgrind $pcregrep -F -e DATA -e "AB.VE
210 elephant" ./testdata/grepinput) >>testtry
211
212 echo "---------------------------- Test 49 ------------------------------" >>testtry
213 (cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtry
214
215 echo "---------------------------- Test 50 ------------------------------" >>testtry
216 (cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtry
217
218 echo "---------------------------- Test 51 ------------------------------" >>testtry
219 (cd $srcdir; $valgrind $pcregrep --colour=always jumps ./testdata/grepinputv) >>testtry
220
221 echo "---------------------------- Test 52 ------------------------------" >>testtry
222 (cd $srcdir; $valgrind $pcregrep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
223
224 echo "---------------------------- Test 53 ------------------------------" >>testtry
225 (cd $srcdir; $valgrind $pcregrep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtry
226
227 echo "---------------------------- Test 54 -----------------------------" >>testtry
228 (cd $srcdir; $valgrind $pcregrep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtry
229
230 echo "---------------------------- Test 55 -----------------------------" >>testtry
231 (cd $srcdir; $valgrind $pcregrep -c lazy ./testdata/grepinput*) >>testtry
232
233 echo "---------------------------- Test 56 -----------------------------" >>testtry
234 (cd $srcdir; $valgrind $pcregrep -c -l lazy ./testdata/grepinput*) >>testtry
235
236 echo "---------------------------- Test 57 -----------------------------" >>testtry
237 (cd $srcdir; $valgrind $pcregrep --regex=PATTERN ./testdata/grepinput) >>testtry
238
239 echo "---------------------------- Test 58 -----------------------------" >>testtry
240 (cd $srcdir; $valgrind $pcregrep --regexp=PATTERN ./testdata/grepinput) >>testtry
241
242 echo "---------------------------- Test 59 -----------------------------" >>testtry
243 (cd $srcdir; $valgrind $pcregrep --regex PATTERN ./testdata/grepinput) >>testtry
244
245 echo "---------------------------- Test 60 -----------------------------" >>testtry
246 (cd $srcdir; $valgrind $pcregrep --regexp PATTERN ./testdata/grepinput) >>testtry
247
248 # Now compare the results.
249
250 $cf $srcdir/testdata/grepoutput testtry
251 if [ $? != 0 ] ; then exit 1; fi
252
253
254 # These tests require UTF-8 support
255
256 if [ $utf8 -ne 0 ] ; then
257 echo "Testing pcregrep UTF-8 features"
258
259 echo "---------------------------- Test U1 ------------------------------" >testtry
260 (cd $srcdir; $valgrind $pcregrep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtry
261
262 echo "---------------------------- Test U2 ------------------------------" >>testtry
263 (cd $srcdir; $valgrind $pcregrep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtry
264
265 $cf $srcdir/testdata/grepoutput8 testtry
266 if [ $? != 0 ] ; then exit 1; fi
267
268 else
269 echo "Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library"
270 fi
271
272
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.
279
280 echo "Testing pcregrep newline settings"
281 printf "abc\rdef\r\nghi\njkl" >testNinput
282
283 printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtry
284 $valgrind $pcregrep -n -N CR "^(abc|def|ghi|jkl)" testNinput >>testtry
285
286 printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtry
287 $valgrind $pcregrep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinput >>testtry
288
289 printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtry
290 pattern=`printf 'def\rjkl'`
291 $valgrind $pcregrep -n --newline=cr -F "$pattern" testNinput >>testtry
292
293 printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtry
294 pattern=`printf 'xxx\r\njkl'`
295 $valgrind $pcregrep -n --newline=crlf -F "$pattern" testNinput >>testtry
296
297 printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtry
298 $valgrind $pcregrep -n --newline=any "^(abc|def|ghi|jkl)" testNinput >>testtry
299
300 printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtry
301 $valgrind $pcregrep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinput >>testtry
302
303 $cf $srcdir/testdata/grepoutputN testtry
304 if [ $? != 0 ] ; then exit 1; fi
305
306 exit 0
307
308 # End

Properties

Name Value
svn:executable *
svn:keywords "Author Date Id Revision Url"

webmaster@exim.org
ViewVC Help
Powered by ViewVC 1.1.12