From e448e86b5c01c0a98b16e84d61ede7940170bb5b Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Sat, 1 Apr 2023 21:01:01 -0700
Subject: [PATCH] tests: add a known-failing glibc-infloop test

* tests/glibc-infloop: New file.
Based on the command from Koen Claessen
reported in https://bugs.gnu.org/62483
* tests/Makefile.am (TESTS): Add the file name
* THANKS.in: Add name of reporter.
---
 THANKS.in           |  1 +
 tests/Makefile.am   |  3 +++
 tests/glibc-infloop | 13 +++++++++++++
 3 files changed, 17 insertions(+)
 create mode 100755 tests/glibc-infloop

diff --git a/THANKS.in b/THANKS.in
index fd36192..06f8c54 100644
--- a/THANKS.in
+++ b/THANKS.in
@@ -56,6 +56,7 @@ Karl Pettersson                     karl.pettersson@klpn.se
 Kaveh R. Ghazi                      ghazi@caip.rutgers.edu
 Kazuro Furukawa                     furukawa@apricot.kek.jp
 Keith Bostic                        bostic@bsdi.com
+Koen Claessen                       koen@chalmers.se
 Krishna Sethuraman                  krishna@sgihub.corp.sgi.com
 Kurt D Schwehr                      kdschweh@insci14.ucsd.edu
 Ludovic Courtès                     ludo@gnu.org
diff --git a/tests/Makefile.am b/tests/Makefile.am
index f195c8d..0c3adbe 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -49,6 +49,8 @@ LDADD = ../lib/libgreputils.a $(LIBINTL) ../lib/libgreputils.a
 # FIXME-2015: Remove this once the glibc and gnulib bugs are fixed.
 XFAIL_TESTS = triple-backref

+XFAIL_TESTS += glibc-infloop
+
 # Equivalence classes are only supported when using the system
 # matcher (which means only with glibc).
 # The included matcher needs to be fixed.
@@ -108,6 +110,7 @@ TESTS =						\
   fillbuf-long-line				\
   fmbtest					\
   foad1						\
+  glibc-infloop					\
   grep-dev-null					\
   grep-dev-null-out				\
   grep-dir					\
diff --git a/tests/glibc-infloop b/tests/glibc-infloop
new file mode 100755
index 0000000..6244b6b
--- /dev/null
+++ b/tests/glibc-infloop
@@ -0,0 +1,13 @@
+#!/bin/sh
+# This would infloop when using glibc's regex at least until glibc-2.36.
+. "${srcdir=.}/init.sh"; path_prepend_ ../src
+
+require_timeout_
+require_en_utf8_locale_
+
+fail=0
+
+echo a > in || framework_failure_
+returns_ 0 timeout 2 env LC_ALL=en_US.UTF-8 grep -E -w '((()|a)|())*' in || fail=1
+
+Exit $fail
-- 
2.40.0.166.g140b9478da

