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)
|
||||
endif()
|
||||
|
||||
if (ETL_FORCE_TEST_CPP03)
|
||||
if (ETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||
message(STATUS "Compiling for C++03 tests")
|
||||
add_definitions(-DETL_FORCE_TEST_CPP03)
|
||||
add_definitions(-DETL_FORCE_TEST_CPP03_IMPLEMENTATION)
|
||||
endif()
|
||||
|
||||
include_directories(${UTPP_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR}/../include)
|
||||
@ -283,7 +283,6 @@ set(TEST_SOURCE_FILES
|
||||
test_xor_rotate_checksum.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
set(UNITTEST_SOURCE_FILES
|
||||
UnitTest++/AssertException.cpp
|
||||
UnitTest++/Checks.cpp
|
||||
@ -305,30 +304,16 @@ if (WIN32)
|
||||
UnitTest++/ThrowingTestReporter.cpp
|
||||
UnitTest++/TimeConstraint.cpp
|
||||
UnitTest++/XmlTestReporter.cpp
|
||||
)
|
||||
|
||||
if (WIN32)
|
||||
set(UNITTEST_SOURCE_FILES
|
||||
${UNITTEST_SOURCE_FILES}
|
||||
UnitTest++/Win32/TimeHelpers.cpp
|
||||
)
|
||||
else ()
|
||||
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
|
||||
${UNITTEST_SOURCE_FILES}
|
||||
UnitTest++/Posix/SignalTranslator.cpp
|
||||
UnitTest++/Posix/TimeHelpers.cpp
|
||||
)
|
||||
@ -339,28 +324,23 @@ if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fexceptions")
|
||||
endif()
|
||||
|
||||
add_executable(etl_tests
|
||||
${TEST_SOURCE_FILES}
|
||||
${UNITTEST_SOURCE_FILES}
|
||||
)
|
||||
add_executable(etl_tests ${TEST_SOURCE_FILES})
|
||||
add_library(unit_test ${UNITTEST_SOURCE_FILES})
|
||||
|
||||
if(UNIX AND NOT APPLE)
|
||||
# atomic is need on Linux with Clang
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
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)
|
||||
set(THREADS_PREFER_PTHREAD_FLAG ON)
|
||||
find_package(Threads REQUIRED)
|
||||
target_link_libraries(etl_tests)
|
||||
target_link_libraries(etl_tests unit_test)
|
||||
else()
|
||||
target_link_libraries(etl_tests)
|
||||
target_link_libraries(etl_tests unit_test)
|
||||
endif()
|
||||
|
||||
target_include_directories(etl_tests
|
||||
PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
||||
target_include_directories(etl_tests PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
|
||||
# Enable the 'make test' CMake target using the executable defined above
|
||||
add_test(etl_unit_tests etl_tests)
|
||||
@ -370,6 +350,4 @@ add_test(etl_unit_tests etl_tests)
|
||||
# as they appear from UnitTest++
|
||||
add_custom_target(test_verbose COMMAND ${CMAKE_CTEST_COMMAND} --verbose)
|
||||
|
||||
#RSG
|
||||
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_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) \
|
||||
UNITTEST_MULTILINE_MACRO_BEGIN \
|
||||
@ -205,6 +213,12 @@
|
||||
#define CHECK_THROW UNITTEST_CHECK_THROW
|
||||
#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
|
||||
#error CHECK_ASSERT already defined, re-configure with UNITTEST_ENABLE_SHORT_MACROS set to 0 and use UNITTEST_CHECK_ASSERT instead
|
||||
#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 "TestMacros.h"
|
||||
#include "CheckMacros.h"
|
||||
#include "ExtraCheckMacros.h"
|
||||
#include "RequireMacros.h"
|
||||
#include "TestRunner.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