RunGrepTest 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  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. # If this test is being run from "make check", $srcdir will be set. If not, set
  57. # it to the current or parent directory, whichever one contains the test data.
  58. # Subsequently, we run most of the pcre2grep tests in the source directory so
  59. # that the file names in the output are always the same.
  60. if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
  61. if [ -d "./testdata" ] ; then
  62. srcdir=.
  63. elif [ -d "../testdata" ] ; then
  64. srcdir=..
  65. else
  66. echo "Cannot find the testdata directory"
  67. exit 1
  68. fi
  69. fi
  70. # Check for the availability of UTF-8 support
  71. $pcre2test -C unicode >/dev/null
  72. utf8=$?
  73. # Check default newline convention. If it does not include LF, force LF.
  74. nl=`$pcre2test -C newline`
  75. if [ "$nl" != "LF" -a "$nl" != "ANY" -a "$nl" != "ANYCRLF" ]; then
  76. pcre2grep="$pcre2grep -N LF"
  77. echo "Default newline setting forced to LF"
  78. fi
  79. # ------ Function to run and check a special pcre2grep arguments test -------
  80. checkspecial()
  81. {
  82. $valgrind $pcre2grep $1 >>testtrygrep 2>&1
  83. if [ $? -ne $2 ] ; then
  84. echo "** pcre2grep $1 failed - check testtrygrep"
  85. exit 1
  86. fi
  87. }
  88. # ------ Normal tests ------
  89. echo "Testing pcre2grep main features"
  90. echo "---------------------------- Test 1 ------------------------------" >testtrygrep
  91. (cd $srcdir; $valgrind $vjs $pcre2grep PATTERN ./testdata/grepinput) >>testtrygrep
  92. echo "RC=$?" >>testtrygrep
  93. echo "---------------------------- Test 2 ------------------------------" >>testtrygrep
  94. (cd $srcdir; $valgrind $vjs $pcre2grep '^PATTERN' ./testdata/grepinput) >>testtrygrep
  95. echo "RC=$?" >>testtrygrep
  96. echo "---------------------------- Test 3 ------------------------------" >>testtrygrep
  97. (cd $srcdir; $valgrind $vjs $pcre2grep -in PATTERN ./testdata/grepinput) >>testtrygrep
  98. echo "RC=$?" >>testtrygrep
  99. echo "---------------------------- Test 4 ------------------------------" >>testtrygrep
  100. (cd $srcdir; $valgrind $vjs $pcre2grep -ic PATTERN ./testdata/grepinput) >>testtrygrep
  101. echo "RC=$?" >>testtrygrep
  102. echo "---------------------------- Test 5 ------------------------------" >>testtrygrep
  103. (cd $srcdir; $valgrind $vjs $pcre2grep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  104. echo "RC=$?" >>testtrygrep
  105. echo "---------------------------- Test 6 ------------------------------" >>testtrygrep
  106. (cd $srcdir; $valgrind $vjs $pcre2grep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  107. echo "RC=$?" >>testtrygrep
  108. echo "---------------------------- Test 7 ------------------------------" >>testtrygrep
  109. (cd $srcdir; $valgrind $vjs $pcre2grep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  110. echo "RC=$?" >>testtrygrep
  111. echo "---------------------------- Test 8 ------------------------------" >>testtrygrep
  112. (cd $srcdir; $valgrind $vjs $pcre2grep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  113. echo "RC=$?" >>testtrygrep
  114. echo "---------------------------- Test 9 ------------------------------" >>testtrygrep
  115. (cd $srcdir; $valgrind $vjs $pcre2grep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  116. echo "RC=$?" >>testtrygrep
  117. echo "---------------------------- Test 10 -----------------------------" >>testtrygrep
  118. (cd $srcdir; $valgrind $vjs $pcre2grep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  119. echo "RC=$?" >>testtrygrep
  120. echo "---------------------------- Test 11 -----------------------------" >>testtrygrep
  121. (cd $srcdir; $valgrind $vjs $pcre2grep -vn pattern ./testdata/grepinputx) >>testtrygrep
  122. echo "RC=$?" >>testtrygrep
  123. echo "---------------------------- Test 12 -----------------------------" >>testtrygrep
  124. (cd $srcdir; $valgrind $vjs $pcre2grep -ix pattern ./testdata/grepinputx) >>testtrygrep
  125. echo "RC=$?" >>testtrygrep
  126. echo "---------------------------- Test 13 -----------------------------" >>testtrygrep
  127. echo seventeen >testtemp1grep
  128. (cd $srcdir; $valgrind $vjs $pcre2grep -f./testdata/greplist -f $builddir/testtemp1grep ./testdata/grepinputx) >>testtrygrep
  129. echo "RC=$?" >>testtrygrep
  130. echo "---------------------------- Test 14 -----------------------------" >>testtrygrep
  131. (cd $srcdir; $valgrind $vjs $pcre2grep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  132. echo "RC=$?" >>testtrygrep
  133. echo "---------------------------- Test 15 -----------------------------" >>testtrygrep
  134. (cd $srcdir; $valgrind $vjs $pcre2grep 'abc^*' ./testdata/grepinput) >>testtrygrep 2>&1
  135. echo "RC=$?" >>testtrygrep
  136. echo "---------------------------- Test 16 -----------------------------" >>testtrygrep
  137. (cd $srcdir; $valgrind $vjs $pcre2grep abc ./testdata/grepinput ./testdata/nonexistfile) >>testtrygrep 2>&1
  138. echo "RC=$?" >>testtrygrep
  139. echo "---------------------------- Test 17 -----------------------------" >>testtrygrep
  140. (cd $srcdir; $valgrind $vjs $pcre2grep -M 'the\noutput' ./testdata/grepinput) >>testtrygrep
  141. echo "RC=$?" >>testtrygrep
  142. echo "---------------------------- Test 18 -----------------------------" >>testtrygrep
  143. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtrygrep
  144. echo "RC=$?" >>testtrygrep
  145. echo "---------------------------- Test 19 -----------------------------" >>testtrygrep
  146. (cd $srcdir; $valgrind $vjs $pcre2grep -Mix 'Pattern' ./testdata/grepinputx) >>testtrygrep
  147. echo "RC=$?" >>testtrygrep
  148. echo "---------------------------- Test 20 -----------------------------" >>testtrygrep
  149. (cd $srcdir; $valgrind $vjs $pcre2grep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtrygrep
  150. echo "RC=$?" >>testtrygrep
  151. echo "---------------------------- Test 21 -----------------------------" >>testtrygrep
  152. (cd $srcdir; $valgrind $vjs $pcre2grep -nA3 'four' ./testdata/grepinputx) >>testtrygrep
  153. echo "RC=$?" >>testtrygrep
  154. echo "---------------------------- Test 22 -----------------------------" >>testtrygrep
  155. (cd $srcdir; $valgrind $vjs $pcre2grep -nB3 'four' ./testdata/grepinputx) >>testtrygrep
  156. echo "RC=$?" >>testtrygrep
  157. echo "---------------------------- Test 23 -----------------------------" >>testtrygrep
  158. (cd $srcdir; $valgrind $vjs $pcre2grep -C3 'four' ./testdata/grepinputx) >>testtrygrep
  159. echo "RC=$?" >>testtrygrep
  160. echo "---------------------------- Test 24 -----------------------------" >>testtrygrep
  161. (cd $srcdir; $valgrind $vjs $pcre2grep -A9 'four' ./testdata/grepinputx) >>testtrygrep
  162. echo "RC=$?" >>testtrygrep
  163. echo "---------------------------- Test 25 -----------------------------" >>testtrygrep
  164. (cd $srcdir; $valgrind $vjs $pcre2grep -nB9 'four' ./testdata/grepinputx) >>testtrygrep
  165. echo "RC=$?" >>testtrygrep
  166. echo "---------------------------- Test 26 -----------------------------" >>testtrygrep
  167. (cd $srcdir; $valgrind $vjs $pcre2grep -A9 -B9 'four' ./testdata/grepinputx) >>testtrygrep
  168. echo "RC=$?" >>testtrygrep
  169. echo "---------------------------- Test 27 -----------------------------" >>testtrygrep
  170. (cd $srcdir; $valgrind $vjs $pcre2grep -A10 'four' ./testdata/grepinputx) >>testtrygrep
  171. echo "RC=$?" >>testtrygrep
  172. echo "---------------------------- Test 28 -----------------------------" >>testtrygrep
  173. (cd $srcdir; $valgrind $vjs $pcre2grep -nB10 'four' ./testdata/grepinputx) >>testtrygrep
  174. echo "RC=$?" >>testtrygrep
  175. echo "---------------------------- Test 29 -----------------------------" >>testtrygrep
  176. (cd $srcdir; $valgrind $vjs $pcre2grep -C12 -B10 'four' ./testdata/grepinputx) >>testtrygrep
  177. echo "RC=$?" >>testtrygrep
  178. echo "---------------------------- Test 30 -----------------------------" >>testtrygrep
  179. (cd $srcdir; $valgrind $vjs $pcre2grep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  180. echo "RC=$?" >>testtrygrep
  181. echo "---------------------------- Test 31 -----------------------------" >>testtrygrep
  182. (cd $srcdir; $valgrind $vjs $pcre2grep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  183. echo "RC=$?" >>testtrygrep
  184. echo "---------------------------- Test 32 -----------------------------" >>testtrygrep
  185. (cd $srcdir; $valgrind $vjs $pcre2grep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  186. echo "RC=$?" >>testtrygrep
  187. echo "---------------------------- Test 33 -----------------------------" >>testtrygrep
  188. (cd $srcdir; $valgrind $vjs $pcre2grep 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
  189. echo "RC=$?" >>testtrygrep
  190. echo "---------------------------- Test 34 -----------------------------" >>testtrygrep
  191. (cd $srcdir; $valgrind $vjs $pcre2grep -s 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
  192. echo "RC=$?" >>testtrygrep
  193. echo "---------------------------- Test 35 -----------------------------" >>testtrygrep
  194. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinputx --include grepinput8 --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  195. echo "RC=$?" >>testtrygrep
  196. echo "---------------------------- Test 36 -----------------------------" >>testtrygrep
  197. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinput --exclude 'grepinput$' --exclude=grepinput8 --exclude=grepinputM --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  198. echo "RC=$?" >>testtrygrep
  199. echo "---------------------------- Test 37 -----------------------------" >>testtrygrep
  200. (cd $srcdir; $valgrind $vjs $pcre2grep '^(a+)*\d' ./testdata/grepinput) >>testtrygrep 2>teststderrgrep
  201. echo "RC=$?" >>testtrygrep
  202. echo "======== STDERR ========" >>testtrygrep
  203. cat teststderrgrep >>testtrygrep
  204. echo "---------------------------- Test 38 ------------------------------" >>testtrygrep
  205. (cd $srcdir; $valgrind $vjs $pcre2grep '>\x00<' ./testdata/grepinput) >>testtrygrep
  206. echo "RC=$?" >>testtrygrep
  207. echo "---------------------------- Test 39 ------------------------------" >>testtrygrep
  208. (cd $srcdir; $valgrind $vjs $pcre2grep -A1 'before the binary zero' ./testdata/grepinput) >>testtrygrep
  209. echo "RC=$?" >>testtrygrep
  210. echo "---------------------------- Test 40 ------------------------------" >>testtrygrep
  211. (cd $srcdir; $valgrind $vjs $pcre2grep -B1 'after the binary zero' ./testdata/grepinput) >>testtrygrep
  212. echo "RC=$?" >>testtrygrep
  213. echo "---------------------------- Test 41 ------------------------------" >>testtrygrep
  214. (cd $srcdir; $valgrind $vjs $pcre2grep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
  215. echo "RC=$?" >>testtrygrep
  216. echo "---------------------------- Test 42 ------------------------------" >>testtrygrep
  217. (cd $srcdir; $valgrind $vjs $pcre2grep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
  218. echo "RC=$?" >>testtrygrep
  219. echo "---------------------------- Test 43 ------------------------------" >>testtrygrep
  220. (cd $srcdir; $valgrind $vjs $pcre2grep -on 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  221. echo "RC=$?" >>testtrygrep
  222. echo "---------------------------- Test 44 ------------------------------" >>testtrygrep
  223. (cd $srcdir; $valgrind $vjs $pcre2grep -on -e before -ezero -e after ./testdata/grepinput) >>testtrygrep
  224. echo "RC=$?" >>testtrygrep
  225. echo "---------------------------- Test 45 ------------------------------" >>testtrygrep
  226. (cd $srcdir; $valgrind $vjs $pcre2grep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtrygrep
  227. echo "RC=$?" >>testtrygrep
  228. echo "---------------------------- Test 46 ------------------------------" >>testtrygrep
  229. (cd $srcdir; $valgrind $vjs $pcre2grep -eabc -e '(unclosed' ./testdata/grepinput) >>testtrygrep 2>&1
  230. echo "RC=$?" >>testtrygrep
  231. echo "---------------------------- Test 47 ------------------------------" >>testtrygrep
  232. (cd $srcdir; $valgrind $vjs $pcre2grep -Fx "AB.VE
  233. elephant" ./testdata/grepinput) >>testtrygrep
  234. echo "RC=$?" >>testtrygrep
  235. echo "---------------------------- Test 48 ------------------------------" >>testtrygrep
  236. (cd $srcdir; $valgrind $vjs $pcre2grep -F "AB.VE
  237. elephant" ./testdata/grepinput) >>testtrygrep
  238. echo "RC=$?" >>testtrygrep
  239. echo "---------------------------- Test 49 ------------------------------" >>testtrygrep
  240. (cd $srcdir; $valgrind $vjs $pcre2grep -F -e DATA -e "AB.VE
  241. elephant" ./testdata/grepinput) >>testtrygrep
  242. echo "RC=$?" >>testtrygrep
  243. echo "---------------------------- Test 50 ------------------------------" >>testtrygrep
  244. (cd $srcdir; $valgrind $vjs $pcre2grep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtrygrep
  245. echo "RC=$?" >>testtrygrep
  246. echo "---------------------------- Test 51 ------------------------------" >>testtrygrep
  247. (cd $srcdir; $valgrind $vjs $pcre2grep -Mv "brown\sfox" ./testdata/grepinputv) >>testtrygrep
  248. echo "RC=$?" >>testtrygrep
  249. echo "---------------------------- Test 52 ------------------------------" >>testtrygrep
  250. (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always jumps ./testdata/grepinputv) >>testtrygrep
  251. echo "RC=$?" >>testtrygrep
  252. echo "---------------------------- Test 53 ------------------------------" >>testtrygrep
  253. (cd $srcdir; $valgrind $vjs $pcre2grep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  254. echo "RC=$?" >>testtrygrep
  255. echo "---------------------------- Test 54 ------------------------------" >>testtrygrep
  256. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  257. echo "RC=$?" >>testtrygrep
  258. echo "---------------------------- Test 55 -----------------------------" >>testtrygrep
  259. (cd $srcdir; $valgrind $vjs $pcre2grep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtrygrep
  260. echo "RC=$?" >>testtrygrep
  261. echo "---------------------------- Test 56 -----------------------------" >>testtrygrep
  262. (cd $srcdir; $valgrind $vjs $pcre2grep -c lazy ./testdata/grepinput*) >>testtrygrep
  263. echo "RC=$?" >>testtrygrep
  264. echo "---------------------------- Test 57 -----------------------------" >>testtrygrep
  265. (cd $srcdir; $valgrind $vjs $pcre2grep -c -l lazy ./testdata/grepinput*) >>testtrygrep
  266. echo "RC=$?" >>testtrygrep
  267. echo "---------------------------- Test 58 -----------------------------" >>testtrygrep
  268. (cd $srcdir; $valgrind $vjs $pcre2grep --regex=PATTERN ./testdata/grepinput) >>testtrygrep
  269. echo "RC=$?" >>testtrygrep
  270. echo "---------------------------- Test 59 -----------------------------" >>testtrygrep
  271. (cd $srcdir; $valgrind $vjs $pcre2grep --regexp=PATTERN ./testdata/grepinput) >>testtrygrep
  272. echo "RC=$?" >>testtrygrep
  273. echo "---------------------------- Test 60 -----------------------------" >>testtrygrep
  274. (cd $srcdir; $valgrind $vjs $pcre2grep --regex PATTERN ./testdata/grepinput) >>testtrygrep
  275. echo "RC=$?" >>testtrygrep
  276. echo "---------------------------- Test 61 -----------------------------" >>testtrygrep
  277. (cd $srcdir; $valgrind $vjs $pcre2grep --regexp PATTERN ./testdata/grepinput) >>testtrygrep
  278. echo "RC=$?" >>testtrygrep
  279. echo "---------------------------- Test 62 -----------------------------" >>testtrygrep
  280. (cd $srcdir; $valgrind $pcre2grep --match-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
  281. echo "RC=$?" >>testtrygrep
  282. echo "---------------------------- Test 63 -----------------------------" >>testtrygrep
  283. (cd $srcdir; $valgrind $pcre2grep --recursion-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
  284. echo "RC=$?" >>testtrygrep
  285. echo "---------------------------- Test 64 ------------------------------" >>testtrygrep
  286. (cd $srcdir; $valgrind $vjs $pcre2grep -o1 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  287. echo "RC=$?" >>testtrygrep
  288. echo "---------------------------- Test 65 ------------------------------" >>testtrygrep
  289. (cd $srcdir; $valgrind $vjs $pcre2grep -o2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  290. echo "RC=$?" >>testtrygrep
  291. echo "---------------------------- Test 66 ------------------------------" >>testtrygrep
  292. (cd $srcdir; $valgrind $vjs $pcre2grep -o3 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  293. echo "RC=$?" >>testtrygrep
  294. echo "---------------------------- Test 67 ------------------------------" >>testtrygrep
  295. (cd $srcdir; $valgrind $vjs $pcre2grep -o12 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  296. echo "RC=$?" >>testtrygrep
  297. echo "---------------------------- Test 68 ------------------------------" >>testtrygrep
  298. (cd $srcdir; $valgrind $vjs $pcre2grep --only-matching=2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  299. echo "RC=$?" >>testtrygrep
  300. echo "---------------------------- Test 69 -----------------------------" >>testtrygrep
  301. (cd $srcdir; $valgrind $vjs $pcre2grep -vn --colour=always pattern ./testdata/grepinputx) >>testtrygrep
  302. echo "RC=$?" >>testtrygrep
  303. echo "---------------------------- Test 70 -----------------------------" >>testtrygrep
  304. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always -M "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  305. echo "RC=$?" >>testtrygrep
  306. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always -M -n "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  307. echo "RC=$?" >>testtrygrep
  308. (cd $srcdir; $valgrind $vjs $pcre2grep -M "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  309. echo "RC=$?" >>testtrygrep
  310. (cd $srcdir; $valgrind $vjs $pcre2grep -M -n "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  311. echo "RC=$?" >>testtrygrep
  312. echo "---------------------------- Test 71 -----------------------------" >>testtrygrep
  313. (cd $srcdir; $valgrind $vjs $pcre2grep -o "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  314. echo "RC=$?" >>testtrygrep
  315. echo "---------------------------- Test 72 -----------------------------" >>testtrygrep
  316. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  317. echo "RC=$?" >>testtrygrep
  318. echo "---------------------------- Test 73 -----------------------------" >>testtrygrep
  319. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  320. echo "RC=$?" >>testtrygrep
  321. echo "---------------------------- Test 74 -----------------------------" >>testtrygrep
  322. (cd $srcdir; $valgrind $vjs $pcre2grep -o "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  323. echo "RC=$?" >>testtrygrep
  324. echo "---------------------------- Test 75 -----------------------------" >>testtrygrep
  325. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  326. echo "RC=$?" >>testtrygrep
  327. echo "---------------------------- Test 76 -----------------------------" >>testtrygrep
  328. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  329. echo "RC=$?" >>testtrygrep
  330. echo "---------------------------- Test 77 -----------------------------" >>testtrygrep
  331. (cd $srcdir; $valgrind $vjs $pcre2grep -o "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  332. echo "RC=$?" >>testtrygrep
  333. echo "---------------------------- Test 78 -----------------------------" >>testtrygrep
  334. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  335. echo "RC=$?" >>testtrygrep
  336. echo "---------------------------- Test 79 -----------------------------" >>testtrygrep
  337. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  338. echo "RC=$?" >>testtrygrep
  339. echo "---------------------------- Test 80 -----------------------------" >>testtrygrep
  340. (cd $srcdir; $valgrind $vjs $pcre2grep -o "\b01|\b02" ./testdata/grepinput) >>testtrygrep
  341. echo "RC=$?" >>testtrygrep
  342. echo "---------------------------- Test 81 -----------------------------" >>testtrygrep
  343. (cd $srcdir; $valgrind $vjs $pcre2grep --color=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
  344. echo "RC=$?" >>testtrygrep
  345. echo "---------------------------- Test 82 -----------------------------" >>testtrygrep
  346. (cd $srcdir; $valgrind $vjs $pcre2grep -o --colour=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
  347. echo "RC=$?" >>testtrygrep
  348. echo "---------------------------- Test 83 -----------------------------" >>testtrygrep
  349. (cd $srcdir; $valgrind $vjs $pcre2grep --buffer-size=10 --max-buffer-size=100 "^a" ./testdata/grepinput3) >>testtrygrep 2>&1
  350. echo "RC=$?" >>testtrygrep
  351. echo "---------------------------- Test 84 -----------------------------" >>testtrygrep
  352. echo testdata/grepinput3 >testtemp1grep
  353. (cd $srcdir; $valgrind $vjs $pcre2grep --file-list ./testdata/grepfilelist --file-list $builddir/testtemp1grep "fox|complete|t7") >>testtrygrep 2>&1
  354. echo "RC=$?" >>testtrygrep
  355. echo "---------------------------- Test 85 -----------------------------" >>testtrygrep
  356. (cd $srcdir; $valgrind $vjs $pcre2grep --file-list=./testdata/grepfilelist "dolor" ./testdata/grepinput3) >>testtrygrep 2>&1
  357. echo "RC=$?" >>testtrygrep
  358. echo "---------------------------- Test 86 -----------------------------" >>testtrygrep
  359. (cd $srcdir; $valgrind $vjs $pcre2grep "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  360. echo "RC=$?" >>testtrygrep
  361. echo "---------------------------- Test 87 -----------------------------" >>testtrygrep
  362. (cd $srcdir; $valgrind $vjs $pcre2grep "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
  363. echo "RC=$?" >>testtrygrep
  364. echo "---------------------------- Test 88 -----------------------------" >>testtrygrep
  365. (cd $srcdir; $valgrind $vjs $pcre2grep -v "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
  366. echo "RC=$?" >>testtrygrep
  367. echo "---------------------------- Test 89 -----------------------------" >>testtrygrep
  368. (cd $srcdir; $valgrind $vjs $pcre2grep -I "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  369. echo "RC=$?" >>testtrygrep
  370. echo "---------------------------- Test 90 -----------------------------" >>testtrygrep
  371. (cd $srcdir; $valgrind $vjs $pcre2grep --binary-files=without-match "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  372. echo "RC=$?" >>testtrygrep
  373. echo "---------------------------- Test 91 -----------------------------" >>testtrygrep
  374. (cd $srcdir; $valgrind $vjs $pcre2grep -a "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  375. echo "RC=$?" >>testtrygrep
  376. echo "---------------------------- Test 92 -----------------------------" >>testtrygrep
  377. (cd $srcdir; $valgrind $vjs $pcre2grep --binary-files=text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  378. echo "RC=$?" >>testtrygrep
  379. echo "---------------------------- Test 93 -----------------------------" >>testtrygrep
  380. (cd $srcdir; $valgrind $vjs $pcre2grep --text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  381. echo "RC=$?" >>testtrygrep
  382. echo "---------------------------- Test 94 -----------------------------" >>testtrygrep
  383. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinputx --include grepinput8 'fox' ./testdata/grepinput* | sort) >>testtrygrep
  384. echo "RC=$?" >>testtrygrep
  385. echo "---------------------------- Test 95 -----------------------------" >>testtrygrep
  386. (cd $srcdir; $valgrind $vjs $pcre2grep --file-list ./testdata/grepfilelist --exclude grepinputv "fox|complete") >>testtrygrep 2>&1
  387. echo "RC=$?" >>testtrygrep
  388. echo "---------------------------- Test 96 -----------------------------" >>testtrygrep
  389. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include-dir=testdata --exclude '^(?!grepinput)' --exclude=grepinputM 'fox' ./test* | sort) >>testtrygrep
  390. echo "RC=$?" >>testtrygrep
  391. echo "---------------------------- Test 97 -----------------------------" >>testtrygrep
  392. echo "grepinput$" >testtemp1grep
  393. echo "grepinput8" >>testtemp1grep
  394. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinput --exclude=grepinputM --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  395. echo "RC=$?" >>testtrygrep
  396. echo "---------------------------- Test 98 -----------------------------" >>testtrygrep
  397. echo "grepinput$" >testtemp1grep
  398. echo "grepinput8" >>testtemp1grep
  399. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --exclude=grepinput3 --exclude=grepinputM --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  400. echo "RC=$?" >>testtrygrep
  401. echo "---------------------------- Test 99 -----------------------------" >>testtrygrep
  402. echo "grepinput$" >testtemp1grep
  403. echo "grepinput8" >testtemp2grep
  404. (cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include grepinput --exclude=grepinputM --exclude-from $builddir/testtemp1grep --exclude-from=$builddir/testtemp2grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  405. echo "RC=$?" >>testtrygrep
  406. echo "---------------------------- Test 100 ------------------------------" >>testtrygrep
  407. (cd $srcdir; $valgrind $vjs $pcre2grep -Ho2 --only-matching=1 -o3 '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  408. echo "RC=$?" >>testtrygrep
  409. echo "---------------------------- Test 101 ------------------------------" >>testtrygrep
  410. (cd $srcdir; $valgrind $vjs $pcre2grep -o3 -Ho2 -o12 --only-matching=1 -o3 --colour=always --om-separator='|' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  411. echo "RC=$?" >>testtrygrep
  412. echo "---------------------------- Test 102 -----------------------------" >>testtrygrep
  413. (cd $srcdir; $valgrind $vjs $pcre2grep -n "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  414. echo "RC=$?" >>testtrygrep
  415. echo "---------------------------- Test 103 -----------------------------" >>testtrygrep
  416. (cd $srcdir; $valgrind $vjs $pcre2grep --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  417. echo "RC=$?" >>testtrygrep
  418. echo "---------------------------- Test 104 -----------------------------" >>testtrygrep
  419. (cd $srcdir; $valgrind $vjs $pcre2grep -n --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  420. echo "RC=$?" >>testtrygrep
  421. echo "---------------------------- Test 105 -----------------------------" >>testtrygrep
  422. (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always "ipsum|" ./testdata/grepinput3) >>testtrygrep 2>&1
  423. echo "RC=$?" >>testtrygrep
  424. echo "---------------------------- Test 106 -----------------------------" >>testtrygrep
  425. (cd $srcdir; echo "a" | $valgrind $vjs $pcre2grep -M "|a" ) >>testtrygrep 2>&1
  426. echo "RC=$?" >>testtrygrep
  427. echo "---------------------------- Test 107 -----------------------------" >>testtrygrep
  428. echo "a" >testtemp1grep
  429. echo "aaaaa" >>testtemp1grep
  430. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets --allow-lookaround-bsk '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
  431. echo "RC=$?" >>testtrygrep
  432. echo "---------------------------- Test 108 ------------------------------" >>testtrygrep
  433. (cd $srcdir; $valgrind $vjs $pcre2grep -lq PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  434. echo "RC=$?" >>testtrygrep
  435. echo "---------------------------- Test 109 -----------------------------" >>testtrygrep
  436. (cd $srcdir; $valgrind $vjs $pcre2grep -cq lazy ./testdata/grepinput*) >>testtrygrep
  437. echo "RC=$?" >>testtrygrep
  438. echo "---------------------------- Test 110 -----------------------------" >>testtrygrep
  439. (cd $srcdir; $valgrind $vjs $pcre2grep --om-separator / -Mo0 -o1 -o2 'match (\d+):\n (.)\n' testdata/grepinput) >>testtrygrep
  440. echo "RC=$?" >>testtrygrep
  441. echo "---------------------------- Test 111 -----------------------------" >>testtrygrep
  442. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets -M 'match (\d+):\n (.)\n' testdata/grepinput) >>testtrygrep
  443. echo "RC=$?" >>testtrygrep
  444. echo "---------------------------- Test 112 -----------------------------" >>testtrygrep
  445. (cd $srcdir; $valgrind $vjs $pcre2grep --file-offsets -M 'match (\d+):\n (.)\n' testdata/grepinput) >>testtrygrep
  446. echo "RC=$?" >>testtrygrep
  447. echo "---------------------------- Test 113 -----------------------------" >>testtrygrep
  448. (cd $srcdir; $valgrind $vjs $pcre2grep --total-count 'the' testdata/grepinput*) >>testtrygrep
  449. echo "RC=$?" >>testtrygrep
  450. echo "---------------------------- Test 114 -----------------------------" >>testtrygrep
  451. (cd $srcdir; $valgrind $vjs $pcre2grep -tc 'the' testdata/grepinput*) >>testtrygrep
  452. echo "RC=$?" >>testtrygrep
  453. echo "---------------------------- Test 115 -----------------------------" >>testtrygrep
  454. (cd $srcdir; $valgrind $vjs $pcre2grep -tlc 'the' testdata/grepinput*) >>testtrygrep
  455. echo "RC=$?" >>testtrygrep
  456. echo "---------------------------- Test 116 -----------------------------" >>testtrygrep
  457. (cd $srcdir; $valgrind $vjs $pcre2grep --exclude=grepinputM -th 'the' testdata/grepinput*) >>testtrygrep
  458. echo "RC=$?" >>testtrygrep
  459. echo "---------------------------- Test 117 -----------------------------" >>testtrygrep
  460. (cd $srcdir; $valgrind $vjs $pcre2grep -tch 'the' testdata/grepinput*) >>testtrygrep
  461. echo "RC=$?" >>testtrygrep
  462. echo "---------------------------- Test 118 -----------------------------" >>testtrygrep
  463. (cd $srcdir; $valgrind $vjs $pcre2grep -tL 'the' testdata/grepinput*) >>testtrygrep
  464. echo "RC=$?" >>testtrygrep
  465. echo "---------------------------- Test 119 -----------------------------" >>testtrygrep
  466. printf '123\n456\n789\n---abc\ndef\nxyz\n---\n' >testNinputgrep
  467. $valgrind $vjs $pcre2grep -Mo '(\n|[^-])*---' testNinputgrep >>testtrygrep
  468. echo "RC=$?" >>testtrygrep
  469. echo "---------------------------- Test 120 ------------------------------" >>testtrygrep
  470. (cd $srcdir; $valgrind $vjs $pcre2grep -HO '$0:$2$1$3' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  471. echo "RC=$?" >>testtrygrep
  472. echo "---------------------------- Test 121 -----------------------------" >>testtrygrep
  473. (cd $srcdir; $valgrind $vjs $pcre2grep -F '\E and (regex)' testdata/grepinputv) >>testtrygrep
  474. echo "RC=$?" >>testtrygrep
  475. echo "---------------------------- Test 122 -----------------------------" >>testtrygrep
  476. (cd $srcdir; $valgrind $vjs $pcre2grep -w 'cat|dog' testdata/grepinputv) >>testtrygrep
  477. echo "RC=$?" >>testtrygrep
  478. echo "---------------------------- Test 123 -----------------------------" >>testtrygrep
  479. (cd $srcdir; $valgrind $vjs $pcre2grep -w 'dog|cat' testdata/grepinputv) >>testtrygrep
  480. echo "RC=$?" >>testtrygrep
  481. echo "---------------------------- Test 124 -----------------------------" >>testtrygrep
  482. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn --colour=always 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  483. echo "RC=$?" >>testtrygrep
  484. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn --colour=always -A2 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  485. echo "RC=$?" >>testtrygrep
  486. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  487. echo "RC=$?" >>testtrygrep
  488. (cd $srcdir; $valgrind $vjs $pcre2grep -Mn -A2 'start[\s]+end' testdata/grepinputM) >>testtrygrep
  489. echo "RC=$?" >>testtrygrep
  490. echo "---------------------------- Test 125 -----------------------------" >>testtrygrep
  491. printf 'abcd\n' >testNinputgrep
  492. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?<=\K.)' testNinputgrep >>testtrygrep
  493. echo "RC=$?" >>testtrygrep
  494. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?=.\K)' testNinputgrep >>testtrygrep
  495. echo "RC=$?" >>testtrygrep
  496. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?<=\K[ac])' testNinputgrep >>testtrygrep
  497. echo "RC=$?" >>testtrygrep
  498. $valgrind $vjs $pcre2grep --colour=always --allow-lookaround-bsk '(?=[ac]\K)' testNinputgrep >>testtrygrep
  499. echo "RC=$?" >>testtrygrep
  500. echo "---------------------------- Test 126 -----------------------------" >>testtrygrep
  501. printf 'Next line pattern has binary zero\nABC\0XYZ\n' >testtemp1grep
  502. printf 'ABC\0XYZ\nABCDEF\nDEFABC\n' >testtemp2grep
  503. $valgrind $vjs $pcre2grep -a -f testtemp1grep testtemp2grep >>testtrygrep
  504. echo "RC=$?" >>testtrygrep
  505. echo "---------------------------- Test 127 -----------------------------" >>testtrygrep
  506. (cd $srcdir; $valgrind $vjs $pcre2grep -o --om-capture=0 'pattern()()()()' testdata/grepinput) >>testtrygrep
  507. echo "RC=$?" >>testtrygrep
  508. echo "---------------------------- Test 128 -----------------------------" >>testtrygrep
  509. (cd $srcdir; $valgrind $vjs $pcre2grep -o1 --om-capture=0 'pattern()()()()' testdata/grepinput) >>testtrygrep 2>&1
  510. echo "RC=$?" >>testtrygrep
  511. echo "---------------------------- Test 129 -----------------------------" >>testtrygrep
  512. (cd $srcdir; $valgrind $vjs $pcre2grep -m 2 'fox' testdata/grepinput) >>testtrygrep 2>&1
  513. echo "RC=$?" >>testtrygrep
  514. echo "---------------------------- Test 130 -----------------------------" >>testtrygrep
  515. (cd $srcdir; $valgrind $vjs $pcre2grep -o -m2 'fox' testdata/grepinput) >>testtrygrep 2>&1
  516. echo "RC=$?" >>testtrygrep
  517. echo "---------------------------- Test 131 -----------------------------" >>testtrygrep
  518. (cd $srcdir; $valgrind $vjs $pcre2grep -oc -m2 'fox' testdata/grepinput) >>testtrygrep 2>&1
  519. echo "RC=$?" >>testtrygrep
  520. echo "---------------------------- Test 132 -----------------------------" >>testtrygrep
  521. (cd $srcdir; $valgrind $vjs $pcre2grep -m1 -A3 '^match'; echo '---'; head -1) <$srcdir/testdata/grepinput >>testtrygrep 2>&1
  522. echo "RC=$?" >>testtrygrep
  523. echo "---------------------------- Test 133 -----------------------------" >>testtrygrep
  524. (cd $srcdir; $valgrind $vjs $pcre2grep -m1 -O '=$x{41}$x423$o{103}$o1045=' 'fox') <$srcdir/testdata/grepinputv >>testtrygrep 2>&1
  525. echo "RC=$?" >>testtrygrep
  526. # Now compare the results.
  527. $cf $srcdir/testdata/grepoutput testtrygrep
  528. if [ $? != 0 ] ; then exit 1; fi
  529. # These tests require UTF-8 support
  530. if [ $utf8 -ne 0 ] ; then
  531. echo "Testing pcre2grep UTF-8 features"
  532. echo "---------------------------- Test U1 ------------------------------" >testtrygrep
  533. (cd $srcdir; $valgrind $vjs $pcre2grep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtrygrep
  534. echo "RC=$?" >>testtrygrep
  535. echo "---------------------------- Test U2 ------------------------------" >>testtrygrep
  536. (cd $srcdir; $valgrind $vjs $pcre2grep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtrygrep
  537. echo "RC=$?" >>testtrygrep
  538. echo "---------------------------- Test U3 ------------------------------" >>testtrygrep
  539. (cd $srcdir; $valgrind $vjs $pcre2grep --line-offsets -u --newline=any --allow-lookaround-bsk '(?<=\K\x{17f})' ./testdata/grepinput8) >>testtrygrep
  540. echo "RC=$?" >>testtrygrep
  541. echo "---------------------------- Test U4 ------------------------------" >>testtrygrep
  542. printf 'A\341\200\200\200CD\342\200\200Z\n' >testtemp1grep
  543. (cd $srcdir; $valgrind $vjs $pcre2grep -u -o '....' $builddir/testtemp1grep) >>testtrygrep 2>&1
  544. echo "RC=$?" >>testtrygrep
  545. echo "---------------------------- Test U5 ------------------------------" >>testtrygrep
  546. printf 'A\341\200\200\200CD\342\200\200Z\n' >testtemp1grep
  547. (cd $srcdir; $valgrind $vjs $pcre2grep -U -o '....' $builddir/testtemp1grep) >>testtrygrep
  548. echo "RC=$?" >>testtrygrep
  549. echo "---------------------------- Test U6 -----------------------------" >>testtrygrep
  550. (cd $srcdir; $valgrind $vjs $pcre2grep -u -m1 -O '=$x{1d3}$o{744}=' 'fox') <$srcdir/testdata/grepinputv >>testtrygrep 2>&1
  551. echo "RC=$?" >>testtrygrep
  552. $cf $srcdir/testdata/grepoutput8 testtrygrep
  553. if [ $? != 0 ] ; then exit 1; fi
  554. else
  555. echo "Skipping pcre2grep UTF-8 tests: no UTF-8 support in PCRE2 library"
  556. fi
  557. # We go to some contortions to try to ensure that the tests for the various
  558. # newline settings will work in environments where the normal newline sequence
  559. # is not \n. Do not use exported files, whose line endings might be changed.
  560. # Instead, create an input file using printf so that its contents are exactly
  561. # what we want. Note the messy fudge to get printf to write a string that
  562. # starts with a hyphen. These tests are run in the build directory.
  563. echo "Testing pcre2grep newline settings"
  564. printf 'abc\rdef\r\nghi\njkl' >testNinputgrep
  565. printf '%c--------------------------- Test N1 ------------------------------\r\n' - >testtrygrep
  566. $valgrind $vjs $pcre2grep -n -N CR "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  567. printf '%c--------------------------- Test N2 ------------------------------\r\n' - >>testtrygrep
  568. $valgrind $vjs $pcre2grep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  569. printf '%c--------------------------- Test N3 ------------------------------\r\n' - >>testtrygrep
  570. pattern=`printf 'def\rjkl'`
  571. $valgrind $vjs $pcre2grep -n --newline=cr -F "$pattern" testNinputgrep >>testtrygrep
  572. printf '%c--------------------------- Test N4 ------------------------------\r\n' - >>testtrygrep
  573. $valgrind $vjs $pcre2grep -n --newline=crlf -F -f $srcdir/testdata/greppatN4 testNinputgrep >>testtrygrep
  574. printf '%c--------------------------- Test N5 ------------------------------\r\n' - >>testtrygrep
  575. $valgrind $vjs $pcre2grep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  576. printf '%c--------------------------- Test N6 ------------------------------\r\n' - >>testtrygrep
  577. $valgrind $vjs $pcre2grep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  578. # This next test involves NUL characters. It seems impossible to handle them
  579. # easily in many operating systems. An earlier version of this script used sed
  580. # to translate NUL into the string ZERO, but this didn't work on Solaris (aka
  581. # SunOS), where the version of sed explicitly doesn't like them, and also MacOS
  582. # (Darwin), OpenBSD, FreeBSD, NetBSD, and some Linux distributions like Alpine,
  583. # even when using GNU sed. A user suggested using tr instead, which
  584. # necessitates translating to a single character (@). However, on (some
  585. # versions of?) Solaris, the normal "tr" cannot handle binary zeros, but if
  586. # /usr/xpg4/bin/tr is available, it can do so, so test for that.
  587. if [ -x /usr/xpg4/bin/tr ] ; then
  588. tr=/usr/xpg4/bin/tr
  589. else
  590. tr=tr
  591. fi
  592. printf '%c--------------------------- Test N7 ------------------------------\r\n' - >>testtrygrep
  593. printf 'abc\0def' >testNinputgrep
  594. $valgrind $vjs $pcre2grep -na --newline=nul "^(abc|def)" testNinputgrep | $tr '\000' '@' >>testtrygrep
  595. echo "" >>testtrygrep
  596. $cf $srcdir/testdata/grepoutputN testtrygrep
  597. if [ $? != 0 ] ; then exit 1; fi
  598. # If pcre2grep supports script callouts, run some tests on them. It is possible
  599. # to restrict these callouts to the non-fork case, either for security, or for
  600. # environments that do not support fork(). This is handled by comparing to a
  601. # different output.
  602. if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'callout scripts in patterns are supported'; then
  603. echo "Testing pcre2grep script callouts"
  604. $valgrind $vjs $pcre2grep '(T)(..(.))(?C"/bin/echo|Arg1: [$1] [$2] [$3]|Arg2: $|${1}$| ($4) ($14) ($0)")()' $srcdir/testdata/grepinputv >testtrygrep
  605. $valgrind $vjs $pcre2grep '(T)(..(.))()()()()()()()(..)(?C"/bin/echo|Arg1: [$11] [${11}]")' $srcdir/testdata/grepinputv >>testtrygrep
  606. $valgrind $vjs $pcre2grep '(T)(?C"|$0:$1$n")' $srcdir/testdata/grepinputv >>testtrygrep
  607. $valgrind $vjs $pcre2grep '(T)(?C"|$1$n")(*F)' $srcdir/testdata/grepinputv >>testtrygrep
  608. $valgrind $vjs $pcre2grep -m1 '(T)(?C"|$0:$1:$x{41}$o{101}$n")' $srcdir/testdata/grepinputv >>testtrygrep
  609. if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'Non-fork callout scripts in patterns are supported'; then
  610. $cf $srcdir/testdata/grepoutputCN testtrygrep
  611. else
  612. $cf $srcdir/testdata/grepoutputC testtrygrep
  613. fi
  614. if [ $? != 0 ] ; then exit 1; fi
  615. else
  616. echo "Script callouts are not supported"
  617. fi
  618. # Finally, some tests to exercise code that is not tested above, just to be
  619. # sure that it runs OK. Doing this improves the coverage statistics. The output
  620. # is not checked.
  621. echo "Testing miscellaneous pcre2grep arguments (unchecked)"
  622. echo '' >testtrygrep
  623. checkspecial '-xxxxx' 2
  624. checkspecial '--help' 0
  625. checkspecial '--line-buffered --colour=auto abc /dev/null' 1
  626. # Clean up local working files
  627. rm -f testNinputgrep teststderrgrep testtrygrep testtemp1grep testtemp2grep
  628. exit 0
  629. # End