summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2015-12-30 23:22:36 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2015-12-30 23:23:30 -0800
commit413fe0e603740b9cdeb49d61aa789f7254e13d18 (patch)
tree507e6771bb2b898de7f8b24dcbabff15d944e5f0 /tests
parent5827733ce621bb169afc4f9220cc4624124fc7ba (diff)
downloadgrep-413fe0e603740b9cdeb49d61aa789f7254e13d18.tar.gz
grep: -c should keep counting after binary data
Problem and fix reported by Jaroslav Škarvada, and test case reported by Norihiro Tanaka, in: http://bugs.gnu.org/22028 * NEWS: Document this. * src/grep.c (grep): Don't stop counting merely because nulls seen. * tests/pcre-count: New file. * tests/Makefile.am (TESTS): Add it.
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile.am1
-rwxr-xr-xtests/pcre-count23
2 files changed, 24 insertions, 0 deletions
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f1b8c436..e8b11b5a 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -106,6 +106,7 @@ TESTS = \
pcre \
pcre-abort \
pcre-context \
+ pcre-count \
pcre-infloop \
pcre-invalid-utf8-infloop \
pcre-invalid-utf8-input \
diff --git a/tests/pcre-count b/tests/pcre-count
new file mode 100755
index 00000000..78e1c7cc
--- /dev/null
+++ b/tests/pcre-count
@@ -0,0 +1,23 @@
+#! /bin/sh
+# grep -P / grep -Pc are inconsistent results
+# This bug affected grep versions 2.21 through 2.22.
+#
+# Copyright (C) 2015 Free Software Foundation, Inc.
+#
+# Copying and distribution of this file, with or without modification,
+# are permitted in any medium without royalty provided the copyright
+# notice and this notice are preserved.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+require_pcre_
+
+fail=0
+
+printf 'a\n%032768d\nb\x0\n%032768d\na\n' 0 0 > in
+
+LC_ALL=C grep -P 'a' in | wc -l > exp
+
+LC_ALL=C grep -Pc 'a' in > out || fail=1
+compare exp out || fail=1
+
+Exit $fail