Skip to content
Snippets Groups Projects
Commit 0be8532d authored by Wuttke, Joachim's avatar Wuttke, Joachim
Browse files

GoogletestWrapper generates either compile-time or post-build test.

parent 207cb1a9
No related branches found
No related tags found
No related merge requests found
......@@ -37,7 +37,7 @@ include(CheckCompiler)
include(BornAgainConfiguration)
include(GeneratePythonDocs)
include(FuTestMacros)
include(UnitTests)
include(GoogletestWrapper)
#--- Recurse into the given subdirectories ---
if(BORNAGAIN_USERMANUAL)
......@@ -59,5 +59,6 @@ add_subdirectory(Tests/FunctionalTests) # functional tests (make check)
add_subdirectory(cmake/bornagain) # trick to print an after-install message
# packaging
#--- Make test and package targets ---
add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND}) # => 'make check' is an alias for 'ctest'
include(BornAgainCPack)
......@@ -2,9 +2,6 @@
# FunctionalTests/CMakeLists.txt (called from top-level CMakeLists.txt)
############################################################################
add_custom_target(check ${CMAKE_CTEST_COMMAND})
# export CTEST_OUTPUT_ON_FAILURE=ON will give some output on failure
execute_process( COMMAND ${CMAKE_COMMAND} -E copy_directory
${CMAKE_SOURCE_DIR}/Tests/ReferenceData/BornAgain
${CMAKE_BINARY_DIR}/Tests/ReferenceData/BornAgain )
......
......@@ -16,13 +16,14 @@ endif()
# function UNIT_TESTS defined in cmake/modules/UnitTests.cmake
UNIT_TESTS(TestCoreQ "Q" ${BornAgainCore_LIBRARY}) # q loops, lengthy output
UNIT_TESTS(TestCoreP "P" ${BornAgainCore_LIBRARY}) # q loops, lengthy output
UNIT_TESTS(TestCore0 "0" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCore1 "1" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCore2 "2" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCore3 "3" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCore4 "4" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCore5 "5" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCore6 "6" ${BornAgainCore_LIBRARY})
UNIT_TESTS(TestCoreS "S" ${BornAgainCore_LIBRARY})
WRAP_GTEST(TestCore0 "0" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCore1 "1" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCore2 "2" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCore3 "3" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCore4 "4" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCore5 "5" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCore6 "6" ${BornAgainCore_LIBRARY} 0)
WRAP_GTEST(TestCoreS "S" ${BornAgainCore_LIBRARY} 1)
WRAP_GTEST(TestCoreQ "Q" ${BornAgainCore_LIBRARY} 1) # q loops, lengthy output
WRAP_GTEST(TestCoreP "P" ${BornAgainCore_LIBRARY} 1) # q loops, lengthy output
......@@ -14,6 +14,4 @@ if(BORNAGAIN_OPENMPI)
include_directories(${MPI_INCLUDE_PATH})
endif()
# function UNIT_TESTS defined in cmake/modules/UnitTests.cmake
UNIT_TESTS(TestFit0 "." ${BornAgainFit_LIBRARY})
WRAP_GTEST(TestFit0 "." ${BornAgainFit_LIBRARY} 0)
......@@ -74,5 +74,4 @@ endfunction()
function(BORNAGAIN_ADD_TEST test_name test_exe)
cmake_parse_arguments(ARG "" "TEST_ARGUMENTS" "" "" ${ARGN})
add_test(${test_name} ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${test_exe} "${ARG_TEST_ARGUMENTS}")
add_dependencies(check ${test_exe})
endfunction()
......@@ -2,8 +2,8 @@
#
# BornAgain: simulate and fit scattering at grazing incidence
#
# @file cmake/modules/UnitTests
# @brief Implements function UNIT_TESTS(..)
# @file cmake/bornagain/modules/GoogletestWrapper.cmake
# @brief Implements function WRAP_GTEST(..)
#
# @homepage http://www.bornagainproject.org
# @license GNU General Public License v3 or higher (see COPYING)
......@@ -15,7 +15,10 @@
# @brief Compile tests given as .h files in SUBDIR, link with LINK_LIB, and execute
function(UNIT_TESTS TEST_NAME SUBDIR LINK_LIB)
# STAGE=0: test run at compile time
# STAGE=1: test run upon "ctest"="make check"
function(WRAP_GTEST TEST_NAME SUBDIR LINK_LIB STAGE)
include_directories(${gtest_SOURCE_DIR}/include ${gtest_SOURCE_DIR})
file(GLOB INCLUDE_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} "${SUBDIR}/*.h")
......@@ -23,12 +26,12 @@ function(UNIT_TESTS TEST_NAME SUBDIR LINK_LIB)
# Compose main program (C++ snippets plus #include's of test code from SUBDIR)
set(TMP "/* Generated by CMake. Do not edit. Do not put under version control. */\n")
file(READ "${TEMPLATE_DIR}/unitTests.cpp.header" TMPTMP)
file(READ "${TEMPLATE_DIR}/GoogletestHeader.cpp" TMPTMP)
set(TMP "${TMP}\n${TMPTMP}\n")
foreach(FILE ${INCLUDE_FILES})
set(TMP "${TMP}#include \"${CMAKE_CURRENT_SOURCE_DIR}/${FILE}\"\n")
endforeach()
file(READ "${TEMPLATE_DIR}/unitTests.cpp.footer" TMPTMP)
file(READ "${TEMPLATE_DIR}/GoogletestFooter.cpp" TMPTMP)
set(TMP "${TMP}\n${TMPTMP}")
set(TEST_SRC "${BUILD_AUTO_DIR}/${TEST_NAME}.cpp")
......@@ -42,10 +45,14 @@ function(UNIT_TESTS TEST_NAME SUBDIR LINK_LIB)
# to prevent problems with finding libBornAgainCore.dll under Windows
set_property(TARGET ${EXE} PROPERTY RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
add_test(${TEST_NAME} ${EXE})
# Add execution of TestCore just after compilation
add_custom_command(TARGET ${TEST_NAME} POST_BUILD COMMAND ${EXE})
if (${STAGE} EQUAL 0)
# Add execution of TestCore just after compilation
add_custom_command(TARGET ${TEST_NAME} POST_BUILD COMMAND ${EXE})
elseif(${STAGE} EQUAL 1)
add_test(${TEST_NAME} ${EXE})
else()
message(FATAL_ERROR "invalid parameter STAGE=${STAGE} in WRAP_GTEST")
endif()
# To make the .h files appear in QtCreator's project tree
add_custom_target("${TEST_NAME}_sources" SOURCES ${INCLUDE_FILES})
......
/* From unitTests.cpp.footer: */
/* From GoogletestFooter.cpp: */
struct ErrorStreamRedirect {
ErrorStreamRedirect( std::streambuf * new_buffer )
......@@ -15,7 +15,7 @@ private:
int main(int argc, char** argv)
{
std::cout << "UnitTest::main ...\n";
std::cout << "GoogleTest::main ...\n";
::testing::InitGoogleTest(&argc, argv);
// redirect std::cerr stream
......
/* From unitTests.cpp.header: */
/* From GoogletestHeader.cpp: */
#ifdef _MSC_VER
#define _VARIADIC_MAX 10
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment