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