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.

1067 lines
53 KiB

  1. #! /bin/sh
  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. # CODING CONVENTIONS:
  6. # * Put printf arguments in single, not double quotes to avoid unwanted
  7. # escaping.
  8. # * Use \0 for binary zero in printf, not \x0, for the benefit of older
  9. # versions (and use octal for other special values).
  10. # Set the C locale, so that sort(1) behaves predictably.
  11. LC_ALL=C
  12. export LC_ALL
  13. # Remove any non-default colouring and aliases that the caller may have set.
  14. unset PCRE2GREP_COLOUR PCRE2GREP_COLOR PCREGREP_COLOUR PCREGREP_COLOR
  15. unset GREP_COLOR GREP_COLORS
  16. unset cp ls mv rm
  17. # Remember the current (build) directory, set the program to be tested, and
  18. # valgrind settings when requested.
  19. builddir=`pwd`
  20. pcre2grep=$builddir/pcre2grep
  21. pcre2test=$builddir/pcre2test
  22. if [ ! -x $pcre2grep ] ; then
  23. echo "** $pcre2grep does not exist or is not executable."
  24. exit 1
  25. fi
  26. if [ ! -x $pcre2test ] ; then
  27. echo "** $pcre2test does not exist or is not executable."
  28. exit 1
  29. fi
  30. valgrind=
  31. while [ $# -gt 0 ] ; do
  32. case $1 in
  33. valgrind) valgrind="valgrind -q --leak-check=no --smc-check=all-non-file";;
  34. *) echo "RunGrepTest: Unknown argument $1"; exit 1;;
  35. esac
  36. shift
  37. done
  38. vjs=
  39. pcre2grep_version=`$pcre2grep -V`
  40. if [ "$valgrind" = "" ] ; then
  41. echo "Testing $pcre2grep_version"
  42. else
  43. echo "Testing $pcre2grep_version using valgrind"
  44. $pcre2test -C jit >/dev/null
  45. if [ $? -ne 0 ]; then
  46. vjs="--suppressions=./testdata/valgrind-jit.supp"
  47. fi
  48. fi
  49. # Set up a suitable "diff" command for comparison. Some systems have a diff
  50. # that lacks a -u option. Try to deal with this; better do the test for the -b
  51. # option as well.
  52. cf="diff"
  53. diff -b /dev/null /dev/null 2>/dev/null && cf="diff -b"
  54. diff -u /dev/null /dev/null 2>/dev/null && cf="diff -u"
  55. diff -ub /dev/null /dev/null 2>/dev/null && cf="diff -ub"
  56. # Add a -a (always treat as text) if available. This was added in an attempt
  57. # to get more detail from an Alpine Linux test failure on GitHub.
  58. $cf -a /dev/null /dev/null 2>/dev/null && cf="$cf -a"
  59. # Some tests involve NUL characters. It seems impossible to handle them easily
  60. # in many operating systems. An earlier version of this script used sed to
  61. # translate NUL into the string ZERO, but this didn't work on Solaris (aka
  62. # SunOS), where the version of sed explicitly doesn't like them, and also MacOS
  63. # (Darwin), OpenBSD, FreeBSD, NetBSD, and some Linux distributions like Alpine,
  64. # even when using GNU sed. A user suggested using tr instead, which
  65. # necessitates translating to a single character. However, on (some versions
  66. # of?) Solaris, the normal "tr" cannot handle binary zeros, but if
  67. # /usr/xpg4/bin/tr is available, it can do so, so test for that.
  68. if [ -x /usr/xpg4/bin/tr ] ; then
  69. tr=/usr/xpg4/bin/tr
  70. else
  71. tr=tr
  72. fi
  73. # If this test is being run from "make check", $srcdir will be set. If not, set
  74. # it to the current or parent directory, whichever one contains the test data.
  75. # Subsequently, we run most of the pcre2grep tests in the source directory so
  76. # that the file names in the output are always the same.
  77. if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
  78. if [ -d "./testdata" ] ; then
  79. srcdir=.
  80. elif [ -d "../testdata" ] ; then
  81. srcdir=..
  82. else
  83. echo "Cannot find the testdata directory"
  84. exit 1
  85. fi
  86. fi
  87. # Check for the availability of UTF-8 support
  88. $pcre2test -C unicode >/dev/null
  89. utf8=$?
  90. # Check default newline convention. If it does not include LF, force LF.
  91. nl=`$pcre2test -C newline`
  92. if [ "$nl" != "LF" -a "$nl" != "ANY" -a "$nl" != "ANYCRLF" ]; then
  93. pcre2grep="$pcre2grep -N LF"
  94. echo "Default newline setting forced to LF"
  95. fi
  96. # ------ Function to run and check a special pcre2grep arguments test -------
  97. checkspecial()
  98. {
  99. $valgrind $pcre2grep $1 >>testtrygrep 2>&1
  100. if [ $? -ne $2 ] ; then
  101. echo "** pcre2grep $1 failed - check testtrygrep"
  102. exit 1
  103. fi
  104. }
  105. # ------ Normal tests ------
  106. echo "Testing pcre2grep main features"
  107. echo "---------------------------- Test 1 ------------------------------" >testtrygrep
  108. (cd $srcdir; $valgrind $vjs $pcre2grep PATTERN ./testdata/grepinput) >>testtrygrep
  109. echo "RC=$?" >>testtrygrep
  110. echo "---------------------------- Test 2 ------------------------------" >>testtrygrep
  111. (cd $srcdir; $valgrind $vjs $pcre2grep '^PATTERN' ./testdata/grepinput) >>testtrygrep
  112. echo "RC=$?" >>testtrygrep
  113. echo "---------------------------- Test 3 ------------------------------" >>testtrygrep
  114. (cd $srcdir; $valgrind $vjs $pcre2grep -in PATTERN ./testdata/grepinput) >>testtrygrep
  115. echo "RC=$?" >>testtrygrep
  116. echo "---------------------------- Test 4 ------------------------------" >>testtrygrep
  117. (cd $srcdir; $valgrind $vjs $pcre2grep -ic PATTERN ./testdata/grepinput) >>testtrygrep
  118. echo "RC=$?" >>testtrygrep
  119. echo "---------------------------- Test 5 ------------------------------" >>testtrygrep
  120. (cd $srcdir; $valgrind $vjs $pcre2grep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  121. echo "RC=$?" >>testtrygrep
  122. echo "---------------------------- Test 6 ------------------------------" >>testtrygrep
  123. (cd $srcdir; $valgrind $vjs $pcre2grep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  124. echo "RC=$?" >>testtrygrep
  125. echo "---------------------------- Test 7 ------------------------------" >>testtrygrep
  126. (cd $srcdir; $valgrind $vjs $pcre2grep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  127. echo "RC=$?" >>testtrygrep
  128. echo "---------------------------- Test 8 ------------------------------" >>testtrygrep
  129. (cd $srcdir; $valgrind $vjs $pcre2grep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  130. echo "RC=$?" >>testtrygrep
  131. echo "---------------------------- Test 9 ------------------------------" >>testtrygrep
  132. (cd $srcdir; $valgrind $vjs $pcre2grep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  133. echo "RC=$?" >>testtrygrep
  134. echo "---------------------------- Test 10 -----------------------------" >>testtrygrep
  135. (cd $srcdir; $valgrind $vjs $pcre2grep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  136. echo "RC=$?" >>testtrygrep
  137. echo "---------------------------- Test 11 -----------------------------" >>testtrygrep
  138. (cd $srcdir; $valgrind $vjs $pcre2grep -vn pattern ./testdata/grepinputx) >>testtrygrep
  139. echo "RC=$?" >>testtrygrep
  140. echo "---------------------------- Test 12 -----------------------------" >>testtrygrep
  141. (cd $srcdir; $valgrind $vjs $pcre2grep -ix pattern ./testdata/grepinputx) >>testtrygrep
  142. echo "RC=$?" >>testtrygrep
  143. echo "---------------------------- Test 13 -----------------------------" >>testtrygrep
  144. echo seventeen >testtemp1grep
  145. (cd $srcdir; $valgrind $vjs $pcre2grep -f./testdata/greplist -f $builddir/testtemp1grep ./testdata/grepinputx) >>testtrygrep
  146. echo "RC=$?" >>testtrygrep
  147. echo "---------------------------- Test 14 -----------------------------" >>testtrygrep
  148. (cd $srcdir; $valgrind $vjs $pcre2grep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  149. echo "RC=$?" >>testtrygrep
  150. echo "---------------------------- Test 15 -----------------------------" >>testtrygrep
  151. (cd $srcdir; $valgrind $vjs $pcre2grep 'abc^*' ./testdata/grepinput) >>testtrygrep 2>&1
  152. echo "RC=$?" >>testtrygrep
  153. echo "---------------------------- Test 16 -----------------------------" >>testtrygrep
  154. (cd $srcdir; $valgrind $vjs $pcre2grep abc ./testdata/grepinput ./testdata/nonexistfile) >>testtrygrep 2>&1
  155. echo "RC=$?" >>testtrygrep
  156. echo "---------------------------- Test 17 -----------------------------" >>testtrygrep
  157. (cd $srcdir; $valgrind $vjs $pcre2grep -M 'the\noutput' ./testdata/grepinput) >>testtrygrep
  158. echo "RC=$?" >>testtrygrep
  159. echo "---------------------------- Test 18 -----------------------------" >>testtrygrep
  160. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtrygrep
  161. echo "RC=$?" >>testtrygrep
  162. echo "---------------------------- Test 19 -----------------------------" >>testtrygrep
  163. (cd $srcdir; $valgrind $vjs $pcre2grep -Mix 'Pattern' ./testdata/grepinputx) >>testtrygrep
  164. echo "RC=$?" >>testtrygrep
  165. echo "---------------------------- Test 20 -----------------------------" >>testtrygrep
  166. (cd $srcdir; $valgrind $vjs $pcre2grep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtrygrep
  167. echo "RC=$?" >>testtrygrep
  168. echo "---------------------------- Test 21 -----------------------------" >>testtrygrep
  169. (cd $srcdir; $valgrind $vjs $pcre2grep -nA3 'four' ./testdata/grepinputx) >>testtrygrep
  170. echo "RC=$?" >>testtrygrep
  171. echo "---------------------------- Test 22 -----------------------------" >>testtrygrep
  172. (cd $srcdir; $valgrind $vjs $pcre2grep -nB3 'four' ./testdata/grepinputx) >>testtrygrep
  173. echo "RC=$?" >>testtrygrep
  174. echo "---------------------------- Test 23 -----------------------------" >>testtrygrep
  175. (cd $srcdir; $valgrind $vjs $pcre2grep -C3 'four' ./testdata/grepinputx) >>testtrygrep
  176. echo "RC=$?" >>testtrygrep
  177. echo "---------------------------- Test 24 -----------------------------" >>testtrygrep
  178. (cd $srcdir; $valgrind $vjs $pcre2grep -A9 'four' ./testdata/grepinputx) >>testtrygrep
  179. echo "RC=$?" >>testtrygrep
  180. echo "---------------------------- Test 25 -----------------------------" >>testtrygrep
  181. (cd $srcdir; $valgrind $vjs $pcre2grep -nB9 'four' ./testdata/grepinputx) >>testtrygrep
  182. echo "RC=$?" >>testtrygrep
  183. echo "---------------------------- Test 26 -----------------------------" >>testtrygrep
  184. (cd $srcdir; $valgrind $vjs $pcre2grep -A9 -B9 'four' ./testdata/grepinputx) >>testtrygrep
  185. echo "RC=$?" >>testtrygrep
  186. echo "---------------------------- Test 27 -----------------------------" >>testtrygrep
  187. (cd $srcdir; $valgrind $vjs $pcre2grep -A10 'four' ./testdata/grepinputx) >>testtrygrep
  188. echo "RC=$?" >>testtrygrep
  189. echo "---------------------------- Test 28 -----------------------------" >>testtrygrep
  190. (cd $srcdir; $valgrind $vjs $pcre2grep -nB10 'four' ./testdata/grepinputx) >>testtrygrep
  191. echo "RC=$?" >>testtrygrep
  192. echo "---------------------------- Test 29 -----------------------------" >>testtrygrep
  193. (cd $srcdir; $valgrind $vjs $pcre2grep -C12 -B10 'four' ./testdata/grepinputx) >>testtrygrep
  194. echo "RC=$?" >>testtrygrep
  195. echo "---------------------------- Test 30 -----------------------------" >>testtrygrep
  196. (cd $srcdir; $valgrind $vjs $pcre2grep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  197. echo "RC=$?" >>testtrygrep
  198. echo "---------------------------- Test 31 -----------------------------" >>testtrygrep
  199. (cd $srcdir; $valgrind $vjs $pcre2grep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  200. echo "RC=$?" >>testtrygrep
  201. echo "---------------------------- Test 32 -----------------------------" >>testtrygrep
  202. (cd $srcdir; $valgrind $vjs $pcre2grep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  203. echo "RC=$?" >>testtrygrep
  204. echo "---------------------------- Test 33 -----------------------------" >>testtrygrep
  205. (cd $srcdir; $valgrind $vjs $pcre2grep 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
  206. echo "RC=$?" >>testtrygrep
  207. echo "---------------------------- Test 34 -----------------------------" >>testtrygrep
  208. (cd $srcdir; $valgrind $vjs $pcre2grep -s 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
  209. echo "RC=$?" >>testtrygrep
  210. echo "---------------------------- Test 35 -----------------------------" >>testtrygrep
  211. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinputx --include grepinput8 --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  212. echo "RC=$?" >>testtrygrep
  213. echo "---------------------------- Test 36 -----------------------------" >>testtrygrep
  214. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include='grepinput[^C]' --exclude 'grepinput$' --exclude=grepinput8 --exclude=grepinputM --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  215. echo "RC=$?" >>testtrygrep
  216. echo "---------------------------- Test 37 -----------------------------" >>testtrygrep
  217. (cd $srcdir; $valgrind $vjs $pcre2grep '^(a+)*\d' ./testdata/grepinput) >>testtrygrep 2>teststderrgrep
  218. echo "RC=$?" >>testtrygrep
  219. echo "======== STDERR ========" >>testtrygrep
  220. cat teststderrgrep >>testtrygrep
  221. echo "---------------------------- Test 38 ------------------------------" >>testtrygrep
  222. (cd $srcdir; $valgrind $vjs $pcre2grep '>\x00<' ./testdata/grepinput) >>testtrygrep
  223. echo "RC=$?" >>testtrygrep
  224. echo "---------------------------- Test 39 ------------------------------" >>testtrygrep
  225. (cd $srcdir; $valgrind $vjs $pcre2grep -A1 'before the binary zero' ./testdata/grepinput) >>testtrygrep
  226. echo "RC=$?" >>testtrygrep
  227. echo "---------------------------- Test 40 ------------------------------" >>testtrygrep
  228. (cd $srcdir; $valgrind $vjs $pcre2grep -B1 'after the binary zero' ./testdata/grepinput) >>testtrygrep
  229. echo "RC=$?" >>testtrygrep
  230. echo "---------------------------- Test 41 ------------------------------" >>testtrygrep
  231. (cd $srcdir; $valgrind $vjs $pcre2grep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
  232. echo "RC=$?" >>testtrygrep
  233. echo "---------------------------- Test 42 ------------------------------" >>testtrygrep
  234. (cd $srcdir; $valgrind $vjs $pcre2grep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
  235. echo "RC=$?" >>testtrygrep
  236. echo "---------------------------- Test 43 ------------------------------" >>testtrygrep
  237. (cd $srcdir; $valgrind $vjs $pcre2grep -on 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  238. echo "RC=$?" >>testtrygrep
  239. echo "---------------------------- Test 44 ------------------------------" >>testtrygrep
  240. (cd $srcdir; $valgrind $vjs $pcre2grep -on -e before -ezero -e after ./testdata/grepinput) >>testtrygrep
  241. echo "RC=$?" >>testtrygrep
  242. echo "---------------------------- Test 45 ------------------------------" >>testtrygrep
  243. (cd $srcdir; $valgrind $vjs $pcre2grep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtrygrep
  244. echo "RC=$?" >>testtrygrep
  245. echo "---------------------------- Test 46 ------------------------------" >>testtrygrep
  246. (cd $srcdir; $valgrind $vjs $pcre2grep -e 'unopened)' -e abc ./testdata/grepinput) >>testtrygrep 2>&1
  247. (cd $srcdir; $valgrind $vjs $pcre2grep -eabc -e '(unclosed' ./testdata/grepinput) >>testtrygrep 2>&1
  248. (cd $srcdir; $valgrind $vjs $pcre2grep -eabc -e xyz -e '[unclosed' ./testdata/grepinput) >>testtrygrep 2>&1
  249. (cd $srcdir; $valgrind $vjs $pcre2grep --regex=123 -eabc -e xyz -e '[unclosed' ./testdata/grepinput) >>testtrygrep 2>&1
  250. echo "RC=$?" >>testtrygrep
  251. echo "---------------------------- Test 47 ------------------------------" >>testtrygrep
  252. (cd $srcdir; $valgrind $vjs $pcre2grep -Fx "AB.VE
  253. elephant" ./testdata/grepinput) >>testtrygrep
  254. echo "RC=$?" >>testtrygrep
  255. echo "---------------------------- Test 48 ------------------------------" >>testtrygrep
  256. (cd $srcdir; $valgrind $vjs $pcre2grep -F "AB.VE
  257. elephant" ./testdata/grepinput) >>testtrygrep
  258. echo "RC=$?" >>testtrygrep
  259. echo "---------------------------- Test 49 ------------------------------" >>testtrygrep
  260. (cd $srcdir; $valgrind $vjs $pcre2grep -F -e DATA -e "AB.VE
  261. elephant" ./testdata/grepinput) >>testtrygrep
  262. echo "RC=$?" >>testtrygrep
  263. echo "---------------------------- Test 50 ------------------------------" >>testtrygrep
  264. (cd $srcdir; $valgrind $vjs $pcre2grep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtrygrep
  265. echo "RC=$?" >>testtrygrep
  266. echo "---------------------------- Test 51 ------------------------------" >>testtrygrep
  267. (cd $srcdir; $valgrind $vjs $pcre2grep -Mv "brown\sfox" ./testdata/grepinputv) >>testtrygrep
  268. echo "RC=$?" >>testtrygrep
  269. echo "---------------------------- Test 52 ------------------------------" >>testtrygrep
  270. (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always jumps ./testdata/grepinputv) >>testtrygrep
  271. echo "RC=$?" >>testtrygrep
  272. echo "---------------------------- Test 53 ------------------------------" >>testtrygrep
  273. (cd $srcdir; $valgrind $vjs $pcre2grep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  274. echo "RC=$?" >>testtrygrep
  275. echo "---------------------------- Test 54 ------------------------------" >>testtrygrep
  276. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  277. echo "RC=$?" >>testtrygrep
  278. echo "---------------------------- Test 55 -----------------------------" >>testtrygrep
  279. (cd $srcdir; $valgrind $vjs $pcre2grep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtrygrep
  280. echo "RC=$?" >>testtrygrep
  281. echo "---------------------------- Test 56 -----------------------------" >>testtrygrep
  282. (cd $srcdir; $valgrind $vjs $pcre2grep -c --exclude=grepinputC lazy ./testdata/grepinput*) >>testtrygrep
  283. echo "RC=$?" >>testtrygrep
  284. echo "---------------------------- Test 57 -----------------------------" >>testtrygrep
  285. (cd $srcdir; $valgrind $vjs $pcre2grep -c -l --exclude=grepinputC lazy ./testdata/grepinput*) >>testtrygrep
  286. echo "RC=$?" >>testtrygrep
  287. echo "---------------------------- Test 58 -----------------------------" >>testtrygrep
  288. (cd $srcdir; $valgrind $vjs $pcre2grep --regex=PATTERN ./testdata/grepinput) >>testtrygrep
  289. echo "RC=$?" >>testtrygrep
  290. echo "---------------------------- Test 59 -----------------------------" >>testtrygrep
  291. (cd $srcdir; $valgrind $vjs $pcre2grep --regexp=PATTERN ./testdata/grepinput) >>testtrygrep
  292. echo "RC=$?" >>testtrygrep
  293. echo "---------------------------- Test 60 -----------------------------" >>testtrygrep
  294. (cd $srcdir; $valgrind $vjs $pcre2grep --regex PATTERN ./testdata/grepinput) >>testtrygrep
  295. echo "RC=$?" >>testtrygrep
  296. echo "---------------------------- Test 61 -----------------------------" >>testtrygrep
  297. (cd $srcdir; $valgrind $vjs $pcre2grep --regexp PATTERN ./testdata/grepinput) >>testtrygrep
  298. echo "RC=$?" >>testtrygrep
  299. echo "---------------------------- Test 62 -----------------------------" >>testtrygrep
  300. (cd $srcdir; $valgrind $pcre2grep --match-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
  301. echo "RC=$?" >>testtrygrep
  302. echo "---------------------------- Test 63 -----------------------------" >>testtrygrep
  303. (cd $srcdir; $valgrind $pcre2grep --recursion-limit=1K --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
  304. echo "RC=$?" >>testtrygrep
  305. echo "---------------------------- Test 64 ------------------------------" >>testtrygrep
  306. (cd $srcdir; $valgrind $vjs $pcre2grep -o1 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  307. echo "RC=$?" >>testtrygrep
  308. echo "---------------------------- Test 65 ------------------------------" >>testtrygrep
  309. (cd $srcdir; $valgrind $vjs $pcre2grep -o2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  310. echo "RC=$?" >>testtrygrep
  311. echo "---------------------------- Test 66 ------------------------------" >>testtrygrep
  312. (cd $srcdir; $valgrind $vjs $pcre2grep -o3 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  313. echo "RC=$?" >>testtrygrep
  314. echo "---------------------------- Test 67 ------------------------------" >>testtrygrep
  315. (cd $srcdir; $valgrind $vjs $pcre2grep -o12 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  316. echo "RC=$?" >>testtrygrep
  317. echo "---------------------------- Test 68 ------------------------------" >>testtrygrep
  318. (cd $srcdir; $valgrind $vjs $pcre2grep --only-matching=2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  319. echo "RC=$?" >>testtrygrep
  320. echo "---------------------------- Test 69 -----------------------------" >>testtrygrep
  321. (cd $srcdir; $valgrind $vjs $pcre2grep -vn --colour=always pattern ./testdata/grepinputx) >>testtrygrep
  322. echo "RC=$?" >>testtrygrep
  323. echo "---------------------------- Test 70 -----------------------------" >>testtrygrep
  324. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always -M "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  325. echo "RC=$?" >>testtrygrep
  326. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always -M -n "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  327. echo "RC=$?" >>testtrygrep
  328. (cd $srcdir; $valgrind $vjs $pcre2grep -M "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  329. echo "RC=$?" >>testtrygrep
  330. (cd $srcdir; $valgrind $vjs $pcre2grep -M -n "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  331. echo "RC=$?" >>testtrygrep
  332. echo "---------------------------- Test 71 -----------------------------" >>testtrygrep
  333. (cd $srcdir; $valgrind $vjs $pcre2grep -o "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  334. echo "RC=$?" >>testtrygrep
  335. echo "---------------------------- Test 72 -----------------------------" >>testtrygrep
  336. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  337. echo "RC=$?" >>testtrygrep
  338. echo "---------------------------- Test 73 -----------------------------" >>testtrygrep
  339. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  340. echo "RC=$?" >>testtrygrep
  341. echo "---------------------------- Test 74 -----------------------------" >>testtrygrep
  342. (cd $srcdir; $valgrind $vjs $pcre2grep -o "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  343. echo "RC=$?" >>testtrygrep
  344. echo "---------------------------- Test 75 -----------------------------" >>testtrygrep
  345. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  346. echo "RC=$?" >>testtrygrep
  347. echo "---------------------------- Test 76 -----------------------------" >>testtrygrep
  348. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  349. echo "RC=$?" >>testtrygrep
  350. echo "---------------------------- Test 77 -----------------------------" >>testtrygrep
  351. (cd $srcdir; $valgrind $vjs $pcre2grep -o "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  352. echo "RC=$?" >>testtrygrep
  353. echo "---------------------------- Test 78 -----------------------------" >>testtrygrep
  354. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  355. echo "RC=$?" >>testtrygrep
  356. echo "---------------------------- Test 79 -----------------------------" >>testtrygrep
  357. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  358. echo "RC=$?" >>testtrygrep
  359. echo "---------------------------- Test 80 -----------------------------" >>testtrygrep
  360. (cd $srcdir; $valgrind $vjs $pcre2grep -o "\b01|\b02" ./testdata/grepinput) >>testtrygrep
  361. echo "RC=$?" >>testtrygrep
  362. echo "---------------------------- Test 81 -----------------------------" >>testtrygrep
  363. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
  364. echo "RC=$?" >>testtrygrep
  365. echo "---------------------------- Test 82 -----------------------------" >>testtrygrep
  366. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
  367. echo "RC=$?" >>testtrygrep
  368. echo "---------------------------- Test 83 -----------------------------" >>testtrygrep
  369. (cd $srcdir; $valgrind $vjs $pcre2grep --buffer-size=10 --max-buffer-size=100 "^a" ./testdata/grepinput3) >>testtrygrep 2>&1
  370. echo "RC=$?" >>testtrygrep
  371. echo "---------------------------- Test 84 -----------------------------" >>testtrygrep
  372. echo testdata/grepinput3 >testtemp1grep
  373. (cd $srcdir; $valgrind $vjs $pcre2grep --file-list ./testdata/grepfilelist --file-list $builddir/testtemp1grep "fox|complete|t7") >>testtrygrep 2>&1
  374. echo "RC=$?" >>testtrygrep
  375. echo "---------------------------- Test 85 -----------------------------" >>testtrygrep
  376. (cd $srcdir; $valgrind $vjs $pcre2grep --file-list=./testdata/grepfilelist "dolor" ./testdata/grepinput3) >>testtrygrep 2>&1
  377. echo "RC=$?" >>testtrygrep
  378. echo "---------------------------- Test 86 -----------------------------" >>testtrygrep
  379. (cd $srcdir; $valgrind $vjs $pcre2grep "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  380. echo "RC=$?" >>testtrygrep
  381. echo "---------------------------- Test 87 -----------------------------" >>testtrygrep
  382. (cd $srcdir; $valgrind $vjs $pcre2grep "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
  383. echo "RC=$?" >>testtrygrep
  384. echo "---------------------------- Test 88 -----------------------------" >>testtrygrep
  385. (cd $srcdir; $valgrind $vjs $pcre2grep -v "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
  386. echo "RC=$?" >>testtrygrep
  387. echo "---------------------------- Test 89 -----------------------------" >>testtrygrep
  388. (cd $srcdir; $valgrind $vjs $pcre2grep -I "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  389. echo "RC=$?" >>testtrygrep
  390. echo "---------------------------- Test 90 -----------------------------" >>testtrygrep
  391. (cd $srcdir; $valgrind $vjs $pcre2grep --binary-files=without-match "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  392. echo "RC=$?" >>testtrygrep
  393. echo "---------------------------- Test 91 -----------------------------" >>testtrygrep
  394. (cd $srcdir; $valgrind $vjs $pcre2grep -a "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  395. echo "RC=$?" >>testtrygrep
  396. echo "---------------------------- Test 92 -----------------------------" >>testtrygrep
  397. (cd $srcdir; $valgrind $vjs $pcre2grep --binary-files=text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  398. echo "RC=$?" >>testtrygrep
  399. echo "---------------------------- Test 93 -----------------------------" >>testtrygrep
  400. (cd $srcdir; $valgrind $vjs $pcre2grep --text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  401. echo "RC=$?" >>testtrygrep
  402. echo "---------------------------- Test 94 -----------------------------" >>testtrygrep
  403. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinputx --include grepinput8 'fox' ./testdata/grepinput* | sort) >>testtrygrep
  404. echo "RC=$?" >>testtrygrep
  405. echo "---------------------------- Test 95 -----------------------------" >>testtrygrep
  406. (cd $srcdir; $valgrind $vjs $pcre2grep --file-list ./testdata/grepfilelist --exclude grepinputv "fox|complete") >>testtrygrep 2>&1
  407. echo "RC=$?" >>testtrygrep
  408. echo "---------------------------- Test 96 -----------------------------" >>testtrygrep
  409. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include-dir=testdata --exclude '^(?!grepinput)' --exclude=grepinput[MC] 'fox' ./test* | sort) >>testtrygrep
  410. echo "RC=$?" >>testtrygrep
  411. echo "---------------------------- Test 97 -----------------------------" >>testtrygrep
  412. echo "grepinput$" >testtemp1grep
  413. echo "grepinput8" >>testtemp1grep
  414. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinput --exclude=grepinput[MC] --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  415. echo "RC=$?" >>testtrygrep
  416. echo "---------------------------- Test 98 -----------------------------" >>testtrygrep
  417. echo "grepinput$" >testtemp1grep
  418. echo "grepinput8" >>testtemp1grep
  419. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --exclude=grepinput3 --exclude=grepinput[MC] --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  420. echo "RC=$?" >>testtrygrep
  421. echo "---------------------------- Test 99 -----------------------------" >>testtrygrep
  422. echo "grepinput$" >testtemp1grep
  423. echo "grepinput8" >testtemp2grep
  424. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include grepinput --exclude=grepinput[MC] --exclude-from $builddir/testtemp1grep --exclude-from=$builddir/testtemp2grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  425. echo "RC=$?" >>testtrygrep
  426. echo "---------------------------- Test 100 ------------------------------" >>testtrygrep
  427. (cd $srcdir; $valgrind $vjs $pcre2grep -Ho2 --only-matching=1 -o3 '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  428. echo "RC=$?" >>testtrygrep
  429. echo "---------------------------- Test 101 ------------------------------" >>testtrygrep
  430. (cd $srcdir; $valgrind $vjs $pcre2grep -o3 -Ho2 -o12 --only-matching=1 -o3 --colour=always --om-separator='|' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  431. echo "RC=$?" >>testtrygrep
  432. echo "---------------------------- Test 102 -----------------------------" >>testtrygrep
  433. (cd $srcdir; $valgrind $vjs $pcre2grep -n "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  434. echo "RC=$?" >>testtrygrep
  435. echo "---------------------------- Test 103 -----------------------------" >>testtrygrep
  436. (cd $srcdir; $valgrind $vjs $pcre2grep --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  437. echo "RC=$?" >>testtrygrep
  438. echo "---------------------------- Test 104 -----------------------------" >>testtrygrep
  439. (cd $srcdir; $valgrind $vjs $pcre2grep -n --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  440. echo "RC=$?" >>testtrygrep
  441. echo "---------------------------- Test 105 -----------------------------" >>testtrygrep
  442. (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always "ipsum|" ./testdata/grepinput3) >>testtrygrep 2>&1
  443. echo "RC=$?" >>testtrygrep
  444. echo "---------------------------- Test 106 -----------------------------" >>testtrygrep
  445. (cd $srcdir; echo "a" | $valgrind $vjs $pcre2grep -M "|a" ) >>testtrygrep 2>&1
  446. echo "RC=$?" >>testtrygrep
  447. echo "---------------------------- Test 107 -----------------------------" >>testtrygrep
  448. echo "a" >testtemp1grep
  449. echo "aaaaa" >>testtemp1grep
  450. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets --allow-lookaround-bsk '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
  451. echo "RC=$?" >>testtrygrep
  452. echo "---------------------------- Test 108 ------------------------------" >>testtrygrep
  453. (cd $srcdir; $valgrind $vjs $pcre2grep -lq PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  454. echo "RC=$?" >>testtrygrep
  455. echo "---------------------------- Test 109 -----------------------------" >>testtrygrep
  456. (cd $srcdir; $valgrind $vjs $pcre2grep -cq --exclude=grepinputC lazy ./testdata/grepinput*) >>testtrygrep
  457. echo "RC=$?" >>testtrygrep
  458. echo "---------------------------- Test 110 -----------------------------" >>testtrygrep
  459. (cd $srcdir; $valgrind $vjs $pcre2grep --om-separator / -Mo0 -o1 -o2 'match (\d+):\n (.)\n' testdata/grepinput) >>testtrygrep
  460. echo "RC=$?" >>testtrygrep
  461. echo "---------------------------- Test 111 -----------------------------" >>testtrygrep
  462. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets -M 'match (\d+):\n (.)\n' testdata/grepinput) >>testtrygrep
  463. echo "RC=$?" >>testtrygrep
  464. echo "---------------------------- Test 112 -----------------------------" >>testtrygrep
  465. (cd $srcdir; $valgrind $vjs $pcre2grep --file-offsets -M 'match (\d+):\n (.)\n' testdata/grepinput) >>testtrygrep
  466. echo "RC=$?" >>testtrygrep
  467. echo "---------------------------- Test 113 -----------------------------" >>testtrygrep
  468. (cd $srcdir; $valgrind $vjs $pcre2grep --total-count --exclude=grepinputC 'the' testdata/grepinput*) >>testtrygrep
  469. echo "RC=$?" >>testtrygrep
  470. echo "---------------------------- Test 114 -----------------------------" >>testtrygrep
  471. (cd $srcdir; $valgrind $vjs $pcre2grep -tc --exclude=grepinputC 'the' testdata/grepinput*) >>testtrygrep
  472. echo "RC=$?" >>testtrygrep
  473. echo "---------------------------- Test 115 -----------------------------" >>testtrygrep
  474. (cd $srcdir; $valgrind $vjs $pcre2grep -tlc --exclude=grepinputC 'the' testdata/grepinput*) >>testtrygrep
  475. echo "RC=$?" >>testtrygrep
  476. echo "---------------------------- Test 116 -----------------------------" >>testtrygrep
  477. (cd $srcdir; $valgrind $vjs $pcre2grep --exclude=grepinput[MC] -th 'the' testdata/grepinput*) >>testtrygrep
  478. echo "RC=$?" >>testtrygrep
  479. echo "---------------------------- Test 117 -----------------------------" >>testtrygrep
  480. (cd $srcdir; $valgrind $vjs $pcre2grep -tch --exclude=grepinputC 'the' testdata/grepinput*) >>testtrygrep
  481. echo "RC=$?" >>testtrygrep
  482. echo "---------------------------- Test 118 -----------------------------" >>testtrygrep
  483. (cd $srcdir; $valgrind $vjs $pcre2grep -tL --exclude=grepinputC 'the' testdata/grepinput*) >>testtrygrep
  484. echo "RC=$?" >>testtrygrep
  485. echo "---------------------------- Test 119 -----------------------------" >>testtrygrep
  486. printf '123\n456\n789\n---abc\ndef\nxyz\n---\n' >testNinputgrep
  487. $valgrind $vjs $pcre2grep -Mo '(\n|[^-])*---' testNinputgrep >>testtrygrep
  488. echo "RC=$?" >>testtrygrep
  489. echo "---------------------------- Test 120 ------------------------------" >>testtrygrep
  490. (cd $srcdir; $valgrind $vjs $pcre2grep -HO '$0:$2$1$3' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  491. echo "RC=$?" >>testtrygrep
  492. (cd $srcdir; $valgrind $vjs $pcre2grep -m 1 -O '$0:$a$b$e$f$r$t$v' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  493. echo "RC=$?" >>testtrygrep
  494. (cd $srcdir; $valgrind $vjs $pcre2grep -HO '${X}' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep 2>&1
  495. echo "RC=$?" >>testtrygrep
  496. (cd $srcdir; $valgrind $vjs $pcre2grep -HO 'XX$' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep 2>&1
  497. echo "RC=$?" >>testtrygrep
  498. (cd $srcdir; $valgrind $vjs $pcre2grep -O '$x{12345678}' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep 2>&1
  499. echo "RC=$?" >>testtrygrep
  500. (cd $srcdir; $valgrind $vjs $pcre2grep -O '$x{123Z' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep 2>&1
  501. echo "RC=$?" >>testtrygrep
  502. (cd $srcdir; $valgrind $vjs $pcre2grep --output '$x{1234}' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep 2>&1
  503. echo "RC=$?" >>testtrygrep
  504. echo "---------------------------- Test 121 -----------------------------" >>testtrygrep
  505. (cd $srcdir; $valgrind $vjs $pcre2grep -F '\E and (regex)' testdata/grepinputv) >>testtrygrep
  506. echo "RC=$?" >>testtrygrep
  507. echo "---------------------------- Test 122 -----------------------------" >>testtrygrep
  508. (cd $srcdir; $valgrind $vjs $pcre2grep -w 'cat|dog' testdata/grepinputv) >>testtrygrep
  509. echo "RC=$?" >>testtrygrep
  510. echo "---------------------------- Test 123 -----------------------------" >>testtrygrep
  511. (cd $srcdir; $valgrind $vjs $pcre2grep -w 'dog|cat' testdata/grepinputv) >>testtrygrep
  512. echo "RC=$?" >>testtrygrep
  513. echo "---------------------------- Test 124 -----------------------------" >>testtrygrep
  514. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn --colour=always 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  515. echo "RC=$?" >>testtrygrep
  516. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn --colour=always -A2 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  517. echo "RC=$?" >>testtrygrep
  518. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  519. echo "RC=$?" >>testtrygrep
  520. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn -A2 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  521. echo "RC=$?" >>testtrygrep
  522. echo "---------------------------- Test 125 -----------------------------" >>testtrygrep
  523. printf 'abcd\n' >testNinputgrep
  524. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?<=\K.)' testNinputgrep >>testtrygrep
  525. echo "RC=$?" >>testtrygrep
  526. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?=.\K)' testNinputgrep >>testtrygrep
  527. echo "RC=$?" >>testtrygrep
  528. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?<=\K[ac])' testNinputgrep >>testtrygrep
  529. echo "RC=$?" >>testtrygrep
  530. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?=[ac]\K)' testNinputgrep >>testtrygrep
  531. echo "RC=$?" >>testtrygrep
  532. GREP_COLORS='ms=1;20' $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?=[ac]\K)' testNinputgrep >>testtrygrep
  533. echo "RC=$?" >>testtrygrep
  534. echo "---------------------------- Test 126 -----------------------------" >>testtrygrep
  535. printf 'Next line pattern has binary zero\nABC\0XYZ\n' >testtemp1grep
  536. printf 'ABC\0XYZ\nABCDEF\nDEFABC\n' >testtemp2grep
  537. $valgrind $vjs $pcre2grep -a -f testtemp1grep testtemp2grep >>testtrygrep
  538. echo "RC=$?" >>testtrygrep
  539. printf 'Next line pattern is erroneous.\n^abc)(xy' >testtemp1grep
  540. $valgrind $vjs $pcre2grep -a -f testtemp1grep testtemp2grep >>testtrygrep 2>&1
  541. echo "RC=$?" >>testtrygrep
  542. echo "---------------------------- Test 127 -----------------------------" >>testtrygrep
  543. (cd $srcdir; $valgrind $vjs $pcre2grep -o --om-capture=0 'pattern()()()()' testdata/grepinput) >>testtrygrep
  544. echo "RC=$?" >>testtrygrep
  545. echo "---------------------------- Test 128 -----------------------------" >>testtrygrep
  546. (cd $srcdir; $valgrind $vjs $pcre2grep -m1M -o1 --om-capture=0 'pattern()()()()' testdata/grepinput) >>testtrygrep 2>&1
  547. echo "RC=$?" >>testtrygrep
  548. echo "---------------------------- Test 129 -----------------------------" >>testtrygrep
  549. (cd $srcdir; $valgrind $vjs $pcre2grep -m 2 'fox' testdata/grepinput) >>testtrygrep 2>&1
  550. echo "RC=$?" >>testtrygrep
  551. echo "---------------------------- Test 130 -----------------------------" >>testtrygrep
  552. (cd $srcdir; $valgrind $vjs $pcre2grep -o -m2 'fox' testdata/grepinput) >>testtrygrep 2>&1
  553. echo "RC=$?" >>testtrygrep
  554. echo "---------------------------- Test 131 -----------------------------" >>testtrygrep
  555. (cd $srcdir; $valgrind $vjs $pcre2grep -oc -m2 'fox' testdata/grepinput) >>testtrygrep 2>&1
  556. echo "RC=$?" >>testtrygrep
  557. echo "---------------------------- Test 132 -----------------------------" >>testtrygrep
  558. (cd $srcdir; exec 3<testdata/grepinput; $valgrind $vjs $pcre2grep -m1 -A3 '^match' <&3; echo '---'; head -1 <&3; exec 3<&-) >>testtrygrep 2>&1
  559. echo "RC=$?" >>testtrygrep
  560. echo "---------------------------- Test 133 -----------------------------" >>testtrygrep
  561. (cd $srcdir; exec 3<testdata/grepinput; $valgrind $vjs $pcre2grep -m1 -A3 '^match' <&3; echo '---'; $valgrind $vjs $pcre2grep -m1 -A3 '^match' <&3; exec 3<&-) >>testtrygrep 2>&1
  562. echo "RC=$?" >>testtrygrep
  563. echo "---------------------------- Test 134 -----------------------------" >>testtrygrep
  564. (cd $srcdir; $valgrind $vjs $pcre2grep --max-count=1 -nH -O '=$x{41}$x423$o{103}$o1045=' 'fox' -) <$srcdir/testdata/grepinputv >>testtrygrep 2>&1
  565. echo "RC=$?" >>testtrygrep
  566. echo "---------------------------- Test 135 -----------------------------" >>testtrygrep
  567. (cd $srcdir; $valgrind $vjs $pcre2grep -HZ 'word' ./testdata/grepinputv) | $tr '\000' '@' >>testtrygrep
  568. echo "RC=$?" >>testtrygrep
  569. (cd $srcdir; $valgrind $vjs $pcre2grep -lZ 'word' ./testdata/grepinputv ./testdata/grepinputv) | $tr '\000' '@' >>testtrygrep
  570. echo "RC=$?" >>testtrygrep
  571. (cd $srcdir; $valgrind $vjs $pcre2grep -A 1 -B 1 -HZ 'word' ./testdata/grepinputv) | $tr '\000' '@' >>testtrygrep
  572. echo "RC=$?" >>testtrygrep
  573. (cd $srcdir; $valgrind $vjs $pcre2grep -MHZn 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  574. echo "RC=$?" >>testtrygrep
  575. echo "---------------------------- Test 136 -----------------------------" >>testtrygrep
  576. (cd $srcdir; $valgrind $vjs $pcre2grep -m1MK -o1 --om-capture=0 'pattern()()()()' testdata/grepinput) >>testtrygrep 2>&1
  577. echo "RC=$?" >>testtrygrep
  578. (cd $srcdir; $valgrind $vjs $pcre2grep --max-count=1MK -o1 --om-capture=0 'pattern()()()()' testdata/grepinput) >>testtrygrep 2>&1
  579. echo "RC=$?" >>testtrygrep
  580. echo "---------------------------- Test 137 -----------------------------" >>testtrygrep
  581. printf 'Last line\nhas no newline' >testtemp1grep
  582. $valgrind $vjs $pcre2grep -A1 Last testtemp1grep >>testtrygrep
  583. echo "RC=$?" >>testtrygrep
  584. echo "---------------------------- Test 138 -----------------------------" >>testtrygrep
  585. printf 'AbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\n' >testtemp1grep
  586. $valgrind $vjs $pcre2grep --no-jit --heap-limit=0 b testtemp1grep >>testtrygrep 2>&1
  587. echo "RC=$?" >>testtrygrep
  588. echo "---------------------------- Test 139 -----------------------------" >>testtrygrep
  589. (cd $srcdir; $valgrind $vjs $pcre2grep --line-buffered 'fox' testdata/grepinputv) >>testtrygrep
  590. echo "RC=$?" >>testtrygrep
  591. echo "---------------------------- Test 140 -----------------------------" >>testtrygrep
  592. (cd $srcdir; $valgrind $vjs $pcre2grep --buffer-size=10 -A1 'brown' testdata/grepinputv) >>testtrygrep
  593. echo "RC=$?" >>testtrygrep
  594. echo "---------------------------- Test 141 -----------------------------" >>testtrygrep
  595. printf "$srcdir/testdata/grepinputv\n-\n" >testtemp1grep
  596. printf 'This is a line from stdin.' >testtemp2grep
  597. $valgrind $vjs $pcre2grep --file-list testtemp1grep "line from stdin" <testtemp2grep >>testtrygrep 2>&1
  598. echo "RC=$?" >>testtrygrep
  599. echo "---------------------------- Test 142 -----------------------------" >>testtrygrep
  600. printf "/does/not/exist\n" >testtemp1grep
  601. printf 'This is a line from stdin.' >testtemp2grep
  602. $valgrind $vjs $pcre2grep --file-list testtemp1grep "line from stdin" >>testtrygrep 2>&1
  603. echo "RC=$?" >>testtrygrep
  604. echo "---------------------------- Test 143 -----------------------------" >>testtrygrep
  605. printf 'fox|cat' >testtemp1grep
  606. $valgrind $vjs $pcre2grep -f - $srcdir/testdata/grepinputv <testtemp1grep >>testtrygrep 2>&1
  607. echo "RC=$?" >>testtrygrep
  608. echo "---------------------------- Test 144 -----------------------------" >>testtrygrep
  609. $valgrind $vjs $pcre2grep -f /non/exist $srcdir/testdata/grepinputv >>testtrygrep 2>&1
  610. echo "RC=$?" >>testtrygrep
  611. echo "---------------------------- Test 145 -----------------------------" >>testtrygrep
  612. printf '*meta*\rdog.' >testtemp1grep
  613. $valgrind $vjs $pcre2grep -Ncr -F -f testtemp1grep $srcdir/testdata/grepinputv >>testtrygrep 2>&1
  614. echo "RC=$?" >>testtrygrep
  615. echo "---------------------------- Test 146 -----------------------------" >>testtrygrep
  616. printf 'A123B' >testtemp1grep
  617. $valgrind $vjs $pcre2grep -H -e '123|fox' - <testtemp1grep >>testtrygrep 2>&1
  618. echo "RC=$?" >>testtrygrep
  619. $valgrind $vjs $pcre2grep -h -e '123|fox' - $srcdir/testdata/grepinputv <testtemp1grep >>testtrygrep 2>&1
  620. echo "RC=$?" >>testtrygrep
  621. $valgrind $vjs $pcre2grep - $srcdir/testdata/grepinputv <testtemp1grep >>testtrygrep 2>&1
  622. echo "RC=$?" >>testtrygrep
  623. echo "---------------------------- Test 147 -----------------------------" >>testtrygrep
  624. $valgrind $vjs $pcre2grep -e '123|fox' -- -nonfile >>testtrygrep 2>&1
  625. echo "RC=$?" >>testtrygrep
  626. echo "---------------------------- Test 148 -----------------------------" >>testtrygrep
  627. $valgrind $vjs $pcre2grep --nonexist >>testtrygrep 2>&1
  628. echo "RC=$?" >>testtrygrep
  629. $valgrind $vjs $pcre2grep -n-n-bad >>testtrygrep 2>&1
  630. echo "RC=$?" >>testtrygrep
  631. $valgrind $vjs $pcre2grep --context >>testtrygrep 2>&1
  632. echo "RC=$?" >>testtrygrep
  633. $valgrind $vjs $pcre2grep --only-matching --output=xx >>testtrygrep 2>&1
  634. echo "RC=$?" >>testtrygrep
  635. $valgrind $vjs $pcre2grep --colour=badvalue >>testtrygrep 2>&1
  636. echo "RC=$?" >>testtrygrep
  637. $valgrind $vjs $pcre2grep --newline=badvalue >>testtrygrep 2>&1
  638. echo "RC=$?" >>testtrygrep
  639. $valgrind $vjs $pcre2grep -d badvalue >>testtrygrep 2>&1
  640. echo "RC=$?" >>testtrygrep
  641. $valgrind $vjs $pcre2grep -D badvalue >>testtrygrep 2>&1
  642. echo "RC=$?" >>testtrygrep
  643. $valgrind $vjs $pcre2grep --buffer-size=0 >>testtrygrep 2>&1
  644. echo "RC=$?" >>testtrygrep
  645. $valgrind $vjs $pcre2grep --exclude '(badpat' abc /dev/null >>testtrygrep 2>&1
  646. echo "RC=$?" >>testtrygrep
  647. $valgrind $vjs $pcre2grep --exclude-from /non/exist abc /dev/null >>testtrygrep 2>&1
  648. echo "RC=$?" >>testtrygrep
  649. $valgrind $vjs $pcre2grep --include-from /non/exist abc /dev/null >>testtrygrep 2>&1
  650. echo "RC=$?" >>testtrygrep
  651. $valgrind $vjs $pcre2grep --file-list=/non/exist abc /dev/null >>testtrygrep 2>&1
  652. echo "RC=$?" >>testtrygrep
  653. echo "---------------------------- Test 149 -----------------------------" >>testtrygrep
  654. (cd $srcdir; $valgrind $vjs $pcre2grep --binary-files=binary "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  655. echo "RC=$?" >>testtrygrep
  656. (cd $srcdir; $valgrind $vjs $pcre2grep --binary-files=wrong "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  657. echo "RC=$?" >>testtrygrep
  658. # This test runs the code that tests locale support. However, on some systems
  659. # (e.g. Alpine Linux) there is no locale support and running this test just
  660. # generates a "no match" result. Therefore, we test for locale support, and if
  661. # it is found missing, we pretend that the test has run as expected so that the
  662. # output matches.
  663. echo "---------------------------- Test 150 -----------------------------" >>testtrygrep
  664. which locale >/dev/null 2>&1
  665. if [ $? -ne 0 ]; then
  666. echo "pcre2grep: Failed to set locale badlocale (obtained from LC_CTYPE)" >>testtrygrep
  667. echo "RC=2" >>testtrygrep
  668. else
  669. (cd $srcdir; unset LC_ALL; env LC_CTYPE=badlocale $valgrind $vjs $pcre2grep abc /dev/null) >>testtrygrep 2>&1
  670. echo "RC=$?" >>testtrygrep
  671. fi
  672. echo "---------------------------- Test 151 -----------------------------" >>testtrygrep
  673. (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always -e this -e The -e 'The wo' testdata/grepinputv) >>testtrygrep
  674. echo "---------------------------- Test 152 -----------------------------" >>testtrygrep
  675. (cd $srcdir; $valgrind $vjs $pcre2grep -nA3 --group-separator='++' 'four' ./testdata/grepinputx) >>testtrygrep
  676. echo "RC=$?" >>testtrygrep
  677. echo "---------------------------- Test 153 -----------------------------" >>testtrygrep
  678. (cd $srcdir; $valgrind $vjs $pcre2grep -nA3 --no-group-separator 'four' ./testdata/grepinputx) >>testtrygrep
  679. echo "RC=$?" >>testtrygrep
  680. # Now compare the results.
  681. $cf $srcdir/testdata/grepoutput testtrygrep
  682. if [ $? != 0 ] ; then exit 1; fi
  683. # These tests require UTF-8 support
  684. if [ $utf8 -ne 0 ] ; then
  685. echo "Testing pcre2grep UTF-8 features"
  686. echo "---------------------------- Test U1 ------------------------------" >testtrygrep
  687. (cd $srcdir; $valgrind $vjs $pcre2grep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtrygrep
  688. echo "RC=$?" >>testtrygrep
  689. echo "---------------------------- Test U2 ------------------------------" >>testtrygrep
  690. (cd $srcdir; $valgrind $vjs $pcre2grep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtrygrep
  691. echo "RC=$?" >>testtrygrep
  692. echo "---------------------------- Test U3 ------------------------------" >>testtrygrep
  693. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets -u --newline=any --allow-lookaround-bsk '(?<=\K\x{17f})' ./testdata/grepinput8) >>testtrygrep
  694. echo "RC=$?" >>testtrygrep
  695. echo "---------------------------- Test U4 ------------------------------" >>testtrygrep
  696. printf 'A\341\200\200\200CD\342\200\200Z\n' >testtemp1grep
  697. (cd $srcdir; $valgrind $vjs $pcre2grep -u -o '....' $builddir/testtemp1grep) >>testtrygrep 2>&1
  698. echo "RC=$?" >>testtrygrep
  699. echo "---------------------------- Test U5 ------------------------------" >>testtrygrep
  700. printf 'A\341\200\200\200CD\342\200\200Z\n' >testtemp1grep
  701. (cd $srcdir; $valgrind $vjs $pcre2grep -U -o '....' $builddir/testtemp1grep) >>testtrygrep
  702. echo "RC=$?" >>testtrygrep
  703. echo "---------------------------- Test U6 -----------------------------" >>testtrygrep
  704. (cd $srcdir; $valgrind $vjs $pcre2grep -u -m1 -O '=$x{1d3}$o{744}=' 'fox') <$srcdir/testdata/grepinputv >>testtrygrep 2>&1
  705. echo "RC=$?" >>testtrygrep
  706. echo "---------------------------- Test U7 ------------------------------" >>testtrygrep
  707. (cd $srcdir; $valgrind $vjs $pcre2grep -ui --colour=always 'k+|\babc\b' ./testdata/grepinput8) >>testtrygrep
  708. echo "RC=$?" >>testtrygrep
  709. echo "---------------------------- Test U8 ------------------------------" >>testtrygrep
  710. (cd $srcdir; $valgrind $vjs $pcre2grep -UiEP --colour=always 'k+|\babc\b' ./testdata/grepinput8) >>testtrygrep
  711. echo "RC=$?" >>testtrygrep
  712. echo "---------------------------- Test U9 ------------------------------" >>testtrygrep
  713. (cd $srcdir; $valgrind $vjs $pcre2grep -u --colour=always 'A\d' ./testdata/grepinput8) >>testtrygrep
  714. echo "RC=$?" >>testtrygrep
  715. echo "---------------------------- Test U10 ------------------------------" >>testtrygrep
  716. (cd $srcdir; $valgrind $vjs $pcre2grep -u --posix-digit --colour=always 'A\d' ./testdata/grepinput8) >>testtrygrep
  717. echo "RC=$?" >>testtrygrep
  718. $cf $srcdir/testdata/grepoutput8 testtrygrep
  719. if [ $? != 0 ] ; then exit 1; fi
  720. else
  721. echo "Skipping pcre2grep UTF-8 tests: no UTF-8 support in PCRE2 library"
  722. fi
  723. # We go to some contortions to try to ensure that the tests for the various
  724. # newline settings will work in environments where the normal newline sequence
  725. # is not \n. Do not use exported files, whose line endings might be changed.
  726. # Instead, create an input file using printf so that its contents are exactly
  727. # what we want. Note the messy fudge to get printf to write a string that
  728. # starts with a hyphen. These tests are run in the build directory.
  729. echo "Testing pcre2grep newline settings"
  730. printf 'abc\rdef\r\nghi\njkl' >testNinputgrep
  731. printf '%c--------------------------- Test N1 ------------------------------\r\n' - >testtrygrep
  732. $valgrind $vjs $pcre2grep -n -N CR "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  733. $valgrind $vjs $pcre2grep -B1 -n -N CR "^def" testNinputgrep >>testtrygrep
  734. printf '%c--------------------------- Test N2 ------------------------------\r\n' - >>testtrygrep
  735. $valgrind $vjs $pcre2grep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  736. $valgrind $vjs $pcre2grep -B1 -n -N CRLF "^ghi" testNinputgrep >>testtrygrep
  737. printf '%c--------------------------- Test N3 ------------------------------\r\n' - >>testtrygrep
  738. pattern=`printf 'def\rjkl'`
  739. $valgrind $vjs $pcre2grep -n --newline=cr -F "$pattern" testNinputgrep >>testtrygrep
  740. printf '%c--------------------------- Test N4 ------------------------------\r\n' - >>testtrygrep
  741. $valgrind $vjs $pcre2grep -n --newline=crlf -F -f $srcdir/testdata/greppatN4 testNinputgrep >>testtrygrep
  742. printf '%c--------------------------- Test N5 ------------------------------\r\n' - >>testtrygrep
  743. $valgrind $vjs $pcre2grep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  744. $valgrind $vjs $pcre2grep -B1 -n --newline=any "^def" testNinputgrep >>testtrygrep
  745. printf '%c--------------------------- Test N6 ------------------------------\r\n' - >>testtrygrep
  746. $valgrind $vjs $pcre2grep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  747. $valgrind $vjs $pcre2grep -B1 -n --newline=anycrlf "^jkl" testNinputgrep >>testtrygrep
  748. printf '%c--------------------------- Test N7 ------------------------------\r\n' - >>testtrygrep
  749. printf 'xyz\0abc\0def' >testNinputgrep
  750. $valgrind $vjs $pcre2grep -na --newline=nul "^(abc|def)" testNinputgrep | $tr '\000' '@' >>testtrygrep
  751. $valgrind $vjs $pcre2grep -B1 -na --newline=nul "^(abc|def)" testNinputgrep | $tr '\000' '@' >>testtrygrep
  752. echo "" >>testtrygrep
  753. $cf $srcdir/testdata/grepoutputN testtrygrep
  754. if [ $? != 0 ] ; then exit 1; fi
  755. # These newline tests need UTF support.
  756. if [ $utf8 -ne 0 ] ; then
  757. echo "Testing pcre2grep newline settings with UTF-8 features"
  758. printf '%c--------------------------- Test UN1 ------------------------------\r\n' - >testtrygrep
  759. printf 'abc\341\210\264def\nxyz' >testNinputgrep
  760. $valgrind $vjs $pcre2grep -nau --newline=anycrlf "^(abc|def)" testNinputgrep >>testtrygrep
  761. echo "" >>testtrygrep
  762. $cf $srcdir/testdata/grepoutputUN testtrygrep
  763. if [ $? != 0 ] ; then exit 1; fi
  764. else
  765. echo "Skipping pcre2grep newline UTF-8 tests: no UTF-8 support in PCRE2 library"
  766. fi
  767. # If pcre2grep supports script callouts, run some tests on them. It is possible
  768. # to restrict these callouts to the non-fork case, either for security, or for
  769. # environments that do not support fork(). This is handled by comparing to a
  770. # different output.
  771. if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'callout scripts in patterns are supported'; then
  772. echo "Testing pcre2grep script callouts"
  773. $valgrind $vjs $pcre2grep '(T)(..(.))(?C"/bin/echo|Arg1: [$1] [$2] [$3]|Arg2: $|${1}$| ($4) ($14) ($0)")()' $srcdir/testdata/grepinputv >testtrygrep
  774. $valgrind $vjs $pcre2grep '(T)(..(.))()()()()()()()(..)(?C"/bin/echo|Arg1: [$11] [${11}]")' $srcdir/testdata/grepinputv >>testtrygrep
  775. $valgrind $vjs $pcre2grep '(T)(?C"|$0:$1$n")' $srcdir/testdata/grepinputv >>testtrygrep
  776. $valgrind $vjs $pcre2grep '(T)(?C"/bin/echo|$0:$1$n")' $srcdir/testdata/grepinputv >>testtrygrep
  777. $valgrind $vjs $pcre2grep '(T)(?C"|$1$n")(*F)' $srcdir/testdata/grepinputv >>testtrygrep
  778. $valgrind $vjs $pcre2grep -m1 '(T)(?C"|$0:$1:$x{41}$o{101}$n")' $srcdir/testdata/grepinputv >>testtrygrep
  779. if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'Non-fork callout scripts in patterns are supported'; then
  780. nonfork=1
  781. $cf $srcdir/testdata/grepoutputCN testtrygrep
  782. else
  783. nonfork=0
  784. $cf $srcdir/testdata/grepoutputC testtrygrep
  785. fi
  786. if [ $? != 0 ] ; then exit 1; fi
  787. # These callout tests need UTF support.
  788. if [ $utf8 -ne 0 ] ; then
  789. echo "Testing pcre2grep script callout with UTF-8 features"
  790. $valgrind $vjs $pcre2grep -u '(T)(?C"|$0:$x{a6}$n")' $srcdir/testdata/grepinputv >testtrygrep
  791. $valgrind $vjs $pcre2grep -u '(T)(?C"/bin/echo|$0:$x{a6}$n")' $srcdir/testdata/grepinputv >>testtrygrep
  792. if [ $nonfork = 1 ] ; then
  793. $cf $srcdir/testdata/grepoutputCNU testtrygrep
  794. else
  795. $cf $srcdir/testdata/grepoutputCU testtrygrep
  796. fi
  797. if [ $? != 0 ] ; then exit 1; fi
  798. fi
  799. else
  800. echo "Script callouts are not supported"
  801. fi
  802. # Test reading .gz and .bz2 files when supported.
  803. if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q '\.gz are read using zlib'; then
  804. echo "Testing reading .gz file"
  805. $valgrind $vjs $pcre2grep 'one|two' $srcdir/testdata/grepinputC.gz >testtrygrep
  806. echo "RC=$?" >>testtrygrep
  807. $cf $srcdir/testdata/grepoutputCgz testtrygrep
  808. if [ $? != 0 ] ; then exit 1; fi
  809. fi
  810. if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q '\.bz2 are read using bzlib2'; then
  811. echo "Testing reading .bz2 file"
  812. $valgrind $vjs $pcre2grep 'one|two' $srcdir/testdata/grepinputC.bz2 >testtrygrep
  813. echo "RC=$?" >>testtrygrep
  814. $valgrind $vjs $pcre2grep 'one|two' $srcdir/testdata/grepnot.bz2 >>testtrygrep
  815. echo "RC=$?" >>testtrygrep
  816. $cf $srcdir/testdata/grepoutputCbz2 testtrygrep
  817. if [ $? != 0 ] ; then exit 1; fi
  818. fi
  819. # Finally, some tests to exercise code that is not tested above, just to be
  820. # sure that it runs OK. Doing this improves the coverage statistics. The output
  821. # is not checked.
  822. echo "Testing miscellaneous pcre2grep arguments (unchecked)"
  823. echo '' >testtrygrep
  824. checkspecial '-xxxxx' 2
  825. checkspecial '--help' 0
  826. checkspecial '--line-buffered --colour=auto abc /dev/null' 1
  827. checkspecial '--line-buffered --color abc /dev/null' 1
  828. checkspecial '-dskip abc .' 1
  829. checkspecial '-Dread -Dskip abc /dev/null' 1
  830. # Clean up local working files
  831. rm -f testNinputgrep teststderrgrep testtrygrep testtemp1grep testtemp2grep
  832. exit 0
  833. # End