mirror of
https://github.com/ETLCPP/etl.git
synced 2026-10-28 18:07:10 +08:00
Updated CMakeLists.txt to embed the unit test code.
This commit is contained in:
parent
64a03b2aa4
commit
426f7f48a4
@ -27,9 +27,9 @@ if (ETL_USER_DEFINED_TYPE_TRAITS)
|
|||||||
add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS)
|
add_definitions(-DETL_USER_DEFINED_TYPE_TRAITS)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if (ETL_FORCE_TEST_CPP03)
|
if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||||
message(STATUS "Compiling for C++03 tests")
|
message(STATUS "Compiling for C++03 tests")
|
||||||
add_definitions(-DETL_FORCE_TEST_CPP03)
|
add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../include)
|
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../include)
|
||||||
@ -283,54 +283,39 @@ set(TEST_SOURCE_FILES
|
|||||||
test_xor_rotate_checksum.cpp
|
test_xor_rotate_checksum.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(UNITTEST_SOURCE_FILES
|
||||||
|
UnitTest++/AssertException.cpp
|
||||||
|
UnitTest++/Checks.cpp
|
||||||
|
UnitTest++/CompositeTestReporter.cpp
|
||||||
|
UnitTest++/CurrentTest.cpp
|
||||||
|
UnitTest++/DeferredTestReporter.cpp
|
||||||
|
UnitTest++/DeferredTestResult.cpp
|
||||||
|
UnitTest++/MemoryOutStream.cpp
|
||||||
|
UnitTest++/ReportAssert.cpp
|
||||||
|
UnitTest++/RequiredCheckException.cpp
|
||||||
|
UnitTest++/RequiredCheckTestReporter.cpp
|
||||||
|
UnitTest++/Test.cpp
|
||||||
|
UnitTest++/TestDetails.cpp
|
||||||
|
UnitTest++/TestList.cpp
|
||||||
|
UnitTest++/TestReporter.cpp
|
||||||
|
UnitTest++/TestReporterStdout.cpp
|
||||||
|
UnitTest++/TestResults.cpp
|
||||||
|
UnitTest++/TestRunner.cpp
|
||||||
|
UnitTest++/ThrowingTestReporter.cpp
|
||||||
|
UnitTest++/TimeConstraint.cpp
|
||||||
|
UnitTest++/XmlTestReporter.cpp
|
||||||
|
)
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
set(UNITTEST_SOURCE_FILES
|
set(UNITTEST_SOURCE_FILES
|
||||||
UnitTest++/AssertException.cpp
|
${UNITTEST_SOURCE_FILES}
|
||||||
UnitTest++/Checks.cpp
|
UnitTest++/Win32/TimeHelpers.cpp
|
||||||
UnitTest++/CompositeTestReporter.cpp
|
|
||||||
UnitTest++/CurrentTest.cpp
|
|
||||||
UnitTest++/DeferredTestReporter.cpp
|
|
||||||
UnitTest++/DeferredTestResult.cpp
|
|
||||||
UnitTest++/MemoryOutStream.cpp
|
|
||||||
UnitTest++/ReportAssert.cpp
|
|
||||||
UnitTest++/RequiredCheckException.cpp
|
|
||||||
UnitTest++/RequiredCheckTestReporter.cpp
|
|
||||||
UnitTest++/Test.cpp
|
|
||||||
UnitTest++/TestDetails.cpp
|
|
||||||
UnitTest++/TestList.cpp
|
|
||||||
UnitTest++/TestReporter.cpp
|
|
||||||
UnitTest++/TestReporterStdout.cpp
|
|
||||||
UnitTest++/TestResults.cpp
|
|
||||||
UnitTest++/TestRunner.cpp
|
|
||||||
UnitTest++/ThrowingTestReporter.cpp
|
|
||||||
UnitTest++/TimeConstraint.cpp
|
|
||||||
UnitTest++/XmlTestReporter.cpp
|
|
||||||
UnitTest++/Win32/TimeHelpers.cpp
|
|
||||||
)
|
)
|
||||||
else ()
|
else ()
|
||||||
set(UNITTEST_SOURCE_FILES
|
set(UNITTEST_SOURCE_FILES
|
||||||
UnitTest++/AssertException.cpp
|
${UNITTEST_SOURCE_FILES}
|
||||||
UnitTest++/Checks.cpp
|
UnitTest++/Posix/SignalTranslator.cpp
|
||||||
UnitTest++/CompositeTestReporter.cpp
|
UnitTest++/Posix/TimeHelpers.cpp
|
||||||
UnitTest++/CurrentTest.cpp
|
|
||||||
UnitTest++/DeferredTestReporter.cpp
|
|
||||||
UnitTest++/DeferredTestResult.cpp
|
|
||||||
UnitTest++/MemoryOutStream.cpp
|
|
||||||
UnitTest++/ReportAssert.cpp
|
|
||||||
UnitTest++/RequiredCheckException.cpp
|
|
||||||
UnitTest++/RequiredCheckTestReporter.cpp
|
|
||||||
UnitTest++/Test.cpp
|
|
||||||
UnitTest++/TestDetails.cpp
|
|
||||||
UnitTest++/TestList.cpp
|
|
||||||
UnitTest++/TestReporter.cpp
|
|
||||||
UnitTest++/TestReporterStdout.cpp
|
|
||||||
UnitTest++/TestResults.cpp
|
|
||||||
UnitTest++/TestRunner.cpp
|
|
||||||
UnitTest++/ThrowingTestReporter.cpp
|
|
||||||
UnitTest++/TimeConstraint.cpp
|
|
||||||
UnitTest++/XmlTestReporter.cpp
|
|
||||||
UnitTest++/Posix/SignalTranslator.cpp
|
|
||||||
UnitTest++/Posix/TimeHelpers.cpp
|
|
||||||
)
|
)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
||||||
@ -339,28 +324,23 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
|||||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
|
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
add_executable(etl_tests
|
add_executable(etl_tests ${TEST_SOURCE_FILES})
|
||||||
${TEST_SOURCE_FILES}
|
add_library(unit_test ${UNITTEST_SOURCE_FILES})
|
||||||
${UNITTEST_SOURCE_FILES}
|
|
||||||
)
|
|
||||||
|
|
||||||
if(UNIX AND NOT APPLE)
|
if(UNIX AND NOT APPLE)
|
||||||
# atomic is need on Linux with Clang
|
# atomic is need on Linux with Clang
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
target_link_libraries(etl_tests atomic Threads::Threads)
|
target_link_libraries(etl_tests unit_test atomic Threads::Threads)
|
||||||
elseif(NOT UNIX AND APPLE)
|
elseif(NOT UNIX AND APPLE)
|
||||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||||
find_package(Threads REQUIRED)
|
find_package(Threads REQUIRED)
|
||||||
target_link_libraries(etl_tests)
|
target_link_libraries(etl_tests unit_test)
|
||||||
else()
|
else()
|
||||||
target_link_libraries(etl_tests)
|
target_link_libraries(etl_tests unit_test)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(etl_tests
|
target_include_directories(etl_tests PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||||
PUBLIC
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}
|
|
||||||
)
|
|
||||||
|
|
||||||
# Enable the 'make test' CMake target using the executable defined above
|
# Enable the 'make test' CMake target using the executable defined above
|
||||||
add_test(etl_unit_tests etl_tests)
|
add_test(etl_unit_tests etl_tests)
|
||||||
@ -370,6 +350,4 @@ add_test(etl_unit_tests etl_tests)
|
|||||||
# as they appear from UnitTest++
|
# as they appear from UnitTest++
|
||||||
add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
|
add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
|
||||||
|
|
||||||
#RSG
|
|
||||||
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
set_property(TARGET etl_tests PROPERTY CXX_STANDARD 17)
|
||||||
|
|
||||||
|
|||||||
@ -189,6 +189,14 @@
|
|||||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
|
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Expected exception: \"" #ExpectedExceptionType "\" not thrown"); \
|
||||||
UNITTEST_MULTILINE_MACRO_END
|
UNITTEST_MULTILINE_MACRO_END
|
||||||
|
|
||||||
|
#define UNITTEST_CHECK_NO_THROW(expression) \
|
||||||
|
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||||
|
bool caught_ = false; \
|
||||||
|
try { expression; } \
|
||||||
|
catch (...) { caught_ = true; } \
|
||||||
|
if (caught_) \
|
||||||
|
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Unexpected exception thrown"); \
|
||||||
|
UNITTEST_MULTILINE_MACRO_END
|
||||||
|
|
||||||
#define UNITTEST_CHECK_ASSERT(expression) \
|
#define UNITTEST_CHECK_ASSERT(expression) \
|
||||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||||
@ -205,6 +213,12 @@
|
|||||||
#define CHECK_THROW UNITTEST_CHECK_THROW
|
#define CHECK_THROW UNITTEST_CHECK_THROW
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef CHECK_NO_THROW
|
||||||
|
#error CHECK_NO_THROW already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_NO_THROW instead
|
||||||
|
#else
|
||||||
|
#define CHECK_NO_THROW UNITTEST_CHECK_NO_THROW
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef CHECK_ASSERT
|
#ifdef CHECK_ASSERT
|
||||||
#error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead
|
#error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead
|
||||||
#else
|
#else
|
||||||
|
|||||||
@ -1,23 +0,0 @@
|
|||||||
#ifndef UNITTEST_EXTRA_CHECKMACROS_H
|
|
||||||
#define UNITTEST_EXTRA_CHECKMACROS_H
|
|
||||||
|
|
||||||
#include "UnitTest++/HelperMacros.h"
|
|
||||||
#include "UnitTest++/ExceptionMacros.h"
|
|
||||||
#include "UnitTest++/Checks.h"
|
|
||||||
#include "UnitTest++/AssertException.h"
|
|
||||||
#include "UnitTest++/MemoryOutStream.h"
|
|
||||||
#include "UnitTest++/TestDetails.h"
|
|
||||||
#include "UnitTest++/CurrentTest.h"
|
|
||||||
#include "UnitTest++/ReportAssertImpl.h"
|
|
||||||
|
|
||||||
#ifndef CHECK_NO_THROW
|
|
||||||
#define CHECK_NO_THROW(expression) \
|
|
||||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
|
||||||
bool caught_ = false; \
|
|
||||||
try { expression; } \
|
|
||||||
catch (...) { caught_ = true; } \
|
|
||||||
if (caught_) \
|
|
||||||
UnitTest::CurrentTest::Results()->OnTestFailure(UnitTest::TestDetails(*UnitTest::CurrentTest::Details(), __LINE__), "Unexpected exception thrown"); \
|
|
||||||
UNITTEST_MULTILINE_MACRO_END
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
@ -4,7 +4,6 @@
|
|||||||
#include "Config.h"
|
#include "Config.h"
|
||||||
#include "TestMacros.h"
|
#include "TestMacros.h"
|
||||||
#include "CheckMacros.h"
|
#include "CheckMacros.h"
|
||||||
#include "ExtraCheckMacros.h"
|
|
||||||
#include "RequireMacros.h"
|
#include "RequireMacros.h"
|
||||||
#include "TestRunner.h"
|
#include "TestRunner.h"
|
||||||
#include "TimeConstraint.h"
|
#include "TimeConstraint.h"
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
cmake_minimum_required(VERSION 3.5.0)
|
|
||||||
find_package(Git REQUIRED)
|
|
||||||
include(ExternalProject)
|
|
||||||
|
|
||||||
|
|
||||||
#####
|
|
||||||
# \breif Function used to add UnitTest++ as an External Project, install it into the
|
|
||||||
# binary location of the CMake build, add its header directories in the
|
|
||||||
# include_directories, and finally add the built static library as an imported
|
|
||||||
# CMake target
|
|
||||||
#####
|
|
||||||
function (add_unittest_cpp)
|
|
||||||
|
|
||||||
set(UTPP_INSATLL_DIR "${CMAKE_CURRENT_BINARY_DIR}/unittest++/install")
|
|
||||||
if (WIN32)
|
|
||||||
set(UTPP_LIB_NAME "UnitTest++.lib")
|
|
||||||
else()
|
|
||||||
set(UTPP_LIB_NAME "libUnitTest++.a")
|
|
||||||
endif()
|
|
||||||
|
|
||||||
|
|
||||||
ExternalProject_Add(unittest-cpp
|
|
||||||
GIT_REPOSITORY https://github.com/unittest-cpp/unittest-cpp.git
|
|
||||||
GIT_TAG v2.0.0
|
|
||||||
GIT_SHALLOW TRUE # Don't require downloading the entire history
|
|
||||||
SOURCE_DIR "${CMAKE_CURRENT_BINARY_DIR}/unittest++/src"
|
|
||||||
INSTALL_DIR "${UTPP_INSATLL_DIR}"
|
|
||||||
CMAKE_ARGS -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
|
|
||||||
TEST_EXCLUDE_FROM_MAIN TRUE # Don't run UnitTest++'s tests by default
|
|
||||||
)
|
|
||||||
|
|
||||||
set(UTPP_INCLUDE_DIRS "${UTPP_INSATLL_DIR}/include" PARENT_SCOPE)
|
|
||||||
add_library(UnitTest++ STATIC IMPORTED)
|
|
||||||
set_target_properties(UnitTest++ PROPERTIES IMPORTED_LOCATION "${UTPP_INSATLL_DIR}/lib/${UTPP_LIB_NAME}" )
|
|
||||||
# Require the ExternalProject target to complete before importing the library
|
|
||||||
add_dependencies(UnitTest++ unittest-cpp)
|
|
||||||
|
|
||||||
endfunction(add_unittest_cpp)
|
|
||||||
Loading…
x
Reference in New Issue
Block a user