diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 31132034..b2d0ec93 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -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,54 +283,39 @@ set(TEST_SOURCE_FILES 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) - 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++/Win32/TimeHelpers.cpp + 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++/Posix/SignalTranslator.cpp - UnitTest++/Posix/TimeHelpers.cpp + set(UNITTEST_SOURCE_FILES + ${UNITTEST_SOURCE_FILES} + UnitTest++/Posix/SignalTranslator.cpp + UnitTest++/Posix/TimeHelpers.cpp ) endif () @@ -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) - diff --git a/test/UnitTest++/CheckMacros.h b/test/UnitTest++/CheckMacros.h index 898559d1..5fd438cc 100644 --- a/test/UnitTest++/CheckMacros.h +++ b/test/UnitTest++/CheckMacros.h @@ -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 diff --git a/test/UnitTest++/ExtraCheckMacros.h b/test/UnitTest++/ExtraCheckMacros.h deleted file mode 100644 index be2df4c1..00000000 --- a/test/UnitTest++/ExtraCheckMacros.h +++ /dev/null @@ -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 diff --git a/test/UnitTest++/UnitTestPP.h b/test/UnitTest++/UnitTestPP.h index 55fcae23..3e02d31d 100644 --- a/test/UnitTest++/UnitTestPP.h +++ b/test/UnitTest++/UnitTestPP.h @@ -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" diff --git a/test/cmake/unit-test_external_project.cmake b/test/cmake/unit-test_external_project.cmake deleted file mode 100644 index b5e844c5..00000000 --- a/test/cmake/unit-test_external_project.cmake +++ /dev/null @@ -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= - 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)