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