RunGrepTest 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. #! /bin/sh
  2. # Run pcregrep tests. The assumption is that the PCRE tests check the library
  3. # itself. What we are checking here is the file handling and options that are
  4. # supported by pcregrep. This script must be run in the build directory.
  5. # Set the C locale, so that sort(1) behaves predictably.
  6. LC_ALL=C
  7. export LC_ALL
  8. # Remove any non-default colouring and aliases that the caller may have set.
  9. unset PCREGREP_COLOUR PCREGREP_COLOR
  10. unset cp ls mv rm
  11. # Remember the current (build) directory, set the program to be tested, and
  12. # valgrind settings when requested.
  13. builddir=`pwd`
  14. pcregrep=$builddir/pcregrep
  15. valgrind=
  16. while [ $# -gt 0 ] ; do
  17. case $1 in
  18. valgrind) valgrind="valgrind -q --leak-check=no --smc-check=all";;
  19. *) echo "RunGrepTest: Unknown argument $1"; exit 1;;
  20. esac
  21. shift
  22. done
  23. echo " "
  24. pcregrep_version=`$pcregrep -V`
  25. if [ "$valgrind" = "" ] ; then
  26. echo "Testing $pcregrep_version"
  27. else
  28. echo "Testing $pcregrep_version using valgrind"
  29. fi
  30. # Set up a suitable "diff" command for comparison. Some systems have a diff
  31. # that lacks a -u option. Try to deal with this; better do the test for the -b
  32. # option as well.
  33. cf="diff"
  34. diff -b /dev/null /dev/null 2>/dev/null && cf="diff -b"
  35. diff -u /dev/null /dev/null 2>/dev/null && cf="diff -u"
  36. diff -ub /dev/null /dev/null 2>/dev/null && cf="diff -ub"
  37. # If this test is being run from "make check", $srcdir will be set. If not, set
  38. # it to the current or parent directory, whichever one contains the test data.
  39. # Subsequently, we run most of the pcregrep tests in the source directory so
  40. # that the file names in the output are always the same.
  41. if [ -z "$srcdir" -o ! -d "$srcdir/testdata" ] ; then
  42. if [ -d "./testdata" ] ; then
  43. srcdir=.
  44. elif [ -d "../testdata" ] ; then
  45. srcdir=..
  46. else
  47. echo "Cannot find the testdata directory"
  48. exit 1
  49. fi
  50. fi
  51. # Check for the availability of UTF-8 support
  52. ./pcretest -C utf >/dev/null
  53. utf8=$?
  54. # We need valgrind suppressions when JIT is in use. (This isn't perfect because
  55. # some tests are run with -no-jit, but as PCRE1 is in maintenance only, I have
  56. # not bothered about that.)
  57. ./pcretest -C jit >/dev/null
  58. if [ $? -eq 1 -a "$valgrind" != "" ] ; then
  59. valgrind="$valgrind --suppressions=./testdata/valgrind-jit.supp"
  60. fi
  61. echo "Testing pcregrep main features"
  62. echo "---------------------------- Test 1 ------------------------------" >testtrygrep
  63. (cd $srcdir; $valgrind $pcregrep PATTERN ./testdata/grepinput) >>testtrygrep
  64. echo "RC=$?" >>testtrygrep
  65. echo "---------------------------- Test 2 ------------------------------" >>testtrygrep
  66. (cd $srcdir; $valgrind $pcregrep '^PATTERN' ./testdata/grepinput) >>testtrygrep
  67. echo "RC=$?" >>testtrygrep
  68. echo "---------------------------- Test 3 ------------------------------" >>testtrygrep
  69. (cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput) >>testtrygrep
  70. echo "RC=$?" >>testtrygrep
  71. echo "---------------------------- Test 4 ------------------------------" >>testtrygrep
  72. (cd $srcdir; $valgrind $pcregrep -ic PATTERN ./testdata/grepinput) >>testtrygrep
  73. echo "RC=$?" >>testtrygrep
  74. echo "---------------------------- Test 5 ------------------------------" >>testtrygrep
  75. (cd $srcdir; $valgrind $pcregrep -in PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  76. echo "RC=$?" >>testtrygrep
  77. echo "---------------------------- Test 6 ------------------------------" >>testtrygrep
  78. (cd $srcdir; $valgrind $pcregrep -inh PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  79. echo "RC=$?" >>testtrygrep
  80. echo "---------------------------- Test 7 ------------------------------" >>testtrygrep
  81. (cd $srcdir; $valgrind $pcregrep -il PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  82. echo "RC=$?" >>testtrygrep
  83. echo "---------------------------- Test 8 ------------------------------" >>testtrygrep
  84. (cd $srcdir; $valgrind $pcregrep -l PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  85. echo "RC=$?" >>testtrygrep
  86. echo "---------------------------- Test 9 ------------------------------" >>testtrygrep
  87. (cd $srcdir; $valgrind $pcregrep -q PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  88. echo "RC=$?" >>testtrygrep
  89. echo "---------------------------- Test 10 -----------------------------" >>testtrygrep
  90. (cd $srcdir; $valgrind $pcregrep -q NEVER-PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  91. echo "RC=$?" >>testtrygrep
  92. echo "---------------------------- Test 11 -----------------------------" >>testtrygrep
  93. (cd $srcdir; $valgrind $pcregrep -vn pattern ./testdata/grepinputx) >>testtrygrep
  94. echo "RC=$?" >>testtrygrep
  95. echo "---------------------------- Test 12 -----------------------------" >>testtrygrep
  96. (cd $srcdir; $valgrind $pcregrep -ix pattern ./testdata/grepinputx) >>testtrygrep
  97. echo "RC=$?" >>testtrygrep
  98. echo "---------------------------- Test 13 -----------------------------" >>testtrygrep
  99. echo seventeen >testtemp1grep
  100. (cd $srcdir; $valgrind $pcregrep -f./testdata/greplist -f $builddir/testtemp1grep ./testdata/grepinputx) >>testtrygrep
  101. echo "RC=$?" >>testtrygrep
  102. echo "---------------------------- Test 14 -----------------------------" >>testtrygrep
  103. (cd $srcdir; $valgrind $pcregrep -w pat ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  104. echo "RC=$?" >>testtrygrep
  105. echo "---------------------------- Test 15 -----------------------------" >>testtrygrep
  106. (cd $srcdir; $valgrind $pcregrep 'abc^*' ./testdata/grepinput) 2>>testtrygrep >>testtrygrep
  107. echo "RC=$?" >>testtrygrep
  108. echo "---------------------------- Test 16 -----------------------------" >>testtrygrep
  109. (cd $srcdir; $valgrind $pcregrep abc ./testdata/grepinput ./testdata/nonexistfile) 2>>testtrygrep >>testtrygrep
  110. echo "RC=$?" >>testtrygrep
  111. echo "---------------------------- Test 17 -----------------------------" >>testtrygrep
  112. (cd $srcdir; $valgrind $pcregrep -M 'the\noutput' ./testdata/grepinput) >>testtrygrep
  113. echo "RC=$?" >>testtrygrep
  114. echo "---------------------------- Test 18 -----------------------------" >>testtrygrep
  115. (cd $srcdir; $valgrind $pcregrep -Mn '(the\noutput|dog\.\n--)' ./testdata/grepinput) >>testtrygrep
  116. echo "RC=$?" >>testtrygrep
  117. echo "---------------------------- Test 19 -----------------------------" >>testtrygrep
  118. (cd $srcdir; $valgrind $pcregrep -Mix 'Pattern' ./testdata/grepinputx) >>testtrygrep
  119. echo "RC=$?" >>testtrygrep
  120. echo "---------------------------- Test 20 -----------------------------" >>testtrygrep
  121. (cd $srcdir; $valgrind $pcregrep -Mixn 'complete pair\nof lines' ./testdata/grepinputx) >>testtrygrep
  122. echo "RC=$?" >>testtrygrep
  123. echo "---------------------------- Test 21 -----------------------------" >>testtrygrep
  124. (cd $srcdir; $valgrind $pcregrep -nA3 'four' ./testdata/grepinputx) >>testtrygrep
  125. echo "RC=$?" >>testtrygrep
  126. echo "---------------------------- Test 22 -----------------------------" >>testtrygrep
  127. (cd $srcdir; $valgrind $pcregrep -nB3 'four' ./testdata/grepinputx) >>testtrygrep
  128. echo "RC=$?" >>testtrygrep
  129. echo "---------------------------- Test 23 -----------------------------" >>testtrygrep
  130. (cd $srcdir; $valgrind $pcregrep -C3 'four' ./testdata/grepinputx) >>testtrygrep
  131. echo "RC=$?" >>testtrygrep
  132. echo "---------------------------- Test 24 -----------------------------" >>testtrygrep
  133. (cd $srcdir; $valgrind $pcregrep -A9 'four' ./testdata/grepinputx) >>testtrygrep
  134. echo "RC=$?" >>testtrygrep
  135. echo "---------------------------- Test 25 -----------------------------" >>testtrygrep
  136. (cd $srcdir; $valgrind $pcregrep -nB9 'four' ./testdata/grepinputx) >>testtrygrep
  137. echo "RC=$?" >>testtrygrep
  138. echo "---------------------------- Test 26 -----------------------------" >>testtrygrep
  139. (cd $srcdir; $valgrind $pcregrep -A9 -B9 'four' ./testdata/grepinputx) >>testtrygrep
  140. echo "RC=$?" >>testtrygrep
  141. echo "---------------------------- Test 27 -----------------------------" >>testtrygrep
  142. (cd $srcdir; $valgrind $pcregrep -A10 'four' ./testdata/grepinputx) >>testtrygrep
  143. echo "RC=$?" >>testtrygrep
  144. echo "---------------------------- Test 28 -----------------------------" >>testtrygrep
  145. (cd $srcdir; $valgrind $pcregrep -nB10 'four' ./testdata/grepinputx) >>testtrygrep
  146. echo "RC=$?" >>testtrygrep
  147. echo "---------------------------- Test 29 -----------------------------" >>testtrygrep
  148. (cd $srcdir; $valgrind $pcregrep -C12 -B10 'four' ./testdata/grepinputx) >>testtrygrep
  149. echo "RC=$?" >>testtrygrep
  150. echo "---------------------------- Test 30 -----------------------------" >>testtrygrep
  151. (cd $srcdir; $valgrind $pcregrep -inB3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  152. echo "RC=$?" >>testtrygrep
  153. echo "---------------------------- Test 31 -----------------------------" >>testtrygrep
  154. (cd $srcdir; $valgrind $pcregrep -inA3 'pattern' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  155. echo "RC=$?" >>testtrygrep
  156. echo "---------------------------- Test 32 -----------------------------" >>testtrygrep
  157. (cd $srcdir; $valgrind $pcregrep -L 'fox' ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  158. echo "RC=$?" >>testtrygrep
  159. echo "---------------------------- Test 33 -----------------------------" >>testtrygrep
  160. (cd $srcdir; $valgrind $pcregrep 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
  161. echo "RC=$?" >>testtrygrep
  162. echo "---------------------------- Test 34 -----------------------------" >>testtrygrep
  163. (cd $srcdir; $valgrind $pcregrep -s 'fox' ./testdata/grepnonexist) >>testtrygrep 2>&1
  164. echo "RC=$?" >>testtrygrep
  165. echo "---------------------------- Test 35 -----------------------------" >>testtrygrep
  166. (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --include grepinput8 --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  167. echo "RC=$?" >>testtrygrep
  168. echo "---------------------------- Test 36 -----------------------------" >>testtrygrep
  169. (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude 'grepinput$' --exclude=grepinput8 --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  170. echo "RC=$?" >>testtrygrep
  171. echo "---------------------------- Test 37 -----------------------------" >>testtrygrep
  172. (cd $srcdir; $valgrind $pcregrep '^(a+)*\d' ./testdata/grepinput) >>testtrygrep 2>teststderrgrep
  173. echo "RC=$?" >>testtrygrep
  174. echo "======== STDERR ========" >>testtrygrep
  175. cat teststderrgrep >>testtrygrep
  176. echo "---------------------------- Test 38 ------------------------------" >>testtrygrep
  177. (cd $srcdir; $valgrind $pcregrep '>\x00<' ./testdata/grepinput) >>testtrygrep
  178. echo "RC=$?" >>testtrygrep
  179. echo "---------------------------- Test 39 ------------------------------" >>testtrygrep
  180. (cd $srcdir; $valgrind $pcregrep -A1 'before the binary zero' ./testdata/grepinput) >>testtrygrep
  181. echo "RC=$?" >>testtrygrep
  182. echo "---------------------------- Test 40 ------------------------------" >>testtrygrep
  183. (cd $srcdir; $valgrind $pcregrep -B1 'after the binary zero' ./testdata/grepinput) >>testtrygrep
  184. echo "RC=$?" >>testtrygrep
  185. echo "---------------------------- Test 41 ------------------------------" >>testtrygrep
  186. (cd $srcdir; $valgrind $pcregrep -B1 -o '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
  187. echo "RC=$?" >>testtrygrep
  188. echo "---------------------------- Test 42 ------------------------------" >>testtrygrep
  189. (cd $srcdir; $valgrind $pcregrep -B1 -onH '\w+ the binary zero' ./testdata/grepinput) >>testtrygrep
  190. echo "RC=$?" >>testtrygrep
  191. echo "---------------------------- Test 43 ------------------------------" >>testtrygrep
  192. (cd $srcdir; $valgrind $pcregrep -on 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  193. echo "RC=$?" >>testtrygrep
  194. echo "---------------------------- Test 44 ------------------------------" >>testtrygrep
  195. (cd $srcdir; $valgrind $pcregrep -on -e before -ezero -e after ./testdata/grepinput) >>testtrygrep
  196. echo "RC=$?" >>testtrygrep
  197. echo "---------------------------- Test 45 ------------------------------" >>testtrygrep
  198. (cd $srcdir; $valgrind $pcregrep -on -f ./testdata/greplist -e binary ./testdata/grepinput) >>testtrygrep
  199. echo "RC=$?" >>testtrygrep
  200. echo "---------------------------- Test 46 ------------------------------" >>testtrygrep
  201. (cd $srcdir; $valgrind $pcregrep -eabc -e '(unclosed' ./testdata/grepinput) 2>>testtrygrep >>testtrygrep
  202. echo "RC=$?" >>testtrygrep
  203. echo "---------------------------- Test 47 ------------------------------" >>testtrygrep
  204. (cd $srcdir; $valgrind $pcregrep -Fx "AB.VE
  205. elephant" ./testdata/grepinput) >>testtrygrep
  206. echo "RC=$?" >>testtrygrep
  207. echo "---------------------------- Test 48 ------------------------------" >>testtrygrep
  208. (cd $srcdir; $valgrind $pcregrep -F "AB.VE
  209. elephant" ./testdata/grepinput) >>testtrygrep
  210. echo "RC=$?" >>testtrygrep
  211. echo "---------------------------- Test 49 ------------------------------" >>testtrygrep
  212. (cd $srcdir; $valgrind $pcregrep -F -e DATA -e "AB.VE
  213. elephant" ./testdata/grepinput) >>testtrygrep
  214. echo "RC=$?" >>testtrygrep
  215. echo "---------------------------- Test 50 ------------------------------" >>testtrygrep
  216. (cd $srcdir; $valgrind $pcregrep "^(abc|def|ghi|jkl)" ./testdata/grepinputx) >>testtrygrep
  217. echo "RC=$?" >>testtrygrep
  218. echo "---------------------------- Test 51 ------------------------------" >>testtrygrep
  219. (cd $srcdir; $valgrind $pcregrep -Mv "brown\sfox" ./testdata/grepinputv) >>testtrygrep
  220. echo "RC=$?" >>testtrygrep
  221. echo "---------------------------- Test 52 ------------------------------" >>testtrygrep
  222. (cd $srcdir; $valgrind $pcregrep --colour=always jumps ./testdata/grepinputv) >>testtrygrep
  223. echo "RC=$?" >>testtrygrep
  224. echo "---------------------------- Test 53 ------------------------------" >>testtrygrep
  225. (cd $srcdir; $valgrind $pcregrep --file-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  226. echo "RC=$?" >>testtrygrep
  227. echo "---------------------------- Test 54 ------------------------------" >>testtrygrep
  228. (cd $srcdir; $valgrind $pcregrep --line-offsets 'before|zero|after' ./testdata/grepinput) >>testtrygrep
  229. echo "RC=$?" >>testtrygrep
  230. echo "---------------------------- Test 55 -----------------------------" >>testtrygrep
  231. (cd $srcdir; $valgrind $pcregrep -f./testdata/greplist --color=always ./testdata/grepinputx) >>testtrygrep
  232. echo "RC=$?" >>testtrygrep
  233. echo "---------------------------- Test 56 -----------------------------" >>testtrygrep
  234. (cd $srcdir; $valgrind $pcregrep -c lazy ./testdata/grepinput*) >>testtrygrep
  235. echo "RC=$?" >>testtrygrep
  236. echo "---------------------------- Test 57 -----------------------------" >>testtrygrep
  237. (cd $srcdir; $valgrind $pcregrep -c -l lazy ./testdata/grepinput*) >>testtrygrep
  238. echo "RC=$?" >>testtrygrep
  239. echo "---------------------------- Test 58 -----------------------------" >>testtrygrep
  240. (cd $srcdir; $valgrind $pcregrep --regex=PATTERN ./testdata/grepinput) >>testtrygrep
  241. echo "RC=$?" >>testtrygrep
  242. echo "---------------------------- Test 59 -----------------------------" >>testtrygrep
  243. (cd $srcdir; $valgrind $pcregrep --regexp=PATTERN ./testdata/grepinput) >>testtrygrep
  244. echo "RC=$?" >>testtrygrep
  245. echo "---------------------------- Test 60 -----------------------------" >>testtrygrep
  246. (cd $srcdir; $valgrind $pcregrep --regex PATTERN ./testdata/grepinput) >>testtrygrep
  247. echo "RC=$?" >>testtrygrep
  248. echo "---------------------------- Test 61 -----------------------------" >>testtrygrep
  249. (cd $srcdir; $valgrind $pcregrep --regexp PATTERN ./testdata/grepinput) >>testtrygrep
  250. echo "RC=$?" >>testtrygrep
  251. echo "---------------------------- Test 62 -----------------------------" >>testtrygrep
  252. (cd $srcdir; $valgrind $pcregrep --match-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
  253. echo "RC=$?" >>testtrygrep
  254. echo "---------------------------- Test 63 -----------------------------" >>testtrygrep
  255. (cd $srcdir; $valgrind $pcregrep --recursion-limit=1000 --no-jit -M 'This is a file(.|\R)*file.' ./testdata/grepinput) >>testtrygrep 2>&1
  256. echo "RC=$?" >>testtrygrep
  257. echo "---------------------------- Test 64 ------------------------------" >>testtrygrep
  258. (cd $srcdir; $valgrind $pcregrep -o1 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  259. echo "RC=$?" >>testtrygrep
  260. echo "---------------------------- Test 65 ------------------------------" >>testtrygrep
  261. (cd $srcdir; $valgrind $pcregrep -o2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  262. echo "RC=$?" >>testtrygrep
  263. echo "---------------------------- Test 66 ------------------------------" >>testtrygrep
  264. (cd $srcdir; $valgrind $pcregrep -o3 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  265. echo "RC=$?" >>testtrygrep
  266. echo "---------------------------- Test 67 ------------------------------" >>testtrygrep
  267. (cd $srcdir; $valgrind $pcregrep -o12 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  268. echo "RC=$?" >>testtrygrep
  269. echo "---------------------------- Test 68 ------------------------------" >>testtrygrep
  270. (cd $srcdir; $valgrind $pcregrep --only-matching=2 '(?<=PAT)TERN (ap(pear)s)' ./testdata/grepinput) >>testtrygrep
  271. echo "RC=$?" >>testtrygrep
  272. echo "---------------------------- Test 69 -----------------------------" >>testtrygrep
  273. (cd $srcdir; $valgrind $pcregrep -vn --colour=always pattern ./testdata/grepinputx) >>testtrygrep
  274. echo "RC=$?" >>testtrygrep
  275. echo "---------------------------- Test 70 -----------------------------" >>testtrygrep
  276. (cd $srcdir; $valgrind $pcregrep --color=always -M "triple:\t.*\n\n" ./testdata/grepinput3) >>testtrygrep
  277. echo "RC=$?" >>testtrygrep
  278. echo "---------------------------- Test 71 -----------------------------" >>testtrygrep
  279. (cd $srcdir; $valgrind $pcregrep -o "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  280. echo "RC=$?" >>testtrygrep
  281. echo "---------------------------- Test 72 -----------------------------" >>testtrygrep
  282. (cd $srcdir; $valgrind $pcregrep --color=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  283. echo "RC=$?" >>testtrygrep
  284. echo "---------------------------- Test 73 -----------------------------" >>testtrygrep
  285. (cd $srcdir; $valgrind $pcregrep -o --colour=always "^01|^02|^03" ./testdata/grepinput) >>testtrygrep
  286. echo "RC=$?" >>testtrygrep
  287. echo "---------------------------- Test 74 -----------------------------" >>testtrygrep
  288. (cd $srcdir; $valgrind $pcregrep -o "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  289. echo "RC=$?" >>testtrygrep
  290. echo "---------------------------- Test 75 -----------------------------" >>testtrygrep
  291. (cd $srcdir; $valgrind $pcregrep --color=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  292. echo "RC=$?" >>testtrygrep
  293. echo "---------------------------- Test 76 -----------------------------" >>testtrygrep
  294. (cd $srcdir; $valgrind $pcregrep -o --colour=always "^01|02|^03" ./testdata/grepinput) >>testtrygrep
  295. echo "RC=$?" >>testtrygrep
  296. echo "---------------------------- Test 77 -----------------------------" >>testtrygrep
  297. (cd $srcdir; $valgrind $pcregrep -o "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  298. echo "RC=$?" >>testtrygrep
  299. echo "---------------------------- Test 78 -----------------------------" >>testtrygrep
  300. (cd $srcdir; $valgrind $pcregrep --color=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  301. echo "RC=$?" >>testtrygrep
  302. echo "---------------------------- Test 79 -----------------------------" >>testtrygrep
  303. (cd $srcdir; $valgrind $pcregrep -o --colour=always "^01|^02|03" ./testdata/grepinput) >>testtrygrep
  304. echo "RC=$?" >>testtrygrep
  305. echo "---------------------------- Test 80 -----------------------------" >>testtrygrep
  306. (cd $srcdir; $valgrind $pcregrep -o "\b01|\b02" ./testdata/grepinput) >>testtrygrep
  307. echo "RC=$?" >>testtrygrep
  308. echo "---------------------------- Test 81 -----------------------------" >>testtrygrep
  309. (cd $srcdir; $valgrind $pcregrep --color=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
  310. echo "RC=$?" >>testtrygrep
  311. echo "---------------------------- Test 82 -----------------------------" >>testtrygrep
  312. (cd $srcdir; $valgrind $pcregrep -o --colour=always "\\b01|\\b02" ./testdata/grepinput) >>testtrygrep
  313. echo "RC=$?" >>testtrygrep
  314. echo "---------------------------- Test 83 -----------------------------" >>testtrygrep
  315. (cd $srcdir; $valgrind $pcregrep --buffer-size=100 "^a" ./testdata/grepinput3) >>testtrygrep 2>&1
  316. echo "RC=$?" >>testtrygrep
  317. echo "---------------------------- Test 84 -----------------------------" >>testtrygrep
  318. echo testdata/grepinput3 >testtemp1grep
  319. (cd $srcdir; $valgrind $pcregrep --file-list ./testdata/grepfilelist --file-list $builddir/testtemp1grep "fox|complete|t7") >>testtrygrep 2>&1
  320. echo "RC=$?" >>testtrygrep
  321. echo "---------------------------- Test 85 -----------------------------" >>testtrygrep
  322. (cd $srcdir; $valgrind $pcregrep --file-list=./testdata/grepfilelist "dolor" ./testdata/grepinput3) >>testtrygrep 2>&1
  323. echo "RC=$?" >>testtrygrep
  324. echo "---------------------------- Test 86 -----------------------------" >>testtrygrep
  325. (cd $srcdir; $valgrind $pcregrep "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  326. echo "RC=$?" >>testtrygrep
  327. echo "---------------------------- Test 87 -----------------------------" >>testtrygrep
  328. (cd $srcdir; $valgrind $pcregrep "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
  329. echo "RC=$?" >>testtrygrep
  330. echo "---------------------------- Test 88 -----------------------------" >>testtrygrep
  331. (cd $srcdir; $valgrind $pcregrep -v "cat" ./testdata/grepbinary) >>testtrygrep 2>&1
  332. echo "RC=$?" >>testtrygrep
  333. echo "---------------------------- Test 89 -----------------------------" >>testtrygrep
  334. (cd $srcdir; $valgrind $pcregrep -I "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  335. echo "RC=$?" >>testtrygrep
  336. echo "---------------------------- Test 90 -----------------------------" >>testtrygrep
  337. (cd $srcdir; $valgrind $pcregrep --binary-files=without-match "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  338. echo "RC=$?" >>testtrygrep
  339. echo "---------------------------- Test 91 -----------------------------" >>testtrygrep
  340. (cd $srcdir; $valgrind $pcregrep -a "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  341. echo "RC=$?" >>testtrygrep
  342. echo "---------------------------- Test 92 -----------------------------" >>testtrygrep
  343. (cd $srcdir; $valgrind $pcregrep --binary-files=text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  344. echo "RC=$?" >>testtrygrep
  345. echo "---------------------------- Test 93 -----------------------------" >>testtrygrep
  346. (cd $srcdir; $valgrind $pcregrep --text "dog" ./testdata/grepbinary) >>testtrygrep 2>&1
  347. echo "RC=$?" >>testtrygrep
  348. echo "---------------------------- Test 94 -----------------------------" >>testtrygrep
  349. (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinputx --include grepinput8 'fox' ./testdata/grepinput* | sort) >>testtrygrep
  350. echo "RC=$?" >>testtrygrep
  351. echo "---------------------------- Test 95 -----------------------------" >>testtrygrep
  352. (cd $srcdir; $valgrind $pcregrep --file-list ./testdata/grepfilelist --exclude grepinputv "fox|complete") >>testtrygrep 2>&1
  353. echo "RC=$?" >>testtrygrep
  354. echo "---------------------------- Test 96 -----------------------------" >>testtrygrep
  355. (cd $srcdir; $valgrind $pcregrep -L -r --include-dir=testdata --exclude '^(?!grepinput)' 'fox' ./test* | sort) >>testtrygrep
  356. echo "RC=$?" >>testtrygrep
  357. echo "---------------------------- Test 97 -----------------------------" >>testtrygrep
  358. echo "grepinput$" >testtemp1grep
  359. echo "grepinput8" >>testtemp1grep
  360. (cd $srcdir; $valgrind $pcregrep -L -r --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  361. echo "RC=$?" >>testtrygrep
  362. echo "---------------------------- Test 98 -----------------------------" >>testtrygrep
  363. echo "grepinput$" >testtemp1grep
  364. echo "grepinput8" >>testtemp1grep
  365. (cd $srcdir; $valgrind $pcregrep -L -r --exclude=grepinput3 --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  366. echo "RC=$?" >>testtrygrep
  367. echo "---------------------------- Test 99 -----------------------------" >>testtrygrep
  368. echo "grepinput$" >testtemp1grep
  369. echo "grepinput8" >testtemp2grep
  370. (cd $srcdir; $valgrind $pcregrep -L -r --include grepinput --exclude-from $builddir/testtemp1grep --exclude-from=$builddir/testtemp2grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep
  371. echo "RC=$?" >>testtrygrep
  372. echo "---------------------------- Test 100 ------------------------------" >>testtrygrep
  373. (cd $srcdir; $valgrind $pcregrep -Ho2 --only-matching=1 -o3 '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  374. echo "RC=$?" >>testtrygrep
  375. echo "---------------------------- Test 101 ------------------------------" >>testtrygrep
  376. (cd $srcdir; $valgrind $pcregrep -o3 -Ho2 -o12 --only-matching=1 -o3 --colour=always --om-separator='|' '(\w+) binary (\w+)(\.)?' ./testdata/grepinput) >>testtrygrep
  377. echo "RC=$?" >>testtrygrep
  378. echo "---------------------------- Test 102 -----------------------------" >>testtrygrep
  379. (cd $srcdir; $valgrind $pcregrep -n "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  380. echo "RC=$?" >>testtrygrep
  381. echo "---------------------------- Test 103 -----------------------------" >>testtrygrep
  382. (cd $srcdir; $valgrind $pcregrep --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  383. echo "RC=$?" >>testtrygrep
  384. echo "---------------------------- Test 104 -----------------------------" >>testtrygrep
  385. (cd $srcdir; $valgrind $pcregrep -n --only-matching "^$" ./testdata/grepinput3) >>testtrygrep 2>&1
  386. echo "RC=$?" >>testtrygrep
  387. echo "---------------------------- Test 105 -----------------------------" >>testtrygrep
  388. (cd $srcdir; $valgrind $pcregrep --colour=always "ipsum|" ./testdata/grepinput3) >>testtrygrep 2>&1
  389. echo "RC=$?" >>testtrygrep
  390. echo "---------------------------- Test 106 -----------------------------" >>testtrygrep
  391. (cd $srcdir; echo "a" | $valgrind $pcregrep -M "|a" ) >>testtrygrep 2>&1
  392. echo "RC=$?" >>testtrygrep
  393. echo "---------------------------- Test 107 -----------------------------" >>testtrygrep
  394. echo "a" >testtemp1grep
  395. echo "aaaaa" >>testtemp1grep
  396. (cd $srcdir; $valgrind $pcregrep --line-offsets '(?<=\Ka)' $builddir/testtemp1grep) >>testtrygrep 2>&1
  397. echo "RC=$?" >>testtrygrep
  398. echo "---------------------------- Test 108 ------------------------------" >>testtrygrep
  399. (cd $srcdir; $valgrind $pcregrep -lq PATTERN ./testdata/grepinput ./testdata/grepinputx) >>testtrygrep
  400. echo "RC=$?" >>testtrygrep
  401. echo "---------------------------- Test 109 -----------------------------" >>testtrygrep
  402. (cd $srcdir; $valgrind $pcregrep -cq lazy ./testdata/grepinput*) >>testtrygrep
  403. echo "RC=$?" >>testtrygrep
  404. # Now compare the results.
  405. $cf $srcdir/testdata/grepoutput testtrygrep
  406. if [ $? != 0 ] ; then exit 1; fi
  407. # These tests require UTF-8 support
  408. if [ $utf8 -ne 0 ] ; then
  409. echo "Testing pcregrep UTF-8 features"
  410. echo "---------------------------- Test U1 ------------------------------" >testtrygrep
  411. (cd $srcdir; $valgrind $pcregrep -n -u --newline=any "^X" ./testdata/grepinput8) >>testtrygrep
  412. echo "RC=$?" >>testtrygrep
  413. echo "---------------------------- Test U2 ------------------------------" >>testtrygrep
  414. (cd $srcdir; $valgrind $pcregrep -n -u -C 3 --newline=any "Match" ./testdata/grepinput8) >>testtrygrep
  415. echo "RC=$?" >>testtrygrep
  416. $cf $srcdir/testdata/grepoutput8 testtrygrep
  417. if [ $? != 0 ] ; then exit 1; fi
  418. else
  419. echo "Skipping pcregrep UTF-8 tests: no UTF-8 support in PCRE library"
  420. fi
  421. # We go to some contortions to try to ensure that the tests for the various
  422. # newline settings will work in environments where the normal newline sequence
  423. # is not \n. Do not use exported files, whose line endings might be changed.
  424. # Instead, create an input file using printf so that its contents are exactly
  425. # what we want. Note the messy fudge to get printf to write a string that
  426. # starts with a hyphen. These tests are run in the build directory.
  427. echo "Testing pcregrep newline settings"
  428. printf "abc\rdef\r\nghi\njkl" >testNinputgrep
  429. printf "%c--------------------------- Test N1 ------------------------------\r\n" - >testtrygrep
  430. $valgrind $pcregrep -n -N CR "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  431. printf "%c--------------------------- Test N2 ------------------------------\r\n" - >>testtrygrep
  432. $valgrind $pcregrep -n --newline=crlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  433. printf "%c--------------------------- Test N3 ------------------------------\r\n" - >>testtrygrep
  434. pattern=`printf 'def\rjkl'`
  435. $valgrind $pcregrep -n --newline=cr -F "$pattern" testNinputgrep >>testtrygrep
  436. printf "%c--------------------------- Test N4 ------------------------------\r\n" - >>testtrygrep
  437. $valgrind $pcregrep -n --newline=crlf -F -f $srcdir/testdata/greppatN4 testNinputgrep >>testtrygrep
  438. printf "%c--------------------------- Test N5 ------------------------------\r\n" - >>testtrygrep
  439. $valgrind $pcregrep -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  440. printf "%c--------------------------- Test N6 ------------------------------\r\n" - >>testtrygrep
  441. $valgrind $pcregrep -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep
  442. $cf $srcdir/testdata/grepoutputN testtrygrep
  443. if [ $? != 0 ] ; then exit 1; fi
  444. exit 0
  445. # End