Skip to content

Commit

Permalink
Add PCRE support for regular expressions into tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dotsenko Andrey committed Dec 25, 2016
1 parent dcf59ad commit 9b31224
Show file tree
Hide file tree
Showing 5 changed files with 120 additions and 21 deletions.
28 changes: 26 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,17 @@ else(HAVE_MKSTEMP)
set(HAVE_MKSTEMP 0)
endif(HAVE_MKSTEMP)

if (NOT DEFINED WITH_PCREPOSIX)
set(WITH_PCREPOSIX auto)
endif()

if(HAVE_REGEX_H AND HAVE_REGCOMP AND HAVE_REGEXEC)
add_definitions(-DHAVE_REGEX=1)
set(HAVE_REGEX 1)
add_definitions(-DENABLE_REGEX=1)
set(ENABLE_REGEX 1)
if ((NOT WITH_PCREPOSIX) OR (WITH_PCREPOSIX STREQUAL "auto"))
add_definitions(-DENABLE_REGEX=1)
set(ENABLE_REGEX 1)
endif()
endif()


Expand Down Expand Up @@ -312,6 +318,24 @@ else(HAVE_SUBUNIT)
add_definitions(-DENABLE_SUBUNIT=0)
endif (HAVE_SUBUNIT)

if (NOT ENABLE_REGEX AND WITH_PCREPOSIX)
# pcreposix functions are just wrappers for pcre functions
check_library_exists(pcreposix regcomp "" HAVE_LIBPCREPOSIX)
if (HAVE_LIBPCREPOSIX)
check_function_exists(regcomp HAVE_REGCOMP)
check_function_exists(regexec HAVE_REGEXEC)
if (HAVE_REGCOMP AND HAVE_REGEXEC)
set(PCREPOSIX "pcreposix")
set(ENABLE_PCREPOSIX 1)
add_definitions(-DENABLE_PCREPOSIX=1)
endif()
endif()
if (ENABLE_PCREPOSIX)
set(ENABLE_REGEX 1)
add_definitions(-DENABLE_REGEX=1)
endif()
endif()

###############################################################################
# Generate "config.h" from "cmake/config.h.cmake"
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/cmake/config.h.in
Expand Down
69 changes: 65 additions & 4 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,25 @@ AC_HELP_STRING([--enable-timer-replacement],
*) AC_MSG_ERROR(bad value ${enableval} for --enable-timer-replacement) ;;
esac], [enable_timer_replacement=autodetect ])

AC_ARG_ENABLE(pcreposix,
AC_HELP_STRING([--enable-pcreposix],
[enable support for the pcreposix regular expressions @<:@default=autodetect@:>@]),
[case "${enableval}" in
yes)
with_pcreposix=1
echo "Enabled PCRE POSIX regular expressions"
;;
no)
with_pcreposix=0
echo "Disabled PCRE POSIX regular expressions"
;;
autodetect)
echo "PCRE POSIX regular expressions support will be enabled automatically."
;;
*) AC_MSG_ERROR(bad value ${enableval} for --enable-pcreposix) ;;
esac],
[echo "PCRE POSIX regular expressions support will be enabled automatically."
with_pcreposix=autodetect])

# Checks for programs.
AC_PROG_SED
Expand Down Expand Up @@ -257,11 +276,49 @@ fi
AC_SUBST(HAVE_REGEX)
AC_DEFINE_UNQUOTED(HAVE_REGEX, $HAVE_REGEX, "Regular expressions are supported")

if test "x$HAVE_REGEX" = "x1"; then
if test "x$HAVE_REGEX" = "x1" && test "x$with_pcreposix" != "x1"; then
ENABLE_REGEX="1"
else
ENABLE_REGEX="0"
fi

if test "x$ENABLE_REGEX" = "x0"; then
# Check for PCRE POSIX regular expressions support.
AS_IF([test x"$with_pcreposix" != "x0" && test x"$with_pcreposix" != "x1"], [
PKG_CHECK_EXISTS([libpcreposix], [:], [with_pcreposix=0])
])
AS_IF([test x"$with_pcreposix" != "x0"], [
PKG_CHECK_MODULES([PCREPOSIX], [libpcreposix])
])

if test "x0" = x"$with_pcreposix"; then
ENABLE_PCREPOSIX="0"
else
ENABLE_PCREPOSIX="1"
fi

if test "x$ENABLE_PCREPOSIX" = "x1"; then
ENABLE_REGEX="1"
else
ENABLE_REGEX="0"
fi
else
ENABLE_PCREPOSIX="0"
fi

if test "x0" = x"$ENABLE_PCREPOSIX"; then
LIBPCREPOSIX_PC=""
else
LIBPCREPOSIX_PC="libpcreposix"
fi

AC_SUBST(ENABLE_PCREPOSIX)
AC_SUBST([LIBPCREPOSIX_PC])
AC_DEFINE_UNQUOTED(ENABLE_PCREPOSIX, $ENABLE_PCREPOSIX, [PCRE POSIX regular expressions])

AM_CONDITIONAL(PCREPOSIX, test x"$ENABLE_PCREPOSIX" != "x0")


AC_SUBST(ENABLE_REGEX)
AC_DEFINE_UNQUOTED(ENABLE_REGEX, $ENABLE_REGEX, "Regular expressions are supported and enabled")

Expand Down Expand Up @@ -369,7 +426,7 @@ AC_OUTPUT
# Finally, print a summary of the Check's compile options

echo
echo "=========================================="
echo "================================================"
echo "Summary of Check $CHECK_MAJOR_VERSION.$CHECK_MINOR_VERSION.$CHECK_MICRO_VERSION options:"
echo

Expand Down Expand Up @@ -423,8 +480,12 @@ echo "timeout unit tests ................... $result"
if test "x0" = x"$ENABLE_REGEX"; then
result="no"
else
result="yes"
if test "x1" = x"$ENABLE_PCREPOSIX"; then
result="pcreposix"
else
result="yes"
fi
fi
echo "POSIX regular expressions ............ $result"

echo "=========================================="
echo "================================================"
20 changes: 15 additions & 5 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,17 @@ set(CHECK_CHECK_SOURCES
check_list.c)
set(CHECK_CHECK_HEADERS check_check.h)
add_executable(check_check ${CHECK_CHECK_HEADERS} ${CHECK_CHECK_SOURCES})
target_link_libraries(check_check check compat)

set(CHECK_CHECK_LIBRARIES
check
compat)
if(ENABLE_PCREPOSIX)
list(APPEND
CHECK_CHECK_LIBRARIES
pcreposix)
endif()

target_link_libraries(check_check ${CHECK_CHECK_LIBRARIES})

set(CHECK_CHECK_EXPORT_SOURCES
check_check_sub.c
Expand All @@ -72,16 +82,16 @@ set(CHECK_CHECK_EXPORT_HEADERS check_check.h)
add_executable(check_check_export
${CHECK_CHECK_EXPORT_HEADERS}
${CHECK_CHECK_EXPORT_SOURCES})
target_link_libraries(check_check_export check compat)
target_link_libraries(check_check_export ${CHECK_CHECK_LIBRARIES})

set(EX_OUTPUT_SOURCES ex_output.c)
add_executable(ex_output ${EX_OUTPUT_SOURCES})
target_link_libraries(ex_output check compat)
target_link_libraries(ex_output ${CHECK_CHECK_LIBRARIES})

set(CHECK_NOFORK_SOURCES check_nofork.c)
add_executable(check_nofork ${CHECK_NOFORK_SOURCES})
target_link_libraries(check_nofork check compat)
target_link_libraries(check_nofork ${CHECK_CHECK_LIBRARIES})

set(CHECK_NOFORK_TEARDOWN_SOURCES check_nofork_teardown.c)
add_executable(check_nofork_teardown ${CHECK_NOFORK_TEARDOWN_SOURCES})
target_link_libraries(check_nofork_teardown check compat)
target_link_libraries(check_nofork_teardown ${CHECK_CHECK_LIBRARIES})
14 changes: 7 additions & 7 deletions tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ check_check_export_SOURCES = \
check_check_fork.c \
check_check_tags.c \
check_check_export_main.c
check_check_export_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
check_check_export_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la

check_check_SOURCES = \
check_check.h \
Expand All @@ -61,7 +61,7 @@ check_check_SOURCES = \
check_check_selective.c \
check_check_tags.c \
check_check_main.c
check_check_LDADD = $(top_builddir)/src/libcheckinternal.la $(top_builddir)/lib/libcompat.la
check_check_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheckinternal.la $(top_builddir)/lib/libcompat.la

check_mem_leaks_SOURCES = \
check_mem_leaks.c \
Expand All @@ -72,21 +72,21 @@ check_mem_leaks_SOURCES = \
check_check_tags.c \
check_check_sub.c \
check_check_master.c
check_mem_leaks_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
check_mem_leaks_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
check_mem_leaks_CFLAGS = -DTIMEOUT_TESTS_ENABLED=0 -DMEMORY_LEAKING_TESTS_ENABLED=0

check_stress_SOURCES = check_stress.c
check_stress_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
check_stress_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la

check_thread_stress_SOURCES = check_thread_stress.c
check_thread_stress_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la @PTHREAD_LIBS@
check_thread_stress_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la @PTHREAD_LIBS@
check_thread_stress_CFLAGS = @PTHREAD_CFLAGS@

check_nofork_SOURCES = check_nofork.c
check_nofork_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
check_nofork_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la

check_nofork_teardown_SOURCES = check_nofork_teardown.c
check_nofork_teardown_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
check_nofork_teardown_LDADD = $(PCREPOSIX_LIBS) $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la

ex_output_SOURCES = ex_output.c
ex_output_LDADD = $(top_builddir)/src/libcheck.la $(top_builddir)/lib/libcompat.la
Expand Down
10 changes: 7 additions & 3 deletions tests/check_check_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#if ENABLE_REGEX
# include <regex.h>
#endif
#include <check.h>
#include <assert.h>
#include "check_check.h"
#if ENABLE_REGEX
# if ENABLE_PCREPOSIX
# include <pcreposix.h>
# else
# include <regex.h>
# endif
#endif

int sub_nfailed;
int sub_ntests;
Expand Down

0 comments on commit 9b31224

Please sign in to comment.