Make google test framework a mandatory build dependency

All c++ unit tests will be written with it, and testing
should be possible out of the box.
We could make it optional, but then lots of tests will
be skipped. This creates an illusion of all tests passing
while many are simply not run. This confusion should be
avoided.
This change depends on a second commit for the windows build
in the gnucash-on-windows repository. This commit will be
pushed at the same time.
This commit is contained in:
Geert Janssens
2017-02-02 17:20:39 +01:00
parent aeb04e1d9d
commit 0a8d7a2142
8 changed files with 191 additions and 193 deletions

View File

@@ -62,7 +62,7 @@ OPTION (ENABLE_DEBUG "compile with debugging flags set" OFF)
OPTION (ENABLE_REGISTER2 "compile with register2 enabled" OFF) OPTION (ENABLE_REGISTER2 "compile with register2 enabled" OFF)
OPTION (DISABLE_NLS "do not use Native Language Support" OFF) OPTION (DISABLE_NLS "do not use Native Language Support" OFF)
OPTION (DISABLE_DEPRECATED_GLIB "don't use deprecated glib functions" OFF) OPTION (DISABLE_DEPRECATED_GLIB "don't use deprecated glib functions" OFF)
OPTION (DISABLE_DEPRECATED_GTK "don't use deprectacted gtk, gdk or gdk-pixbuf functions" OFF) OPTION (DISABLE_DEPRECATED_GTK "don't use deprecated gtk, gdk or gdk-pixbuf functions" OFF)
OPTION (DISABLE_DEPRECATED_GNOME "don't use deprecated gnome functions" OFF) OPTION (DISABLE_DEPRECATED_GNOME "don't use deprecated gnome functions" OFF)
OPTION (GNC_BUILD_AS_INSTALL "Make build directory structure mirror install" ON) OPTION (GNC_BUILD_AS_INSTALL "Make build directory structure mirror install" ON)
# ############################################################ # ############################################################
@@ -405,7 +405,7 @@ FIND_PROGRAM(POD2MAN_EXECUTABLE pod2man HINTS ${PERL_DIR})
IF (APPLE) IF (APPLE)
# I suppose I would rather use the shared Boost libraries here, but the Boost install procedure # I suppose I would rather use the shared Boost libraries here, but the Boost install procedure
# does not set RPATH for it's shared library correctly. It uses a 'naked' RPATH, which requires # does not set RPATH for it's shared library correctly. It uses a 'naked' RPATH, which requires
# that DYLD_FALLBACK_LIBRARY_PATH be set. There is supposedly a dll-path option so set RPATH, but # that DYLD_FALLBACK_LIBRARY_PATH be set. There is supposedly a dll-path option to set RPATH, but
# I can't get it to work (http://www.boost.org/build/doc/html/bbv2/faq/dll-path.html) and neither # I can't get it to work (http://www.boost.org/build/doc/html/bbv2/faq/dll-path.html) and neither
# can some other random person on the internet: # can some other random person on the internet:
# http://stackoverflow.com/questions/33667795/dll-path-has-no-effect-when-building-boost # http://stackoverflow.com/questions/33667795/dll-path-has-no-effect-when-building-boost

View File

@@ -861,9 +861,6 @@ ac_cv_gtest_headers=""
ac_cv_gtest_libs="" ac_cv_gtest_libs=""
ac_cv_gmock_libs="" ac_cv_gmock_libs=""
AC_ARG_ENABLE( google-test,
[AS_HELP_STRING([--disable-google-test], [do not build the Google Test and Google Mock static libraries and enable C++ Unit Tests])],,[enable_google_test=yes])
if test x$enable_google_test != xno; then
AC_CHECK_LIB([gtest_main], [main], AC_CHECK_LIB([gtest_main], [main],
[AC_CHECK_FILES([/usr/src/gmock/gmock-all.cc [AC_CHECK_FILES([/usr/src/gmock/gmock-all.cc
/usr/include/gtest/gtest.h /usr/include/gtest/gtest.h
@@ -880,7 +877,6 @@ if test x$enable_google_test != xno; then
[ac_cv_gtest_system_install=yes] [ac_cv_have_gtest_libs=no], [ac_cv_gtest_system_install=yes] [ac_cv_have_gtest_libs=no],
[ac_cv_gtest_system_install=no])] [ac_cv_gtest_system_install=no])]
) )
fi
if test x$ac_cv_file__usr_include_gmock_gmock_h = xyes -a x$ac_cv_file__usr_include_gtest_gtest_h = xyes; then if test x$ac_cv_file__usr_include_gmock_gmock_h = xyes -a x$ac_cv_file__usr_include_gtest_gtest_h = xyes; then
if test x$ac_cv_file__usr_src_gmock_src_gmock_all_cc = xyes -a x$ac_cv_file__usr_src_gtest_src_gtest_all_cc = xyes; then if test x$ac_cv_file__usr_src_gmock_src_gmock_all_cc = xyes -a x$ac_cv_file__usr_src_gtest_src_gtest_all_cc = xyes; then
ac_cv_gtest_system_install=yes ac_cv_gtest_system_install=yes
@@ -904,7 +900,7 @@ AC_ARG_WITH([gmock-headers],
[AS_HELP_STRING([--with-gmock-headers=PATH], [location of the google test header files if not in gmock-root])], [AS_HELP_STRING([--with-gmock-headers=PATH], [location of the google test header files if not in gmock-root])],
[ac_cv_gmock_headers="$with_gmock_headers"]) [ac_cv_gmock_headers="$with_gmock_headers"])
if test x$enable_google_test = xyes; then google_test_found=yes
AC_MSG_CHECKING([whether Google Test is available]) AC_MSG_CHECKING([whether Google Test is available])
if test -n "$ac_cv_gtest_root" -a -r "$ac_cv_gtest_root/src/gtest-all.cc"; then if test -n "$ac_cv_gtest_root" -a -r "$ac_cv_gtest_root/src/gtest-all.cc"; then
AC_MSG_WARN([Skipped setting ac_cv_gtest_root, value $ac_cv_gtest_root]) AC_MSG_WARN([Skipped setting ac_cv_gtest_root, value $ac_cv_gtest_root])
@@ -919,7 +915,7 @@ if test x$enable_google_test = xyes; then
fi fi
if test -z "$ac_cv_gtest_root" -a -z "$ac_cv_gtest_libs"; then if test -z "$ac_cv_gtest_root" -a -z "$ac_cv_gtest_libs"; then
AC_MSG_RESULT([No gtest-root]) AC_MSG_RESULT([No gtest-root])
enable_google_test=no google_test_found=no
else else
if test ! -r "$ac_cv_gtest_root/include/gtest/gtest.h"; then if test ! -r "$ac_cv_gtest_root/include/gtest/gtest.h"; then
if test -n "$ac_cv_gtest_headers" -a -r "$ac_cv_gtest_headers/gtest/gtest.h"; then if test -n "$ac_cv_gtest_headers" -a -r "$ac_cv_gtest_headers/gtest/gtest.h"; then
@@ -935,7 +931,7 @@ if test x$enable_google_test = xyes; then
fi fi
if test -z "$ac_cv_gtest_headers"; then if test -z "$ac_cv_gtest_headers"; then
AC_MSG_RESULT([No gtest-headers]) AC_MSG_RESULT([No gtest-headers])
enable_google_test=no google_test_found=no
fi fi
else else
ac_cv_gtest_headers=$ac_cv_gtest_root/include ac_cv_gtest_headers=$ac_cv_gtest_root/include
@@ -968,7 +964,7 @@ if test x$enable_google_test = xyes; then
fi fi
if test -z "$ac_cv_gmock_root"; then if test -z "$ac_cv_gmock_root"; then
AC_MSG_RESULT([No gmock-root]) AC_MSG_RESULT([No gmock-root])
enable_google_test=no google_test_found=no
else else
if test ! -r "$ac_cv_gmock_root/include/gmock/gmock.h"; then if test ! -r "$ac_cv_gmock_root/include/gmock/gmock.h"; then
if test -n "$ac_cv_gmock_headers" -a -r "$ac_cv_gmock_headers/gmock/gmock.h"; then if test -n "$ac_cv_gmock_headers" -a -r "$ac_cv_gmock_headers/gmock/gmock.h"; then
@@ -984,15 +980,22 @@ if test x$enable_google_test = xyes; then
fi fi
if test -z "$ac_cv_gmock_headers"; then if test -z "$ac_cv_gmock_headers"; then
AC_MSG_RESULT([No gmock-headers]) AC_MSG_RESULT([No gmock-headers])
enable_google_test=no google_test_found=no
fi fi
else else
ac_cv_gmock_headers="$ac_cv_gmock_root/include" ac_cv_gmock_headers="$ac_cv_gmock_root/include"
fi fi
fi fi
if test "x$enable_google_test" = "xyes"; then
if test "x$google_test_found" = "xyes"; then
AC_MSG_RESULT([Yes]) AC_MSG_RESULT([Yes])
fi else
AC_MSG_ERROR([
Unable to find the Google test framework. Either install gtest/gmock
packages or point to the base directories of the sources using
GTEST_ROOT and GMOCK_ROOT environment variables.
])
fi fi
if test "x$ac_cv_have_gtest_libs" = xyes; then if test "x$ac_cv_have_gtest_libs" = xyes; then
@@ -1002,10 +1005,9 @@ dnl Google test requires pthreads and this seems the easiest way to check.
AX_PTHREAD([ AX_PTHREAD([
ac_cv_gtest_libs="\$(top_builddir)/src/test-core/libgtest.a $PTHREAD_CFLAGS" ac_cv_gtest_libs="\$(top_builddir)/src/test-core/libgtest.a $PTHREAD_CFLAGS"
],[ ],[
AC_MSG_WARN( AC_MSG_ERROR(
[Disabling GTest because pthreads, which it requires, wasn't found.]) [GTest requires pthreads, but this wasn't found.])
dnl Google test requires pthreads and this seems the easiest way to check. dnl Google test requires pthreads and this seems the easiest way to check.
enable_google_test="no"
]) ])
fi fi
@@ -1015,7 +1017,6 @@ AC_SUBST([GTEST_HEADERS], [$ac_cv_gtest_headers])
AC_SUBST([GMOCK_SRC_PATH], [$ac_cv_gmock_src_path]) AC_SUBST([GMOCK_SRC_PATH], [$ac_cv_gmock_src_path])
AC_SUBST([GMOCK_SRC], [$ac_cv_gmock_root]) AC_SUBST([GMOCK_SRC], [$ac_cv_gmock_root])
AC_SUBST([GMOCK_HEADERS], [$ac_cv_gmock_headers]) AC_SUBST([GMOCK_HEADERS], [$ac_cv_gmock_headers])
AM_CONDITIONAL([WITH_GOOGLE_TEST], [test "x$enable_google_test" = "xyes"])
AM_CONDITIONAL([GOOGLE_TEST_LIBS], [test "x$ac_cv_have_gtest_libs" == "xyes"]) AM_CONDITIONAL([GOOGLE_TEST_LIBS], [test "x$ac_cv_have_gtest_libs" == "xyes"])
### -------------------------------------------------------------------------- ### --------------------------------------------------------------------------
### Register2 ### Register2

View File

@@ -85,16 +85,17 @@ FUNCTION(GNC_ADD_SCHEME_TEST _TARGET _SOURCE_FILE)
ENDFUNCTION() ENDFUNCTION()
FUNCTION(GNC_GTEST_CONFIGURE) FUNCTION(GNC_GTEST_CONFIGURE)
MESSAGE(STATUS "Maybe setting up GTEST with " ${GTEST_DISABLE}) MESSAGE(STATUS "Checking for GTEST")
IF (NOT GTEST_DISABLE) IF (NOT DEFINED ${GTEST_ROOT})
SET(GTEST_ROOT $ENV{GTEST_ROOT})
ENDIF()
IF (NOT DEFINED ${GMOCK_ROOT})
SET(GMOCK_ROOT $ENV{GMOCK_ROOT})
ENDIF()
FIND_PATH(GTEST_INCLUDE_DIR gtest/gtest.h FIND_PATH(GTEST_INCLUDE_DIR gtest/gtest.h
PATHS /usr/include ${GMOCK_ROOT}/gtest/include ${GTEST_ROOT}/include) PATHS ${GTEST_ROOT}/include ${GMOCK_ROOT}/gtest/include /usr/include)
FIND_PATH(GTEST_SRC_DIR src/gtest-all.cc FIND_PATH(GTEST_SRC_DIR src/gtest-all.cc
PATHS /usr/src/gtest ${GMOCK_ROOT}/gtest ${GTEST_ROOT}) PATHS ${GTEST_ROOT} ${GMOCK_ROOT}/gtest /usr/src/gtest)
FIND_PATH(GMOCK_INCLUDE_DIR gmock/gmock.h
PATHS /usr/include ${GMOCK_ROOT}/include)
FIND_PATH(GMOCK_SRC_DIR src/gmock-all.cc
PATHS /usr/src/gmock ${GMOCK_ROOT})
FIND_LIBRARY(GTEST_SHARED_LIB gtest) FIND_LIBRARY(GTEST_SHARED_LIB gtest)
FIND_LIBRARY(GTEST_MAIN_LIB gtest_main) FIND_LIBRARY(GTEST_MAIN_LIB gtest_main)
IF ((GTEST_SHARED_LIB OR GTEST_SRC_DIR) AND GTEST_INCLUDE_DIR) IF ((GTEST_SHARED_LIB OR GTEST_SRC_DIR) AND GTEST_INCLUDE_DIR)
@@ -108,11 +109,20 @@ FUNCTION(GNC_GTEST_CONFIGURE)
SET(GTEST_SRC "${GTEST_SRC_DIR}/src/gtest_main.cc" PARENT_SCOPE) SET(GTEST_SRC "${GTEST_SRC_DIR}/src/gtest_main.cc" PARENT_SCOPE)
SET(GTEST_LIB "${CMAKE_BINARY_DIR}/src/test-core/libgtest.a" PARENT_SCOPE) SET(GTEST_LIB "${CMAKE_BINARY_DIR}/src/test-core/libgtest.a" PARENT_SCOPE)
ENDIF() ENDIF()
ELSE()
MESSAGE(FATAL_ERROR "GTEST not found. Please install it or set GTEST_ROOT or GMOCK_ROOT")
ENDIF()
MESSAGE(STATUS "Checking for GMOCK")
FIND_PATH(GMOCK_INCLUDE_DIR gmock/gmock.h
PATHS ${GMOCK_ROOT}/include /usr/include)
FIND_PATH(GMOCK_SRC_DIR src/gmock-all.cc
PATHS ${GMOCK_ROOT} /usr/src/gmock)
if (GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR) if (GMOCK_INCLUDE_DIR AND GMOCK_SRC_DIR)
SET(GMOCK_FOUND YES PARENT_SCOPE) SET(GMOCK_FOUND YES PARENT_SCOPE)
SET(GMOCK_SRC "${GMOCK_SRC_DIR}/src/gmock_main.cc" PARENT_SCOPE) SET(GMOCK_SRC "${GMOCK_SRC_DIR}/src/gmock_main.cc" PARENT_SCOPE)
SET(GMOCK_LIB "${CMAKE_BINARY_DIR}/src/test-core/libgmock.a" PARENT_SCOPE) SET(GMOCK_LIB "${CMAKE_BINARY_DIR}/src/test-core/libgmock.a" PARENT_SCOPE)
ENDIF() ELSE()
ENDIF() MESSAGE(FATAL_ERROR "GMOCK not found. Please install it or set GMOCK_ROOT")
ENDIF() ENDIF()
ENDFUNCTION() ENDFUNCTION()

View File

@@ -183,7 +183,6 @@ libutest_Trans_la_SOURCES = \
libutest_Trans_la_LIBADD = $(LDADD) libutest_Trans_la_LIBADD = $(LDADD)
if WITH_GOOGLE_TEST
test_import_map_SOURCES = \ test_import_map_SOURCES = \
gtest-import-map.cpp gtest-import-map.cpp
test_import_map_LDADD = \ test_import_map_LDADD = \
@@ -205,7 +204,6 @@ test_import_map_CPPFLAGS = \
${GLIB_CFLAGS} ${GLIB_CFLAGS}
TEST_GROUP_1 += test-import-map TEST_GROUP_1 += test-import-map
endif
CLEANFILES = .scm-links CLEANFILES = .scm-links

View File

@@ -25,7 +25,6 @@ SET(test_qof_SOURCES
IF (NOT WIN32) IF (NOT WIN32)
GNC_ADD_TEST(test-qof "${test_qof_SOURCES}" TEST_QOF_INCLUDE_DIRS TEST_QOF_LIBS) GNC_ADD_TEST(test-qof "${test_qof_SOURCES}" TEST_QOF_INCLUDE_DIRS TEST_QOF_LIBS)
TARGET_COMPILE_DEFINITIONS(test-qof PRIVATE TESTPROG=test_qof) TARGET_COMPILE_DEFINITIONS(test-qof PRIVATE TESTPROG=test_qof)
IF(GTEST_FOUND)
SET(MODULEPATH ${CMAKE_SOURCE_DIR}/src/libqof/qof) SET(MODULEPATH ${CMAKE_SOURCE_DIR}/src/libqof/qof)
SET(gtest_qof_LIBS gnc-qof ${GLIB2_LDFLAGS} ${Boost_LIBRARIES} ${GTEST_LIB}) SET(gtest_qof_LIBS gnc-qof ${GLIB2_LDFLAGS} ${Boost_LIBRARIES} ${GTEST_LIB})
SET(gtest_qof_INCLUDES SET(gtest_qof_INCLUDES
@@ -75,6 +74,4 @@ IF (NOT WIN32)
${GTEST_SRC}) ${GTEST_SRC})
GNC_ADD_TEST(test-gnc-datetime "${test_gnc_datetime_SOURCES}" GNC_ADD_TEST(test-gnc-datetime "${test_gnc_datetime_SOURCES}"
gtest_qof_INCLUDES gtest_qof_LIBS) gtest_qof_INCLUDES gtest_qof_LIBS)
ENDIF()
ENDIF() ENDIF()

View File

@@ -30,7 +30,6 @@ check_PROGRAMS = \
TESTS = ${check_PROGRAMS} TESTS = ${check_PROGRAMS}
if WITH_GOOGLE_TEST
test_gnc_guid_SOURCES = \ test_gnc_guid_SOURCES = \
$(top_srcdir)/$(MODULEPATH)/guid.cpp \ $(top_srcdir)/$(MODULEPATH)/guid.cpp \
test-gnc-guid.cpp test-gnc-guid.cpp
@@ -152,7 +151,6 @@ nodist_test_gnc_datetime_SOURCES = \
endif endif
check_PROGRAMS += test-gnc-datetime check_PROGRAMS += test-gnc-datetime
endif
test_qofdir = ${GNC_LIBEXECDIR}/${MODULEPATH}/test test_qofdir = ${GNC_LIBEXECDIR}/${MODULEPATH}/test

View File

@@ -65,18 +65,14 @@ GNC_ADD_SCHEME_TARGETS(scm-test-core
FALSE FALSE
) )
IF(GTEST_FOUND)
IF(NOT GTEST_SHARED_LIB) IF(NOT GTEST_SHARED_LIB)
SET (lib_gtest_SOURCES ${GTEST_SRC_DIR}/src/gtest-all.cc) SET (lib_gtest_SOURCES ${GTEST_SRC_DIR}/src/gtest-all.cc)
ADD_LIBRARY(gtest STATIC ${lib_gtest_SOURCES}) ADD_LIBRARY(gtest STATIC ${lib_gtest_SOURCES})
TARGET_INCLUDE_DIRECTORIES(gtest PUBLIC ${GTEST_INCLUDE_DIR} ${GTEST_SRC_DIR}) TARGET_INCLUDE_DIRECTORIES(gtest PUBLIC ${GTEST_INCLUDE_DIR} ${GTEST_SRC_DIR})
ENDIF() ENDIF()
IF(GMOCK_FOUND)
SET (lib_gmock_SOURCES ${GMOCK_SRC_DIR}/src/gmock-all.cc) SET (lib_gmock_SOURCES ${GMOCK_SRC_DIR}/src/gmock-all.cc)
ADD_LIBRARY(gmock STATIC ${lib_gmock_SOURCES}) ADD_LIBRARY(gmock STATIC ${lib_gmock_SOURCES})
TARGET_INCLUDE_DIRECTORIES(gmock PUBLIC TARGET_INCLUDE_DIRECTORIES(gmock PUBLIC
${GTEST_INCLUDE_DIR} ${GTEST_SRC_DIR} ${GTEST_INCLUDE_DIR} ${GTEST_SRC_DIR}
${GMOCK_INCLUDE_DIR} ${GMOCK_SRC_DIR}) ${GMOCK_INCLUDE_DIR} ${GMOCK_SRC_DIR})
ENDIF()
ENDIF()
INSTALL(FILES unittest-support.h DESTINATION libexec/gnucash/src/libqof/qof/test) INSTALL(FILES unittest-support.h DESTINATION libexec/gnucash/src/libqof/qof/test)

View File

@@ -79,7 +79,6 @@ _unittest_support_la_LIBADD = \
endif endif
if WITH_GOOGLE_TEST
if GOOGLE_TEST_LIBS if GOOGLE_TEST_LIBS
noinst_LIBRARIES = libgmock.a noinst_LIBRARIES = libgmock.a
else else
@@ -91,7 +90,6 @@ libgtest_a_CPPFLAGS = ${AM_CPPFLAGS} -I${GTEST_HEADERS} -I${GTEST_SRC}
endif endif
nodist_libgmock_a_SOURCES = ${GMOCK_SRC_PATH}/gmock-all.cc nodist_libgmock_a_SOURCES = ${GMOCK_SRC_PATH}/gmock-all.cc
libgmock_a_CPPFLAGS = ${libgtest_a_CPPFLAGS} -I${GMOCK_HEADERS} -I${GMOCK_SRC} libgmock_a_CPPFLAGS = ${libgtest_a_CPPFLAGS} -I${GMOCK_HEADERS} -I${GMOCK_SRC}
endif
gncscmmoddir = ${GNC_SCM_INSTALL_DIR}/gnucash gncscmmoddir = ${GNC_SCM_INSTALL_DIR}/gnucash
gncscmmod_DATA = unittest-support.scm gncscmmod_DATA = unittest-support.scm