From c94d84695866d5edf7f9d2bbe4167e0652b40cdf Mon Sep 17 00:00:00 2001 From: Nick Wilson Date: Mon, 25 Nov 2024 11:41:35 +0000 Subject: [PATCH] Add RunGrepTest.bat to CMake --- CMakeLists.txt | 36 ++-- RunGrepTest | 47 +++-- RunGrepTest.bat | 436 +++++++++++++++++++++++++++++++++++++---- RunTest.bat | 4 +- src/pcre2grep.c | 4 +- testdata/grepinputBad8 | 1 + testdata/grepinputUN | 2 + testdata/grepoutput | 10 + testdata/grepoutputC | 6 + testdata/grepoutputCN | 6 + testdata/grepoutputCNU | 2 + testdata/grepoutputCU | 2 + 12 files changed, 491 insertions(+), 65 deletions(-) create mode 100644 testdata/grepinputBad8 create mode 100644 testdata/grepinputUN diff --git a/CMakeLists.txt b/CMakeLists.txt index 843ef62b5..01f34165b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1014,13 +1014,6 @@ IF(PCRE2_BUILD_TESTS) TARGET_LINK_LIBRARIES(pcre2_jit_test ${PCRE2_JIT_TEST_LIBS}) ENDIF(PCRE2_SUPPORT_JIT) - # exes in Debug location tested by the RunTest and RunGrepTest shell scripts - # via "make test" - - IF(PCRE2_BUILD_PCRE2GREP) - SET(PCRE2GREP_EXE $) - ENDIF(PCRE2_BUILD_PCRE2GREP) - # ================================================= # Write out a CTest configuration file # @@ -1082,10 +1075,31 @@ if errorlevel 1 exit /b 1 echo RunTest.bat tests successfully completed ") - ADD_TEST(NAME pcre2_test_bat - COMMAND pcre2_test.bat) - SET_TESTS_PROPERTIES(pcre2_test_bat PROPERTIES - PASS_REGULAR_EXPRESSION "RunTest\\.bat tests successfully completed") + ADD_TEST(NAME pcre2_test_bat + COMMAND pcre2_test.bat) + SET_TESTS_PROPERTIES(pcre2_test_bat PROPERTIES + PASS_REGULAR_EXPRESSION "RunTest\\.bat tests successfully completed") + + IF(PCRE2_BUILD_PCRE2GREP) + FILE(WRITE ${PROJECT_BINARY_DIR}/pcre2_grep_test.bat + "\@REM This is a generated file. +\@echo off +setlocal +SET srcdir=\"${winsrc}\" +SET pcre2test=\"${winbin}\\pcre2test.exe\" +if not [%CMAKE_CONFIG_TYPE%]==[] SET pcre2test=\"${winbin}\\%CMAKE_CONFIG_TYPE%\\pcre2test.exe\" +SET pcre2grep=\"${winbin}\\pcre2grep.exe\" +if not [%CMAKE_CONFIG_TYPE%]==[] SET pcre2grep=\"${winbin}\\%CMAKE_CONFIG_TYPE%\\pcre2grep.exe\" +call %srcdir%\\RunGrepTest.bat +if errorlevel 1 exit /b 1 +echo RunGrepTest.bat tests successfully completed +") + + ADD_TEST(NAME pcre2_grep_test_bat + COMMAND pcre2_grep_test.bat) + SET_TESTS_PROPERTIES(pcre2_grep_test_bat PROPERTIES + PASS_REGULAR_EXPRESSION "RunGrepTest\\.bat tests successfully completed") + ENDIF(PCRE2_BUILD_PCRE2GREP) IF("$ENV{OSTYPE}" STREQUAL "msys") # Both the sh and bat file versions of RunTest are run if make test is used diff --git a/RunGrepTest b/RunGrepTest index bd39a1c50..9c61d1ae8 100755 --- a/RunGrepTest +++ b/RunGrepTest @@ -275,7 +275,7 @@ echo "---------------------------- Test 35 -----------------------------" >>test echo "RC=$?" >>testtrygrep echo "---------------------------- Test 36 -----------------------------" >>testtrygrep -(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include='grepinput[^C]' --exclude 'grepinput$' --exclude=grepinput8 --exclude=grepinputM --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep +(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include='grepinput[^C]' --exclude 'grepinput$' --exclude='grepinput(Bad)?8' --exclude=grepinputM --exclude=grepinputUN --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 37 -----------------------------" >>testtrygrep @@ -530,25 +530,28 @@ echo "---------------------------- Test 95 -----------------------------" >>test echo "RC=$?" >>testtrygrep echo "---------------------------- Test 96 -----------------------------" >>testtrygrep -(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include-dir=testdata --exclude '^(?!grepinput)' --exclude=grepinput[MC] 'fox' ./test* | sort) >>testtrygrep +(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include-dir=testdata --exclude '^(?!grepinput)' --exclude=grepinput[MCU] 'fox' ./test* | sort) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 97 -----------------------------" >>testtrygrep echo "grepinput$" >testtemp1grep echo "grepinput8" >>testtemp1grep -(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinput --exclude=grepinput[MC] --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep +echo "grepinputBad8" >>testtemp1grep +(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include=grepinput --exclude=grepinput[MCU] --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 98 -----------------------------" >>testtrygrep echo "grepinput$" >testtemp1grep echo "grepinput8" >>testtemp1grep -(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --exclude=grepinput3 --exclude=grepinput[MC] --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep +echo "grepinputBad8" >>testtemp1grep +(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --exclude=grepinput3 --exclude=grepinput[MCU] --include=grepinput --exclude-from $builddir/testtemp1grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 99 -----------------------------" >>testtrygrep echo "grepinput$" >testtemp1grep echo "grepinput8" >testtemp2grep -(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 +echo "grepinputBad8" >>testtemp1grep +(cd $srcdir; $valgrind $vjs $pcre2grep -L -r --include grepinput --exclude=grepinput[MCU] --exclude-from $builddir/testtemp1grep --exclude-from=$builddir/testtemp2grep --exclude-dir='^\.' 'fox' ./testdata | sort) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 100 ------------------------------" >>testtrygrep @@ -618,7 +621,7 @@ echo "---------------------------- Test 115 -----------------------------" >>tes echo "RC=$?" >>testtrygrep echo "---------------------------- Test 116 -----------------------------" >>testtrygrep -(cd $srcdir; $valgrind $vjs $pcre2grep --exclude=grepinput[MC] -th 'the' testdata/grepinput*) >>testtrygrep +(cd $srcdir; $valgrind $vjs $pcre2grep --exclude=grepinput[MCU] -th 'the' testdata/grepinput*) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 117 -----------------------------" >>testtrygrep @@ -763,7 +766,7 @@ echo "---------------------------- Test 140 -----------------------------" >>tes echo "RC=$?" >>testtrygrep echo "---------------------------- Test 141 -----------------------------" >>testtrygrep -printf "$srcdir/testdata/grepinputv\n-\n" >testtemp1grep +printf "%s/testdata/grepinputv\n-\n" "$srcdir" >testtemp1grep printf 'This is a line from stdin.' >testtemp2grep $valgrind $vjs $pcre2grep --file-list testtemp1grep "line from stdin" >testtrygrep 2>&1 echo "RC=$?" >>testtrygrep @@ -848,12 +851,13 @@ if [ $? -ne 0 ]; then echo "RC=2" >>testtrygrep else - (cd $srcdir; unset LC_ALL; env LC_CTYPE=locale.bad $valgrind $vjs $pcre2grep abc /dev/null) >>testtrygrep 2>&1 + (cd $srcdir; unset LC_ALL; LC_CTYPE=locale.bad $valgrind $vjs $pcre2grep abc /dev/null) >>testtrygrep 2>&1 echo "RC=$?" >>testtrygrep fi echo "---------------------------- Test 151 -----------------------------" >>testtrygrep (cd $srcdir; $valgrind $vjs $pcre2grep --colour=always -e this -e The -e 'The wo' testdata/grepinputv) >>testtrygrep +echo "RC=$?" >>testtrygrep echo "---------------------------- Test 152 -----------------------------" >>testtrygrep (cd $srcdir; $valgrind $vjs $pcre2grep -nA3 --group-separator='++' 'four' ./testdata/grepinputx) >>testtrygrep @@ -889,7 +893,7 @@ echo "spaces." >testtemp1grep echo "RC=$?" >>testtrygrep echo "---------------------------- Test 159 -----------------------------" >>testtrygrep -printf "spaces.\015\012" >testtemp1grep +printf "spaces.\r\n" >testtemp1grep (cd $srcdir; $valgrind $vjs $pcre2grep --posix-pattern-file -f$builddir/testtemp1grep ./testdata/grepinputv) >>testtrygrep echo "RC=$?" >>testtrygrep @@ -917,13 +921,11 @@ if [ $utf8 -ne 0 ] ; then echo "RC=$?" >>testtrygrep echo "---------------------------- Test U4 ------------------------------" >>testtrygrep - printf 'A\341\200\200\200CD\342\200\200Z\n' >testtemp1grep - (cd $srcdir; $valgrind $vjs $pcre2grep -u -o '....' $builddir/testtemp1grep) >>testtrygrep 2>&1 + (cd $srcdir; $valgrind $vjs $pcre2grep -u -o '....' ./testdata/grepinputBad8) >>testtrygrep 2>&1 echo "RC=$?" >>testtrygrep echo "---------------------------- Test U5 ------------------------------" >>testtrygrep - printf 'A\341\200\200\200CD\342\200\200Z\n' >testtemp1grep - (cd $srcdir; $valgrind $vjs $pcre2grep -U -o '....' $builddir/testtemp1grep) >>testtrygrep + (cd $srcdir; $valgrind $vjs $pcre2grep -U -o '....' ./testdata/grepinputBad8) >>testtrygrep echo "RC=$?" >>testtrygrep echo "---------------------------- Test U6 -----------------------------" >>testtrygrep @@ -1003,8 +1005,7 @@ if [ $utf8 -ne 0 ] ; then echo "Testing pcre2grep newline settings with UTF-8 features" printf '%c--------------------------- Test UN1 ------------------------------\r\n' - >testtrygrep - printf 'abc\341\210\264def\nxyz' >testNinputgrep - $valgrind $vjs $pcre2grep -nau --newline=anycrlf "^(abc|def)" testNinputgrep >>testtrygrep + $valgrind $vjs $pcre2grep -nau --newline=anycrlf "^(abc|def)" $srcdir/testdata/grepinputUN >>testtrygrep echo "" >>testtrygrep $cf $srcdir/testdata/grepoutputUN testtrygrep @@ -1021,11 +1022,17 @@ fi if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'callout scripts in patterns are supported'; then echo "Testing pcre2grep script callouts" - $valgrind $vjs $pcre2grep '(T)(..(.))(?C"/bin/echo|Arg1: [$1] [$2] [$3]|Arg2: $|${1}$| ($4) ($14) ($0)")()' $srcdir/testdata/grepinputv >testtrygrep + echo "--- Test 1 ---" >testtrygrep + $valgrind $vjs $pcre2grep '(T)(..(.))(?C"/bin/echo|Arg1: [$1] [$2] [$3]|Arg2: $|${1}$| ($4) ($14) ($0)")()' $srcdir/testdata/grepinputv >>testtrygrep + echo "--- Test 2 ---" >>testtrygrep $valgrind $vjs $pcre2grep '(T)(..(.))()()()()()()()(..)(?C"/bin/echo|Arg1: [$11] [${11}]")' $srcdir/testdata/grepinputv >>testtrygrep + echo "--- Test 3 ---" >>testtrygrep $valgrind $vjs $pcre2grep '(T)(?C"|$0:$1$n")' $srcdir/testdata/grepinputv >>testtrygrep + echo "--- Test 4 ---" >>testtrygrep $valgrind $vjs $pcre2grep '(T)(?C"/bin/echo|$0:$1$n")' $srcdir/testdata/grepinputv >>testtrygrep + echo "--- Test 5 ---" >>testtrygrep $valgrind $vjs $pcre2grep '(T)(?C"|$1$n")(*F)' $srcdir/testdata/grepinputv >>testtrygrep + echo "--- Test 6 ---" >>testtrygrep $valgrind $vjs $pcre2grep -m1 '(T)(?C"|$0:$1:$x{41}$o{101}$n")' $srcdir/testdata/grepinputv >>testtrygrep if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'Non-fork callout scripts in patterns are supported'; then @@ -1041,7 +1048,9 @@ if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'callout scri if [ $utf8 -ne 0 ] ; then echo "Testing pcre2grep script callout with UTF-8 features" - $valgrind $vjs $pcre2grep -u '(T)(?C"|$0:$x{a6}$n")' $srcdir/testdata/grepinputv >testtrygrep + echo "--- Test 1 ---" >testtrygrep + $valgrind $vjs $pcre2grep -u '(T)(?C"|$0:$x{a6}$n")' $srcdir/testdata/grepinputv >>testtrygrep + echo "--- Test 2 ---" >>testtrygrep $valgrind $vjs $pcre2grep -u '(T)(?C"/bin/echo|$0:$x{a6}$n")' $srcdir/testdata/grepinputv >>testtrygrep if [ $nonfork = 1 ] ; then @@ -1050,7 +1059,11 @@ if $valgrind $vjs $pcre2grep --help | $valgrind $vjs $pcre2grep -q 'callout scri $cf $srcdir/testdata/grepoutputCU testtrygrep fi if [ $? != 0 ] ; then exit 1; fi + else + echo "Skipping pcre2grep script callout UTF-8 tests: no UTF-8 support in PCRE2 library" fi + + unset nonfork else echo "Script callouts are not supported" fi diff --git a/RunGrepTest.bat b/RunGrepTest.bat index 4a095a36e..8dcfb319f 100644 --- a/RunGrepTest.bat +++ b/RunGrepTest.bat @@ -19,8 +19,9 @@ set GREP_COLOR= :: Remember the current (build) directory and set the program to be tested. set builddir="%CD%" -set pcre2grep=%builddir%\pcre2grep.exe -set pcre2test=%builddir%\pcre2test.exe + +if [%pcre2grep%]==[] set pcre2grep=%builddir%\pcre2grep.exe +if [%pcre2test%]==[] set pcre2test=%builddir%\pcre2test.exe if NOT exist %pcre2grep% ( echo ** %pcre2grep% does not exist. @@ -81,11 +82,16 @@ if NOT "%nl%" == "LF" if NOT "%nl%" == "ANY" if NOT "%nl%" == "ANYCRLF" ( ) :: Create a simple printf via cscript/JScript (an actual printf may translate -:: LF to CRLF, which this one does not). +:: LF to CRLF, which this one does not). We only support the barebones we need: +:: \r, \n, \0, and %s (but only once). -echo WScript.StdOut.Write(WScript.Arguments(0).replace(/\\r/g, "\r").replace(/\\n/g, "\n")) >printf.js +echo WScript.StdOut.Write(WScript.Arguments(0).replace(/\\r/g, "\r").replace(/\\n/g, "\n").replace(/\\0/g, "\x00").replace(/%%s/g, function() { return WScript.Arguments(1) })) >printf.js set printf=cscript //nologo printf.js +:: Create a simple 'tr' via cscript/JScript. +echo WScript.StdOut.Write(WScript.StdIn.ReadAll().replace(/\x00/g, "@")) >trnull.js +set trnull=cscript //nologo trnull.js + :: ------ Normal tests ------ echo Testing pcre2grep main features @@ -232,7 +238,7 @@ echo ---------------------------- Test 35 ----------------------------->>testtry echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 36 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -L -r --include=grepinput --exclude "grepinput$" --exclude=grepinput8 --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -L -r --include="grepinput[^C]" --exclude "grepinput$" --exclude="grepinput(Bad)?8" --exclude=grepinputM --exclude=grepinputUN --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 37 ----------------------------->>testtrygrep @@ -274,7 +280,10 @@ echo ---------------------------- Test 45 ------------------------------>>testtr echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 46 ------------------------------>>testtrygrep +(pushd %srcdir% & %pcre2grep% -e "unopened)" -e abc ./testdata/grepinput & popd) >>testtrygrep 2>&1 (pushd %srcdir% & %pcre2grep% -eabc -e "(unclosed" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +(pushd %srcdir% & %pcre2grep% -eabc -e xyz -e "[unclosed" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +(pushd %srcdir% & %pcre2grep% --regex=123 -eabc -e xyz -e "[unclosed" ./testdata/grepinput & popd) >>testtrygrep 2>&1 echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 47 ------------------------------>>testtrygrep @@ -320,11 +329,11 @@ echo ---------------------------- Test 55 ----------------------------->>testtry echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 56 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -c lazy ./testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -c --exclude=grepinputC lazy ./testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 57 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -c -l lazy ./testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -c -l --exclude=grepinputC lazy ./testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 58 ----------------------------->>testtrygrep @@ -378,6 +387,12 @@ echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 70 ----------------------------->>testtrygrep (pushd %srcdir% & %pcre2grep% --color=always -M "triple:\t.*\n\n" ./testdata/grepinput3 & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% --color=always -M -n "triple:\t.*\n\n" ./testdata/grepinput3 & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -M "triple:\t.*\n\n" ./testdata/grepinput3 & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -M -n "triple:\t.*\n\n" ./testdata/grepinput3 & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 71 ----------------------------->>testtrygrep (pushd %srcdir% & %pcre2grep% -o "^01|^02|^03" ./testdata/grepinput & popd) >>testtrygrep @@ -481,25 +496,28 @@ echo ---------------------------- Test 95 ----------------------------->>testtry echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 96 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -L -r --include-dir=testdata --exclude "^^(?^!grepinput)" "fox" ./test* | sort & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -L -r --include-dir=testdata --exclude "^^(?^!grepinput)" --exclude=grepinput[MCU] "fox" ./test* | sort & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 97 ----------------------------->>testtrygrep echo grepinput$>testtemp1grep echo grepinput8>>testtemp1grep -(pushd %srcdir% & %pcre2grep% -L -r --include=grepinput --exclude-from %builddir%\testtemp1grep --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep +echo grepinputBad8>>testtemp1grep +(pushd %srcdir% & %pcre2grep% -L -r --include=grepinput --exclude=grepinput[MCU] --exclude-from %builddir%\testtemp1grep --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 98 ----------------------------->>testtrygrep echo grepinput$>testtemp1grep echo grepinput8>>testtemp1grep -(pushd %srcdir% & %pcre2grep% -L -r --exclude=grepinput3 --include=grepinput --exclude-from %builddir%\testtemp1grep --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep +echo grepinputBad8>>testtemp1grep +(pushd %srcdir% & %pcre2grep% -L -r --exclude=grepinput3 --exclude=grepinput[MCU] --include=grepinput --exclude-from %builddir%\testtemp1grep --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 99 ----------------------------->>testtrygrep echo grepinput$>testtemp1grep echo grepinput8>testtemp2grep -(pushd %srcdir% & %pcre2grep% -L -r --include grepinput --exclude-from %builddir%\testtemp1grep --exclude-from=%builddir%\testtemp2grep --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep +echo grepinputBad8>>testtemp1grep +(pushd %srcdir% & %pcre2grep% -L -r --include grepinput --exclude=grepinput[MCU] --exclude-from %builddir%\testtemp1grep --exclude-from=%builddir%\testtemp2grep --exclude-dir="^\." "fox" ./testdata | sort & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 100 ------------------------------>>testtrygrep @@ -533,7 +551,7 @@ echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 107 ----------------------------->>testtrygrep echo a>testtemp1grep echo aaaaa>>testtemp1grep -(pushd %srcdir% & %pcre2grep% --line-offsets "(?<=\Ka)" %builddir%\testtemp1grep & popd) >>testtrygrep 2>&1 +(pushd %srcdir% & %pcre2grep% --line-offsets --allow-lookaround-bsk "(?<=\Ka)" %builddir%\testtemp1grep & popd) >>testtrygrep 2>&1 echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 108 ------------------------------>>testtrygrep @@ -541,7 +559,7 @@ echo ---------------------------- Test 108 ------------------------------>>testt echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 109 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -cq lazy ./testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -cq --exclude=grepinputC lazy ./testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 110 ----------------------------->>testtrygrep @@ -557,27 +575,27 @@ echo ---------------------------- Test 112 ----------------------------->>testtr echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 113 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% --total-count "the" testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% --total-count --exclude=grepinputC "the" testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 114 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -tc "the" testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -tc --exclude=grepinputC "the" testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 115 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -tlc "the" testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -tlc --exclude=grepinputC "the" testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 116 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -th "the" testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% --exclude=grepinput[MCU] -th "the" testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 117 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -tch "the" testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -tch --exclude=grepinputC "the" testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 118 ----------------------------->>testtrygrep -(pushd %srcdir% & %pcre2grep% -tL "the" testdata/grepinput* & popd) >>testtrygrep +(pushd %srcdir% & %pcre2grep% -tL --exclude=grepinputC "the" testdata/grepinput* & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 119 ----------------------------->>testtrygrep @@ -588,6 +606,260 @@ echo RC=^%ERRORLEVEL%>>testtrygrep echo ---------------------------- Test 120 ------------------------------>>testtrygrep (pushd %srcdir% & %pcre2grep% -HO "$0:$2$1$3" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -HO "$&:$2$1$3" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -m 1 -O "$0:$a$b$e$f$r$t$v" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -HO "${X}" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -HO "XX$" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -O "$x{12345678}" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -O "$x{123Z" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% --output "$x{1234}" "(\w+) binary (\w+)(\.)?" ./testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 121 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -F "\E and (regex)" testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 122 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -w "cat|dog" testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 123 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -w "dog|cat" testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 124 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -Mn --colour=always "start[\s]+end" testdata/grepinputM & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -Mn --colour=always -A2 "start[\s]+end" testdata/grepinputM & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -Mn "start[\s]+end" testdata/grepinputM & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -Mn -A2 "start[\s]+end" testdata/grepinputM & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 125 ----------------------------->>testtrygrep +%printf% "abcd\n" >testNinputgrep +%pcre2grep% --colour=always --allow-lookaround-bsk "(?<=\K.)" testNinputgrep >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --colour=always --allow-lookaround-bsk "(?=.\K)" testNinputgrep >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --colour=always --allow-lookaround-bsk "(?<=\K[ac])" testNinputgrep >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --colour=always --allow-lookaround-bsk "(?=[ac]\K)" testNinputgrep >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +set GREP_COLORS=ms=1;20 +%pcre2grep% --colour=always --allow-lookaround-bsk "(?=[ac]\K)" testNinputgrep >>testtrygrep +set GREP_COLORS= +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 126 ----------------------------->>testtrygrep +%printf% "Next line pattern has binary zero\nABC\0XYZ\n" >testtemp1grep +%printf% "ABC\0XYZ\nABCDEF\nDEFABC\n" >testtemp2grep +%pcre2grep% -a -f testtemp1grep testtemp2grep >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +%printf% "Next line pattern is erroneous.\n^abc)(xy" >testtemp1grep +%pcre2grep% -a -f testtemp1grep testtemp2grep >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 127 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -o --om-capture=0 "pattern()()()()" testdata/grepinput & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 128 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -m1M -o1 --om-capture=0 "pattern()()()()" testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 129 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -m 2 "fox" testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 130 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -o -m2 "fox" testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 131 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -oc -m2 "fox" testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 132 ----------------------------->>testtrygrep +:: The Unix tests use fd3 here, but Windows only has StdIn/StdOut/StdErr (which, at the kernel +:: level, are not even numbered). Use a subshell instead. +(pushd %srcdir% & (%pcre2grep% -m1 -A3 "^match" & echo ---& head -1) >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 133 ----------------------------->>testtrygrep +:: The Unix tests use fd3 here, but Windows only has StdIn/StdOut/StdErr (which, at the kernel +:: level, are not even numbered). Use a subshell instead. +(pushd %srcdir% & (%pcre2grep% -m1 -A3 "^match" & echo ---& %pcre2grep% -m1 -A3 "^match") >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 134 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% --max-count=1 -nH -O "=$x{41}$x423$o{103}$o1045=" "fox" - & popd) <%srcdir%\testdata\grepinputv >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 135 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -HZ "word" ./testdata/grepinputv & popd) | %trnull% >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -lZ "word" ./testdata/grepinputv ./testdata/grepinputv & popd) | %trnull% >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -A 1 -B 1 -HZ "word" ./testdata/grepinputv & popd) | %trnull% >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% -MHZn "start[\s]+end" testdata/grepinputM & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 136 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -m1MK -o1 --om-capture=0 "pattern()()()()" testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% --max-count=1MK -o1 --om-capture=0 "pattern()()()()" testdata/grepinput & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 137 ----------------------------->>testtrygrep +%printf% "Last line\nhas no newline" >testtemp1grep +%pcre2grep% -A1 Last testtemp1grep >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 138 ----------------------------->>testtrygrep +%printf% "AbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\nAbC\n" >testtemp1grep +%pcre2grep% --no-jit --heap-limit=0 b testtemp1grep >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 139 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% --line-buffered "fox" testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 140 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% --buffer-size=10 -A1 "brown" testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 141 ----------------------------->>testtrygrep +%printf% "%%s\testdata\grepinputv\n-\n" "%srcdir%" >testtemp1grep +%printf% "This is a line from stdin." >testtemp2grep +%pcre2grep% --file-list testtemp1grep "line from stdin" >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 142 ----------------------------->>testtrygrep +%printf% "/does/not/exist\n" >testtemp1grep +%printf% "This is a line from stdin." >testtemp2grep +%pcre2grep% --file-list testtemp1grep "line from stdin" >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 143 ----------------------------->>testtrygrep +%printf% "fox|cat" >testtemp1grep +%pcre2grep% -f - %srcdir%\testdata\grepinputv >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 144 ----------------------------->>testtrygrep +%pcre2grep% -f /non/exist %srcdir%\testdata\grepinputv >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 145 ----------------------------->>testtrygrep +%printf% "*meta*\rdog." >testtemp1grep +%pcre2grep% -Ncr -F -f testtemp1grep %srcdir%\testdata\grepinputv >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 146 ----------------------------->>testtrygrep +%printf% "A123B" >testtemp1grep +%pcre2grep% -H -e "123|fox" - >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% -h -e "123|fox" - %srcdir%\testdata\grepinputv >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% - %srcdir%\testdata\grepinputv >testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 147 ----------------------------->>testtrygrep +%pcre2grep% -e "123|fox" -- -nonfile >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 148 ----------------------------->>testtrygrep +%pcre2grep% --nonexist >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% -n-n-bad >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --context >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --only-matching --output=xx >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --colour=badvalue >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --newline=badvalue >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% -d badvalue >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% -D badvalue >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --buffer-size=0 >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --exclude "(badpat" abc /dev/null >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --exclude-from /non/exist abc /dev/null >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --include-from /non/exist abc /dev/null >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +%pcre2grep% --file-list=/non/exist abc /dev/null >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 149 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% --binary-files=binary "dog" ./testdata/grepbinary & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +(pushd %srcdir% & %pcre2grep% --binary-files=wrong "dog" ./testdata/grepbinary & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 150 ----------------------------->>testtrygrep +:: The Unix version of this tests checks for whether locales are supported. On Windows, +:: we assume they always are. +set LC_ALL= +set LC_CTYPE=locale.bad +(pushd %srcdir% & %pcre2grep% abc /dev/null & popd) >>testtrygrep 2>&1 +echo RC=^%ERRORLEVEL%>>testtrygrep +set LC_CTYPE= + +echo ---------------------------- Test 151 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% --colour=always -e this -e The -e "The wo" testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 152 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -nA3 --group-separator="++" "four" ./testdata/grepinputx & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 153 ----------------------------->>testtrygrep +(pushd %srcdir% & %pcre2grep% -nA3 --no-group-separator "four" ./testdata/grepinputx & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 154 ----------------------------->>testtrygrep +echo. >nul 2>testtemp1grep +(pushd %srcdir% & %pcre2grep% -f %builddir%\testtemp1grep ./testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 155 ----------------------------->>testtrygrep +echo. >testtemp1grep +(pushd %srcdir% & %pcre2grep% -f %builddir%\testtemp1grep ./testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 156 ----------------------------->>testtrygrep +%printf% "\n" >testtemp1grep +(pushd %srcdir% & %pcre2grep% --posix-pattern-file --file %builddir%\testtemp1grep ./testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 157 ----------------------------->>testtrygrep +%printf% "spaces \n" >testtemp1grep +(pushd %srcdir% & %pcre2grep% -o --posix-pattern-file --file=%builddir%\testtemp1grep ./testdata/grepinputv >%builddir%\testtemp2grep && %pcre2grep% -q "s " %builddir%\testtemp2grep & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 158 ----------------------------->>testtrygrep +%printf% "spaces.\n" >testtemp1grep +(pushd %srcdir% & %pcre2grep% -f %builddir%\testtemp1grep ./testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep + +echo ---------------------------- Test 159 ----------------------------->>testtrygrep +%printf% "spaces.\r\n" >testtemp1grep +(pushd %srcdir% & %pcre2grep% --posix-pattern-file -f%builddir%\testtemp1grep ./testdata/grepinputv & popd) >>testtrygrep +echo RC=^%ERRORLEVEL%>>testtrygrep :: Now compare the results. @@ -602,15 +874,43 @@ if %utf8% neq 0 ( echo ---------------------------- Test U1 ------------------------------>testtrygrep (pushd %srcdir% & %pcre2grep% -n -u --newline=any "^X" ./testdata/grepinput8 & popd) >>testtrygrep - echo RC=^%ERRORLEVEL%>>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep echo ---------------------------- Test U2 ------------------------------>>testtrygrep (pushd %srcdir% & %pcre2grep% -n -u -C 3 --newline=any "Match" ./testdata/grepinput8 & popd) >>testtrygrep - echo RC=^%ERRORLEVEL%>>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep echo ---------------------------- Test U3 ------------------------------>>testtrygrep - (pushd %srcdir% & %pcre2grep% --line-offsets -u --newline=any "(?<=\K\x{17f})" ./testdata/grepinput8 & popd) >>testtrygrep - echo RC=^%ERRORLEVEL%>>testtrygrep + (pushd %srcdir% & %pcre2grep% --line-offsets -u --newline=any --allow-lookaround-bsk "(?<=\K\x{17f})" ./testdata/grepinput8 & popd) >>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U4 ------------------------------>>testtrygrep + (pushd %srcdir% & %pcre2grep% -u -o "...." ./testdata/grepinputBad8 & popd) >>testtrygrep 2>&1 + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U5 ------------------------------>>testtrygrep + (pushd %srcdir% & %pcre2grep% -U -o "...." ./testdata/grepinputBad8 & popd) >>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U6 ----------------------------->>testtrygrep + (pushd %srcdir% & %pcre2grep% -u -m1 -O "=$x{1d3}$o{744}=" "fox" & popd) <%srcdir%\testdata\grepinputv >>testtrygrep 2>&1 + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U7 ------------------------------>>testtrygrep + (pushd %srcdir% & %pcre2grep% -ui --colour=always "k+|\babc\b" ./testdata/grepinput8 & popd) >>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U8 ------------------------------>>testtrygrep + (pushd %srcdir% & %pcre2grep% -UiEP --colour=always "k+|\babc\b" ./testdata/grepinput8 & popd) >>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U9 ------------------------------>>testtrygrep + (pushd %srcdir% & %pcre2grep% -u --colour=always "A\d" ./testdata/grepinput8 & popd) >>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep + + echo ---------------------------- Test U10 ------------------------------>>testtrygrep + (pushd %srcdir% & %pcre2grep% -u --posix-digit --colour=always "A\d" ./testdata/grepinput8 & popd) >>testtrygrep + echo RC=^!ERRORLEVEL!>>testtrygrep %cf% %srcdir%\testdata\grepoutput8 testtrygrep %cfout% if ERRORLEVEL 1 exit /b 1 @@ -631,58 +931,128 @@ echo Testing pcre2grep newline settings echo ---------------------------- Test N1 ------------------------------>testtrygrep %pcre2grep% -n -N CR "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep +%pcre2grep% -B1 -n -N CR "^def" testNinputgrep >>testtrygrep echo ---------------------------- Test N2 ------------------------------>>testtrygrep %pcre2grep% -n --newline=crlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep +%pcre2grep% -B1 -n -N CRLF "^ghi" testNinputgrep >>testtrygrep echo ---------------------------- Test N3 ------------------------------>>testtrygrep for /f %%a in ('%printf% "def\rjkl"') do set pattern=%%a %pcre2grep% -n --newline=cr -F "!pattern!" testNinputgrep >>testtrygrep echo ---------------------------- Test N4 ------------------------------>>testtrygrep -%pcre2grep% -n --newline=crlf -F -f %srcdir%/testdata/greppatN4 testNinputgrep >>testtrygrep +%pcre2grep% -n --newline=crlf -F -f %srcdir%\testdata\greppatN4 testNinputgrep >>testtrygrep echo ---------------------------- Test N5 ------------------------------>>testtrygrep %pcre2grep% -n --newline=any "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep +%pcre2grep% -B1 -n --newline=any "^def" testNinputgrep >>testtrygrep echo ---------------------------- Test N6 ------------------------------>>testtrygrep %pcre2grep% -n --newline=anycrlf "^(abc|def|ghi|jkl)" testNinputgrep >>testtrygrep +%pcre2grep% -B1 -n --newline=anycrlf "^jkl" testNinputgrep >>testtrygrep + +echo ---------------------------- Test N7 ------------------------------>>testtrygrep +%printf% "xyz\0abc\0def" >testNinputgrep +%pcre2grep% -na --newline=nul "^(abc|def)" testNinputgrep | %trnull% >>testtrygrep +%pcre2grep% -B1 -na --newline=nul "^(abc|def)" testNinputgrep | %trnull% >>testtrygrep +%printf% "\n" >>testtrygrep %cf% %srcdir%\testdata\grepoutputN testtrygrep %cfout% if ERRORLEVEL 1 exit /b 1 -:: If pcre2grep supports script callouts, run some tests on them. + +:: These newline tests need UTF support. + +if %utf8% neq 0 ( + echo Testing pcre2grep newline settings with UTF-8 features + + echo ---------------------------- Test UN1 ------------------------------>testtrygrep + %pcre2grep% -nau --newline=anycrlf "^(abc|def)" %srcdir%\testdata\grepinputUN >>testtrygrep + %printf% "\n" >>testtrygrep + + %cf% %srcdir%\testdata\grepoutputUN testtrygrep %cfout% + if ERRORLEVEL 1 exit /b 1 + +) else ( + echo Skipping pcre2grep newline UTF-8 tests: no UTF-8 support in PCRE2 library +) + + +:: If pcre2grep supports script callouts, run some tests on them. It is possible +:: to restrict these callouts to the non-fork case, either for security, or for +:: environments that do not support fork(). This is handled by comparing to a +:: different output. %pcre2grep% --help | %pcre2grep% -q "callout scripts in patterns are supported" if %ERRORLEVEL% equ 0 ( echo Testing pcre2grep script callouts - %pcre2grep% "(T)(..(.))(?C'cmd|/c echo|Arg1: [$1] [$2] [$3]|Arg2: ^$|${1}^$| ($4) ($14) ($0)')()" %srcdir%/testdata/grepinputv >testtrygrep - %pcre2grep% "(T)(..(.))()()()()()()()(..)(?C'cmd|/c echo|Arg1: [$11] [${11}]')" %srcdir%/testdata/grepinputv >>testtrygrep - %pcre2grep% "(T)(?C'|$0:$1$n')" %srcdir%/testdata/grepinputv >>testtrygrep - %pcre2grep% "(T)(?C'|$1$n')(*F)" %srcdir%/testdata/grepinputv >>testtrygrep - %pcre2grep% --help | %pcre2grep% -q "Non-script callout scripts in patterns are supported" - if %ERRORLEVEL% equ 0 ( + + echo --- Test 1 --->testtrygrep + %pcre2grep% "(T)(..(.))(?C'cmd|/c echo|Arg1: [$1] [$2] [$3]|Arg2: ^$|${1}^$| ($4) ($14) ($0)')()" %srcdir%\testdata\grepinputv >>testtrygrep + echo --- Test 2 --->>testtrygrep + %pcre2grep% "(T)(..(.))()()()()()()()(..)(?C'cmd|/c echo|Arg1: [$11] [${11}]')" %srcdir%\testdata\grepinputv >>testtrygrep + echo --- Test 3 --->>testtrygrep + %pcre2grep% "(T)(?C'|$0:$1$n')" %srcdir%\testdata\grepinputv >>testtrygrep + echo --- Test 4 --->>testtrygrep + %pcre2grep% "(T)(?C'cscript|//nologo|printf.js|%%s\r\n|$0:$1$n')" %srcdir%\testdata\grepinputv >>testtrygrep + echo --- Test 5 --->>testtrygrep + %pcre2grep% "(T)(?C'|$1$n')(*F)" %srcdir%\testdata\grepinputv >>testtrygrep + echo --- Test 6 --->>testtrygrep + %pcre2grep% -m1 "(T)(?C'|$0:$1:$x{41}$o{101}$n')" %srcdir%\testdata\grepinputv >>testtrygrep + + %pcre2grep% --help | %pcre2grep% -q "Non-fork callout scripts in patterns are supported" + if ^!ERRORLEVEL! equ 0 ( + set nonfork=1 %cf% %srcdir%\testdata\grepoutputCN testtrygrep %cfout% ) else ( + set nonfork=0 %cf% %srcdir%\testdata\grepoutputC testtrygrep %cfout% ) if ERRORLEVEL 1 exit /b 1 + + @REM These callout tests need UTF support. + + if %utf8% neq 0 ( + echo Testing pcre2grep script callout with UTF-8 features + + echo --- Test 1 --->testtrygrep + %pcre2grep% -u "(T)(?C'|$0:$x{a6}$n')" %srcdir%\testdata\grepinputv >>testtrygrep + echo --- Test 2 --->>testtrygrep + %pcre2grep% -u "(T)(?C'cscript|//nologo|printf.js|%%s\r\n|$0:$x{a6}$n')" %srcdir%\testdata\grepinputv >>testtrygrep + + if ^!nonfork! equ 1 ( + %cf% %srcdir%\testdata\grepoutputCNU testtrygrep %cfout% + ) else ( + %cf% %srcdir%\testdata\grepoutputCU testtrygrep %cfout% + ) + if ERRORLEVEL 1 exit /b 1 + + ) else ( + echo Skipping pcre2grep script callout UTF-8 tests: no UTF-8 support in PCRE2 library + ) + ) else ( echo Script callouts are not supported ) + :: Finally, some tests to exercise code that is not tested above, just to be :: sure that it runs OK. Doing this improves the coverage statistics. The output :: is not checked. echo Testing miscellaneous pcre2grep arguments (unchecked) -%printf% "" >testtrygrep +echo. >nul 2>testtrygrep call :checkspecial "-xxxxx" 2 || exit /b 1 call :checkspecial "--help" 0 || exit /b 1 call :checkspecial "--line-buffered --colour=auto abc nul" 1 || exit /b 1 +call :checkspecial "--line-buffered --color abc nul" 1 || exit /b 1 +call :checkspecial "-dskip abc ." 1 || exit /b 1 +call :checkspecial "-Dread -Dskip abc nul" 1 || exit /b 1 + :: Clean up local working files -del testcf printf.js testNinputgrep teststderrgrep testtrygrep testtemp1grep testtemp2grep +del testcf printf.js trnull.js testNinputgrep teststderrgrep testtrygrep testtemp1grep testtemp2grep exit /b 0 diff --git a/RunTest.bat b/RunTest.bat index d0b9f7e8d..3b6f7f5cf 100644 --- a/RunTest.bat +++ b/RunTest.bat @@ -141,9 +141,9 @@ if "%all%" == "yes" ( set do7=yes set do8=yes set do9=yes - set do10=no + set do10=yes set do11=yes - set do12=no + set do12=yes set do13=yes set do14=yes set do15=yes diff --git a/src/pcre2grep.c b/src/pcre2grep.c index 1ad91da98..083b13f7b 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -2528,6 +2528,7 @@ while (length > 0) necessary, otherwise assume fork(). */ #ifdef WIN32 +(void)fflush(stdout); result = _spawnvp(_P_WAIT, argsvector[0], (const char * const *)argsvector); #elif defined __VMS @@ -2551,6 +2552,7 @@ result = _spawnvp(_P_WAIT, argsvector[0], (const char * const *)argsvector); } #else /* Neither Windows nor VMS */ +(void)fflush(stdout); pid = fork(); if (pid == 0) { @@ -2560,9 +2562,7 @@ if (pid == 0) } else if (pid > 0) { - (void)fflush(stdout); (void)waitpid(pid, &result, 0); - (void)fflush(stdout); } #endif /* End Windows/VMS/other handling */ diff --git a/testdata/grepinputBad8 b/testdata/grepinputBad8 new file mode 100644 index 000000000..af52f08d5 --- /dev/null +++ b/testdata/grepinputBad8 @@ -0,0 +1 @@ +Aက€CD Z diff --git a/testdata/grepinputUN b/testdata/grepinputUN new file mode 100644 index 000000000..dd4a8cca9 --- /dev/null +++ b/testdata/grepinputUN @@ -0,0 +1,2 @@ +abcሴdef +xyz \ No newline at end of file diff --git a/testdata/grepoutput b/testdata/grepoutput index 94b951264..379eb2498 100644 --- a/testdata/grepoutput +++ b/testdata/grepoutput @@ -493,7 +493,9 @@ RC=0 ./testdata/grepinput:456 ./testdata/grepinput3:0 ./testdata/grepinput8:0 +./testdata/grepinputBad8:0 ./testdata/grepinputM:0 +./testdata/grepinputUN:0 ./testdata/grepinputv:1 ./testdata/grepinputx:0 RC=0 @@ -722,6 +724,7 @@ RC=0 ---------------------------- Test 96 ----------------------------- ./testdata/grepinput3 ./testdata/grepinput8 +./testdata/grepinputBad8 ./testdata/grepinputx RC=0 ---------------------------- Test 97 ----------------------------- @@ -833,7 +836,9 @@ RC=0 testdata/grepinput:469 testdata/grepinput3:0 testdata/grepinput8:0 +testdata/grepinputBad8:0 testdata/grepinputM:2 +testdata/grepinputUN:0 testdata/grepinputv:3 testdata/grepinputx:6 TOTAL:480 @@ -852,7 +857,9 @@ RC=0 469 0 0 +0 2 +0 3 6 480 @@ -860,6 +867,8 @@ RC=0 ---------------------------- Test 118 ----------------------------- testdata/grepinput3 testdata/grepinput8 +testdata/grepinputBad8 +testdata/grepinputUN RC=0 ---------------------------- Test 119 ----------------------------- 123 @@ -1238,6 +1247,7 @@ RC=2 The word is cat in this line The caterpillar sat on the mat The snowcat is not an animal +RC=0 ---------------------------- Test 152 ----------------------------- 24:four 25-five diff --git a/testdata/grepoutputC b/testdata/grepoutputC index 56bd283b3..290a35dd8 100644 --- a/testdata/grepoutputC +++ b/testdata/grepoutputC @@ -1,3 +1,4 @@ +--- Test 1 --- Arg1: [T] [he ] [ ] Arg2: |T| () () (0) The quick brown Arg1: [T] [his] [s] Arg2: |T| () () (0) @@ -10,6 +11,7 @@ Arg1: [T] [he ] [ ] Arg2: |T| () () (0) The caterpillar sat on the mat Arg1: [T] [he ] [ ] Arg2: |T| () () (0) The snowcat is not an animal +--- Test 2 --- Arg1: [qu] [qu] The quick brown Arg1: [ t] [ t] @@ -22,6 +24,7 @@ Arg1: [ca] [ca] The caterpillar sat on the mat Arg1: [sn] [sn] The snowcat is not an animal +--- Test 3 --- 0:T The quick brown 0:T @@ -34,6 +37,7 @@ The word is cat in this line The caterpillar sat on the mat 0:T The snowcat is not an animal +--- Test 4 --- 0:T The quick brown @@ -52,11 +56,13 @@ The caterpillar sat on the mat 0:T The snowcat is not an animal +--- Test 5 --- T T T T T T +--- Test 6 --- 0:T:AA The quick brown diff --git a/testdata/grepoutputCN b/testdata/grepoutputCN index aef1a3df0..f6ae7a9de 100644 --- a/testdata/grepoutputCN +++ b/testdata/grepoutputCN @@ -1,15 +1,18 @@ +--- Test 1 --- The quick brown This time it jumps and jumps and jumps. This line contains \E and (regex) *meta* [characters]. The word is cat in this line The caterpillar sat on the mat The snowcat is not an animal +--- Test 2 --- The quick brown This time it jumps and jumps and jumps. This line contains \E and (regex) *meta* [characters]. The word is cat in this line The caterpillar sat on the mat The snowcat is not an animal +--- Test 3 --- 0:T The quick brown 0:T @@ -22,17 +25,20 @@ The word is cat in this line The caterpillar sat on the mat 0:T The snowcat is not an animal +--- Test 4 --- The quick brown This time it jumps and jumps and jumps. This line contains \E and (regex) *meta* [characters]. The word is cat in this line The caterpillar sat on the mat The snowcat is not an animal +--- Test 5 --- T T T T T T +--- Test 6 --- 0:T:AA The quick brown diff --git a/testdata/grepoutputCNU b/testdata/grepoutputCNU index 2fbfba0f3..454cf21e4 100644 --- a/testdata/grepoutputCNU +++ b/testdata/grepoutputCNU @@ -1,3 +1,4 @@ +--- Test 1 --- 0:¦ The quick brown 0:¦ @@ -10,6 +11,7 @@ The word is cat in this line The caterpillar sat on the mat 0:¦ The snowcat is not an animal +--- Test 2 --- The quick brown This time it jumps and jumps and jumps. This line contains \E and (regex) *meta* [characters]. diff --git a/testdata/grepoutputCU b/testdata/grepoutputCU index ed8f491ed..96661fe7c 100644 --- a/testdata/grepoutputCU +++ b/testdata/grepoutputCU @@ -1,3 +1,4 @@ +--- Test 1 --- 0:¦ The quick brown 0:¦ @@ -10,6 +11,7 @@ The word is cat in this line The caterpillar sat on the mat 0:¦ The snowcat is not an animal +--- Test 2 --- 0:¦ The quick brown