From 4c7e42e9d5b54dba43b5e40d3d172ee648d86a16 Mon Sep 17 00:00:00 2001 From: Iain Lane Date: Fri, 15 Jan 2016 17:56:40 +0000 Subject: [PATCH] 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 23f29401e..9d0de5edb 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 ad3fdad5d..f021940b1 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 ("(?Pfoo)\\gfoo)\\gfoo)\\gfoo)\\geks)(?Peccs)", 0, G_REGEX_ERROR_DUPLICATE_SUBPATTERN_NAME); #if 0 TEST_NEW_FAIL (?, 0, G_REGEX_ERROR_MALFORMED_PROPERTY);