summaryrefslogtreecommitdiffstats
path: root/src/grep/tests/backref
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsrc/grep/tests/backref46
-rwxr-xr-xsrc/grep/tests/backref-alt34
-rwxr-xr-xsrc/grep/tests/backref-multibyte-slow33
-rwxr-xr-xsrc/grep/tests/backref-word18
4 files changed, 131 insertions, 0 deletions
diff --git a/src/grep/tests/backref b/src/grep/tests/backref
new file mode 100755
index 0000000..947981b
--- /dev/null
+++ b/src/grep/tests/backref
@@ -0,0 +1,46 @@
+#! /bin/sh
+# Test for back-references and other things.
+#
+# Copyright (C) 2001, 2006, 2009-2021 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
+
+failures=0
+
+# checking for a palindrome
+echo "radar" | grep -e '\(.\)\(.\).\2\1' > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "Backref: palindrome, test #1 failed"
+ failures=1
+fi
+
+# hit hard with the 'Bond' tests
+# For now, remove the '?' in the last parentheses, so that new glibc can do it.
+# --Stepan
+echo "civic" \
+ | grep -E -e '^(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.?)(.).?\9\8\7\6\5\4\3\2\1$' \
+ > /dev/null 2>&1
+if test $? -ne 0 ; then
+ echo "Options: Bond, test #2 failed"
+ failures=1
+fi
+
+# backref are local should be error
+echo "123" | grep -e 'a\(.\)' -e 'b\1' > /dev/null 2>&1
+if test $? -ne 2 ; then
+ echo "Backref: Backref not local, test #3 failed"
+ failures=1
+fi
+
+# Pattern should fail
+echo "123" | grep -e '[' -e ']' > /dev/null 2>&1
+if test $? -ne 2 ; then
+ echo "Backref: Compiled not local, test #4 failed"
+ failures=1
+fi
+
+Exit $failures
diff --git a/src/grep/tests/backref-alt b/src/grep/tests/backref-alt
new file mode 100755
index 0000000..986621b
--- /dev/null
+++ b/src/grep/tests/backref-alt
@@ -0,0 +1,34 @@
+#! /bin/sh
+# Test for a bug in glibc's regex code as of 2015-09-19.
+#
+# Copyright 2015-2021 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
+
+echo aa > in || framework_failure_
+
+fail=0
+
+grep -E 'b|(.)b|\1|b' in >out
+status=$?
+# POSIX isn't clear whether this regular expression should be invalid,
+# (because the \1 is out of range for REs that could precede it)
+# or valid but \1 should not match. Allow either interpretation.
+test $status -eq 2 || test $status -eq 1 || fail=1
+
+grep -E '0|()0|\1|0' in >out
+status=$?
+test $status -eq 2 || test $status -eq 1 || fail=1
+
+# This test is a reduced version of the one in Bug#27838.
+# It triggers this glibc assertion failure:
+# grep: regexec.c:1342: pop_fail_stack: Assertion `num >= 0' failed.
+LC_ALL=C grep -E '(()x)|\2' in > out
+status=$?
+test $status -eq 2 || test $status -eq 1 || fail=1
+
+Exit $fail
diff --git a/src/grep/tests/backref-multibyte-slow b/src/grep/tests/backref-multibyte-slow
new file mode 100755
index 0000000..9c4fe06
--- /dev/null
+++ b/src/grep/tests/backref-multibyte-slow
@@ -0,0 +1,33 @@
+#!/bin/sh
+# This was approximately quadratic up to grep-2.6.3
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+require_en_utf8_locale_
+require_timeout_
+
+fail=0
+
+# Create a 13000-line input
+$AWK 'BEGIN {for (i=0; i<13000; i++) print "aba"}' /dev/null > in || fail=1
+
+# Use 10 times the duration of running grep in the C locale as the timeout
+# when running in en_US.UTF-8. Round up to whole seconds, since timeout
+# can't deal with fractional seconds.
+max_seconds=$(LC_ALL=C perl -le 'use Time::HiRes qw(time); my $s = time();
+ system q,grep -E '\''^([a-z]).\1$'\'' in > junk,;
+ my $elapsed = time() - $s; print int (1 + 10 * $elapsed)') \
+ || { max_seconds=5;
+ warn_ "$ME_: warning: no perl? using default of 5s timeout"; }
+
+# If the above finished so quickly that we'd have a 1-second timeout,
+# increase it to a duration less likely to arise in a parallel test run.
+test $max_seconds = 1 && max_seconds=5
+
+for LOC in en_US.UTF-8; do
+ out=out-$LOC
+ LC_ALL=$LOC timeout ${max_seconds}s grep -aE '^([a-z]).\1$' in > $out 2>&1 \
+ || fail=1
+ compare $out in || fail=1
+done
+
+Exit $fail
diff --git a/src/grep/tests/backref-word b/src/grep/tests/backref-word
new file mode 100755
index 0000000..e5b5486
--- /dev/null
+++ b/src/grep/tests/backref-word
@@ -0,0 +1,18 @@
+#!/bin/sh
+# This would fail for grep-2.6
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+printf 'foo foo bar\n' > exp1 || framework_failure_
+fail=0
+
+for LOC in en_US.UTF-8 zh_CN $LOCALE_FR_UTF8; do
+ out=out1-$LOC
+ LC_ALL=$LOC grep -w '\(foo\) \1' exp1 > $out || fail=1
+ compare exp1 $out || fail=1
+
+ LC_ALL=$LOC grep -wx '\(foo\) \1' exp1 > $out
+ test $? -eq 1 || fail=1
+ compare /dev/null $out || fail=1
+done
+
+Exit $fail