summaryrefslogtreecommitdiffstats
path: root/src/grep/tests/null-byte
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:21:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-11 08:21:29 +0000
commit29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc (patch)
tree63ef546b10a81d461e5cf5ed9e98a68cd7dee1aa /src/grep/tests/null-byte
parentInitial commit. (diff)
downloadkbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.tar.xz
kbuild-29cd838eab01ed7110f3ccb2e8c6a35c8a31dbcc.zip
Adding upstream version 1:0.1.9998svn3589+dfsg.upstream/1%0.1.9998svn3589+dfsg
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/grep/tests/null-byte')
-rwxr-xr-xsrc/grep/tests/null-byte68
1 files changed, 68 insertions, 0 deletions
diff --git a/src/grep/tests/null-byte b/src/grep/tests/null-byte
new file mode 100755
index 0000000..9402c2b
--- /dev/null
+++ b/src/grep/tests/null-byte
@@ -0,0 +1,68 @@
+#!/bin/sh
+# Test NUL bytes in patterns and data.
+
+# Copyright 2014-2021 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+# Add "." to PATH for the use of get-mb-cur-max.
+path_prepend_ .
+
+locales=C
+for locale in en_US.iso885915 en_US.UTF-8; do
+ get-mb-cur-max en_US.UTF-8 >/dev/null 2>&1 && locales="$locales $locale"
+done
+
+fail=0
+
+for left in '' a '#' '\0'; do
+ for right in '' b '#' '\0'; do
+ data="$left\\0$right"
+ printf "$data\\n" >in || framework_failure_
+ for hat in '' '^'; do
+ for dollar in '' '$'; do
+ for force_regex in '' '\\(\\)\\1'; do
+ pat="$hat$force_regex$data$dollar"
+ printf "$pat\\n" >pat || framework_failure_
+ for locale in $locales; do
+ LC_ALL=$locale grep -f pat in
+ status=$?
+ test $status -eq 0 || test $status -eq 1 ||
+ fail_ "'$pat' caused an error"
+ LC_ALL=$locale grep -a -f pat in | cmp -s - in ||
+ fail_ "-a '$pat' does not match '$data'"
+ done
+ done
+ done
+ done
+ done
+done
+
+(echo xxx && yes yyy | sed 100000q && printf 'z\n\0') >in || framework_failure_
+echo xxx >exp || framework_failure_
+grep xxx in >out || fail=1
+compare exp out || fail=1
+
+printf 'xxx\n' > exp || framework_failure_
+grep -E 'xxx|z' in >out || fail=1
+compare exp out || fail=1
+
+printf '%s\0' 'abcadc' >in || framework_failure_
+printf '%s\0' 'abc' 'adc' >exp || framework_failure_
+grep -oz 'a[^c]*c' in >out || fail=1
+compare exp out || fail=1
+
+Exit $fail