github的一些开源项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

699 lines
34 KiB

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