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