[glib] regex test: Check the expected PCRE version at runtime



commit db90987990bf303d30668c966da9bcfdeb3ac174
Author: Iain Lane <iain orangesquash org uk>
Date:   Fri Jan 15 17:56:40 2016 +0000

    regex test: Check the expected PCRE version at runtime
    
    We might be built against a newer version than we're run against.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=760683

 glib/tests/Makefile.am |   13 ++++++++++++-
 glib/tests/regex.c     |   37 +++++++++++++++++++++++++++++--------
 2 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/glib/tests/Makefile.am b/glib/tests/Makefile.am
index 4bdbf58..57c00b0 100644
--- a/glib/tests/Makefile.am
+++ b/glib/tests/Makefile.am
@@ -1,9 +1,20 @@
 include $(top_srcdir)/glib-tap.mk
 
+if USE_SYSTEM_PCRE
+pcre_lib = $(PCRE_LIBS)
+pcre_inc = $(PCRE_CFLAGS)
+else
+pcre_lib = pcre/libpcre.la
+pcre_inc =
+endif
+
 LDADD = $(top_builddir)/glib/libglib-2.0.la -lm
 AM_CPPFLAGS = -g $(glib_INCLUDES) $(GLIB_DEBUG_FLAGS)
 DEFS = -DG_LOG_DOMAIN=\"GLib\" -DEXEEXT=\"$(EXEEXT)\"
-AM_CFLAGS = $(GLIB_WARN_CFLAGS)
+AM_CFLAGS = $(GLIB_WARN_CFLAGS) $(pcre_inc)
+
+# The regex test uses pcre_version()
+regex_LDADD = $(LDADD) $(pcre_lib)
 
 # These tests corrupt the gcov bookkeeping, so we
 # skip them. See bug 682133
diff --git a/glib/tests/regex.c b/glib/tests/regex.c
index ad3fdad..f021940 100644
--- a/glib/tests/regex.c
+++ b/glib/tests/regex.c
@@ -2165,6 +2165,24 @@ test_max_lookbehind (void)
   g_regex_unref (regex);
 }
 
+static gboolean
+pcre_ge (guint64 major, guint64 minor)
+{
+    const char *version;
+    gchar *ptr;
+    guint64 pcre_major, pcre_minor;
+
+    /* e.g. 8.35 2014-04-04 */
+    version = pcre_version ();
+
+    pcre_major = g_ascii_strtoull (version, &ptr, 10);
+    /* ptr points to ".MINOR (release date)" */
+    g_assert (ptr[0] == '.');
+    pcre_minor = g_ascii_strtoull (ptr + 1, NULL, 10);
+
+    return (pcre_major > major) || (pcre_major == major && pcre_minor >= minor);
+}
+
 int
 main (int argc, char *argv[])
 {
@@ -2261,14 +2279,17 @@ main (int argc, char *argv[])
   TEST_NEW_FAIL ("^(?(0)f|b)oo", 0, G_REGEX_ERROR_INVALID_CONDITION);
   TEST_NEW_FAIL ("(?<=\\C)X", 0, G_REGEX_ERROR_SINGLE_BYTE_MATCH_IN_LOOKBEHIND);
   TEST_NEW_FAIL ("(?!\\w)(?R)", 0, G_REGEX_ERROR_INFINITE_LOOP);
-#if PCRE_MAJOR > 8 || (PCRE_MAJOR == 8 && PCRE_MINOR >= 37)
-  /* The expected errors changed here. */
-  TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
-  TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_ASSERTION_EXPECTED);
-#else
-  TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_BACK_REFERENCE);
-  TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
-#endif
+  if (pcre_ge (8, 37))
+    {
+      /* The expected errors changed here. */
+      TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
+      TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_ASSERTION_EXPECTED);
+    }
+  else
+    {
+      TEST_NEW_FAIL ("(?P<sub>foo)\\g<sub", 0, G_REGEX_ERROR_MISSING_BACK_REFERENCE);
+      TEST_NEW_FAIL ("(?(?<ab))", 0, G_REGEX_ERROR_MISSING_SUBPATTERN_NAME_TERMINATOR);
+    }
   TEST_NEW_FAIL ("(?P<x>eks)(?P<x>eccs)", 0, G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME);
 #if 0
   TEST_NEW_FAIL (?, 0, G_REGEX_ERROR_MALFORMED_PROPERTY);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]