From 92bbd8ca21222da65ea62d69795aa82d8974b538 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@fb.com>
Date: Mon, 8 Sep 2014 07:52:19 -0700
Subject: [PATCH 1/2] tests: add expect-to-fail test for a glibc regexp bug

* tests/triple-backref: New file.
* tests/Makefile.am (TESTS): Add it.
(XFAIL_TESTS): List it as a known, always-failing test.
Based on the bug report from Paul Eggert:
        https://sourceware.org/bugzilla/show_bug.cgi?id=17356
---
 tests/Makefile.am    |  3 ++-
 tests/triple-backref | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100755 tests/triple-backref

diff --git a/tests/Makefile.am b/tests/Makefile.am
index 31e2a81..d47978f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -22,7 +22,7 @@ AM_CFLAGS = $(WARN_CFLAGS) $(WERROR_CFLAGS)
 AM_LDFLAGS = $(IGNORE_UNUSED_LIBRARIES_CFLAGS)
 LDADD = ../lib/libgreputils.a $(LIBINTL) ../lib/libgreputils.a

-XFAIL_TESTS =
+XFAIL_TESTS = triple-backref

 # Equivalence classes are only supported when using the system
 # matcher (which means only with glibc).
@@ -104,6 +104,7 @@ TESTS =						\
   status					\
   surrogate-pair				\
   symlink					\
+  triple-backref				\
   turkish-eyes					\
   turkish-I					\
   turkish-I-without-dot				\
diff --git a/tests/triple-backref b/tests/triple-backref
new file mode 100755
index 0000000..6701819
--- /dev/null
+++ b/tests/triple-backref
@@ -0,0 +1,35 @@
+#! /bin/sh
+# Test for a bug in glibc's regex code as of September 7, 2014.
+#
+# Copyright (C) 2014 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
+
+# FIXME-2014: once the glibc bug is fixed, remove this skip-if-glibc guard.
+# Since this tests for an as-yet-unfixed bug in glibc,
+# we expect it to fail on such systems.
+# Since we expect this test to fail, we must skip this test on
+# non-glibc systems.
+cat <<\EOF > glibc.c
+#include <features.h>
+#if defined __GNU_LIBRARY__ && __GLIBC__ >= 2
+#else
+"run this test only with glibc"
+#endif
+EOF
+$CC -c glibc.c \
+  || skip_ 'this test runs only on systems with glibc'
+
+echo a > in || framework_failure_
+
+fail=0
+grep -E '(.?)(.?)(.?)\3\2\1' in > out || fail=1
+compare out in || fail=1
+
+Exit $fail
-- 
2.0.0.421.g786a89d

