Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add PCRE support for regular expressions into tests #106

Open
wants to merge 1 commit into
base: pcre
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
67 changes: 63 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,47 @@ 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"
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 +424,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 +478,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
6 changes: 5 additions & 1 deletion tests/check_check_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
#include <stdio.h>
#include <string.h>
#if ENABLE_REGEX
# include <regex.h>
# if ENABLE_PCREPOSIX
# include <pcreposix.h>
# else
# include <regex.h>
# endif
#endif
#include <check.h>
#include <assert.h>
Expand Down