From 44722f9ed3d019bdff92d003f9e73333e68c503a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Ho=C5=99e=C5=88ovsk=C3=BD?= Date: Mon, 11 Jun 2018 10:48:10 +0200 Subject: [PATCH] Integrate CMake with `` include paths This also goes for pkg-config installed by our CMake installation. This includes * Updating CMake version on Travis * Adding a `Catch2` subfolder to the `single_include/` folder to provide this include path both _inside_ the repository, and _outside_. * Updated examples to build with the new paths * Other general CMake cleanup --- .travis.yml | 2 +- CMake/MiscFunctions.cmake | 26 + catch.pc.in => CMake/catch2.pc.in | 4 +- CMakeLists.txt | 509 ++++-------------- conanfile.py | 4 +- examples/000-CatchMain.cpp | 2 +- examples/010-TestCase.cpp | 2 +- examples/020-TestCase-1.cpp | 2 +- examples/020-TestCase-2.cpp | 2 +- examples/030-Asn-Require-Check.cpp | 2 +- examples/100-Fix-Section.cpp | 2 +- examples/110-Fix-ClassFixture.cpp | 2 +- examples/120-Bdd-ScenarioGivenWhenThen.cpp | 2 +- examples/210-Evt-EventListeners.cpp | 2 +- examples/CMakeLists.txt | 8 +- projects/CMakeLists.txt | 329 +++++++++++ scripts/generateSingleHeader.py | 2 +- scripts/releaseCommon.py | 2 +- scripts/updateWandbox.py | 2 +- single_include/{ => catch2}/catch.hpp | 2 +- .../{ => catch2}/catch_reporter_automake.hpp | 0 .../{ => catch2}/catch_reporter_tap.hpp | 0 .../{ => catch2}/catch_reporter_teamcity.hpp | 0 test_package/MainTest.cpp | 2 +- 24 files changed, 476 insertions(+), 434 deletions(-) create mode 100644 CMake/MiscFunctions.cmake rename catch.pc.in => CMake/catch2.pc.in (64%) create mode 100644 projects/CMakeLists.txt rename single_include/{ => catch2}/catch.hpp (99%) rename single_include/{ => catch2}/catch_reporter_automake.hpp (100%) rename single_include/{ => catch2}/catch_reporter_tap.hpp (100%) rename single_include/{ => catch2}/catch_reporter_teamcity.hpp (100%) diff --git a/.travis.yml b/.travis.yml index b2045603..14595f78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -249,7 +249,7 @@ install: - mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR} - | if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then - CMAKE_URL="http://www.cmake.org/files/v3.3/cmake-3.3.2-Linux-x86_64.tar.gz" + CMAKE_URL="http://www.cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz" mkdir cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake export PATH=${DEPS_DIR}/cmake/bin:${PATH} elif [[ "${TRAVIS_OS_NAME}" == "osx" ]]; then diff --git a/CMake/MiscFunctions.cmake b/CMake/MiscFunctions.cmake new file mode 100644 index 00000000..262f7cd8 --- /dev/null +++ b/CMake/MiscFunctions.cmake @@ -0,0 +1,26 @@ +#checks that the given hard-coded list contains all headers + sources in the given folder +function(CheckFileList LIST_VAR FOLDER) + set(MESSAGE " should be added to the variable ${LIST_VAR}") + set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n") + file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp" + "${FOLDER}/*.hpp" + "${FOLDER}/*.h") + list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}}) + foreach(EXTRA_ITEM ${GLOBBED_LIST}) + string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}") + message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}") + endforeach() +endfunction() + +function(CheckFileListRec LIST_VAR FOLDER) + set(MESSAGE " should be added to the variable ${LIST_VAR}") + set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n") + file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp" + "${FOLDER}/*.hpp" + "${FOLDER}/*.h") + list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}}) + foreach(EXTRA_ITEM ${GLOBBED_LIST}) + string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}") + message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}") + endforeach() +endfunction() diff --git a/catch.pc.in b/CMake/catch2.pc.in similarity index 64% rename from catch.pc.in rename to CMake/catch2.pc.in index c2496d29..d50c753b 100644 --- a/catch.pc.in +++ b/CMake/catch2.pc.in @@ -1,6 +1,6 @@ includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ -Name: Catch +Name: Catch2 Description: Testing library for C++ Version: @Catch2_VERSION@ -Cflags: -I${includedir} -I${includedir}/catch +Cflags: -I${includedir} diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fdb5086..ce1ecf8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.1) +cmake_minimum_required(VERSION 3.5) # detect if Catch is being bundled, # disable testsuite in that case @@ -8,7 +8,12 @@ endif() project(Catch2 LANGUAGES CXX VERSION 2.2.3) +# Provide path for scripts +list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") + include(GNUInstallDirs) +include(CMakePackageConfigHelpers) +include(CTest) option(CATCH_USE_VALGRIND "Perform SelfTests with Valgrind" OFF) option(CATCH_BUILD_EXAMPLES "Build documentation examples" OFF) @@ -27,433 +32,115 @@ if(USE_WMAIN) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /ENTRY:wmainCRTStartup") endif() -#checks that the given hard-coded list contains all headers + sources in the given folder -function(CheckFileList LIST_VAR FOLDER) - set(MESSAGE " should be added to the variable ${LIST_VAR}") - set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n") - file(GLOB GLOBBED_LIST "${FOLDER}/*.cpp" - "${FOLDER}/*.hpp" - "${FOLDER}/*.h") - list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}}) - foreach(EXTRA_ITEM ${GLOBBED_LIST}) - string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}") - message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}") - endforeach() -endfunction() - -function(CheckFileListRec LIST_VAR FOLDER) - set(MESSAGE " should be added to the variable ${LIST_VAR}") - set(MESSAGE "${MESSAGE} in ${CMAKE_CURRENT_LIST_FILE}\n") - file(GLOB_RECURSE GLOBBED_LIST "${FOLDER}/*.cpp" - "${FOLDER}/*.hpp" - "${FOLDER}/*.h") - list(REMOVE_ITEM GLOBBED_LIST ${${LIST_VAR}}) - foreach(EXTRA_ITEM ${GLOBBED_LIST}) - string(REPLACE "${CATCH_DIR}/" "" RELATIVE_FILE_NAME "${EXTRA_ITEM}") - message(AUTHOR_WARNING "The file \"${RELATIVE_FILE_NAME}\"${MESSAGE}") - endforeach() -endfunction() - -# define the sources of the self test -# Please keep these ordered alphabetically -set(TEST_SOURCES - ${SELF_TEST_DIR}/TestMain.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/TagAlias.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp - ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp - ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp - ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp - ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp - ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp - ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp - ) -CheckFileList(TEST_SOURCES ${SELF_TEST_DIR}) - -# A set of impl files that just #include a single header -# Please keep these ordered alphabetically -set(SURROGATE_SOURCES - ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp - ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp - ) -CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps) - - -# Please keep these ordered alphabetically -set(TOP_LEVEL_HEADERS - ${HEADER_DIR}/catch.hpp - ${HEADER_DIR}/catch_with_main.hpp - ) -CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR}) - -# Please keep these ordered alphabetically -set(EXTERNAL_HEADERS - ${HEADER_DIR}/external/clara.hpp - ) -CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external) - - -# Please keep these ordered alphabetically -set(INTERNAL_HEADERS - ${HEADER_DIR}/internal/catch_approx.h - ${HEADER_DIR}/internal/catch_assertionhandler.h - ${HEADER_DIR}/internal/catch_assertioninfo.h - ${HEADER_DIR}/internal/catch_assertionresult.h - ${HEADER_DIR}/internal/catch_capture.hpp - ${HEADER_DIR}/internal/catch_capture_matchers.h - ${HEADER_DIR}/internal/catch_clara.h - ${HEADER_DIR}/internal/catch_commandline.h - ${HEADER_DIR}/internal/catch_common.h - ${HEADER_DIR}/internal/catch_compiler_capabilities.h - ${HEADER_DIR}/internal/catch_config.hpp - ${HEADER_DIR}/internal/catch_console_colour.h - ${HEADER_DIR}/internal/catch_context.h - ${HEADER_DIR}/internal/catch_debug_console.h - ${HEADER_DIR}/internal/catch_debugger.h - ${HEADER_DIR}/internal/catch_decomposer.h - ${HEADER_DIR}/internal/catch_default_main.hpp - ${HEADER_DIR}/internal/catch_enforce.h - ${HEADER_DIR}/internal/catch_errno_guard.h - ${HEADER_DIR}/internal/catch_exception_translator_registry.h - ${HEADER_DIR}/internal/catch_external_interfaces.h - ${HEADER_DIR}/internal/catch_fatal_condition.h - ${HEADER_DIR}/internal/catch_impl.hpp - ${HEADER_DIR}/internal/catch_interfaces_capture.h - ${HEADER_DIR}/internal/catch_interfaces_config.h - ${HEADER_DIR}/internal/catch_interfaces_exception.h - ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h - ${HEADER_DIR}/internal/catch_interfaces_reporter.h - ${HEADER_DIR}/internal/catch_interfaces_runner.h - ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h - ${HEADER_DIR}/internal/catch_interfaces_testcase.h - ${HEADER_DIR}/internal/catch_leak_detector.h - ${HEADER_DIR}/internal/catch_list.h - ${HEADER_DIR}/internal/catch_matchers.h - ${HEADER_DIR}/internal/catch_matchers_floating.h - ${HEADER_DIR}/internal/catch_matchers_generic.hpp - ${HEADER_DIR}/internal/catch_matchers_string.h - ${HEADER_DIR}/internal/catch_matchers_vector.h - ${HEADER_DIR}/internal/catch_message.h - ${HEADER_DIR}/internal/catch_objc.hpp - ${HEADER_DIR}/internal/catch_objc_arc.hpp - ${HEADER_DIR}/internal/catch_option.hpp - ${HEADER_DIR}/internal/catch_output_redirect.h - ${HEADER_DIR}/internal/catch_platform.h - ${HEADER_DIR}/internal/catch_random_number_generator.h - ${HEADER_DIR}/internal/catch_reenable_warnings.h - ${HEADER_DIR}/internal/catch_reporter_registrars.hpp - ${HEADER_DIR}/internal/catch_reporter_registry.h - ${HEADER_DIR}/internal/catch_result_type.h - ${HEADER_DIR}/internal/catch_run_context.h - ${HEADER_DIR}/internal/catch_benchmark.h - ${HEADER_DIR}/internal/catch_section.h - ${HEADER_DIR}/internal/catch_section_info.h - ${HEADER_DIR}/internal/catch_session.h - ${HEADER_DIR}/internal/catch_startup_exception_registry.h - ${HEADER_DIR}/internal/catch_stream.h - ${HEADER_DIR}/internal/catch_stringref.h - ${HEADER_DIR}/internal/catch_string_manip.h - ${HEADER_DIR}/internal/catch_suppress_warnings.h - ${HEADER_DIR}/internal/catch_tag_alias.h - ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.h - ${HEADER_DIR}/internal/catch_tag_alias_registry.h - ${HEADER_DIR}/internal/catch_test_case_info.h - ${HEADER_DIR}/internal/catch_test_case_registry_impl.h - ${HEADER_DIR}/internal/catch_test_case_tracker.h - ${HEADER_DIR}/internal/catch_test_registry.h - ${HEADER_DIR}/internal/catch_test_spec.h - ${HEADER_DIR}/internal/catch_test_spec_parser.h - ${HEADER_DIR}/internal/catch_text.h - ${HEADER_DIR}/internal/catch_timer.h - ${HEADER_DIR}/internal/catch_to_string.hpp - ${HEADER_DIR}/internal/catch_tostring.h - ${HEADER_DIR}/internal/catch_totals.h - ${HEADER_DIR}/internal/catch_uncaught_exceptions.h - ${HEADER_DIR}/internal/catch_user_interfaces.h - ${HEADER_DIR}/internal/catch_version.h - ${HEADER_DIR}/internal/catch_wildcard_pattern.h - ${HEADER_DIR}/internal/catch_windows_h_proxy.h - ${HEADER_DIR}/internal/catch_xmlwriter.h - ) -set(IMPL_SOURCES - ${HEADER_DIR}/internal/catch_approx.cpp - ${HEADER_DIR}/internal/catch_assertionhandler.cpp - ${HEADER_DIR}/internal/catch_assertionresult.cpp - ${HEADER_DIR}/internal/catch_benchmark.cpp - ${HEADER_DIR}/internal/catch_capture_matchers.cpp - ${HEADER_DIR}/internal/catch_commandline.cpp - ${HEADER_DIR}/internal/catch_common.cpp - ${HEADER_DIR}/internal/catch_config.cpp - ${HEADER_DIR}/internal/catch_console_colour.cpp - ${HEADER_DIR}/internal/catch_context.cpp - ${HEADER_DIR}/internal/catch_debug_console.cpp - ${HEADER_DIR}/internal/catch_debugger.cpp - ${HEADER_DIR}/internal/catch_decomposer.cpp - ${HEADER_DIR}/internal/catch_errno_guard.cpp - ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp - ${HEADER_DIR}/internal/catch_fatal_condition.cpp - ${HEADER_DIR}/internal/catch_interfaces_capture.cpp - ${HEADER_DIR}/internal/catch_interfaces_config.cpp - ${HEADER_DIR}/internal/catch_interfaces_exception.cpp - ${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp - ${HEADER_DIR}/internal/catch_interfaces_runner.cpp - ${HEADER_DIR}/internal/catch_interfaces_testcase.cpp - ${HEADER_DIR}/internal/catch_list.cpp - ${HEADER_DIR}/internal/catch_leak_detector.cpp - ${HEADER_DIR}/internal/catch_matchers.cpp - ${HEADER_DIR}/internal/catch_matchers_floating.cpp - ${HEADER_DIR}/internal/catch_matchers_generic.cpp - ${HEADER_DIR}/internal/catch_matchers_string.cpp - ${HEADER_DIR}/internal/catch_message.cpp - ${HEADER_DIR}/internal/catch_output_redirect.cpp - ${HEADER_DIR}/internal/catch_registry_hub.cpp - ${HEADER_DIR}/internal/catch_interfaces_reporter.cpp - ${HEADER_DIR}/internal/catch_random_number_generator.cpp - ${HEADER_DIR}/internal/catch_reporter_registry.cpp - ${HEADER_DIR}/internal/catch_result_type.cpp - ${HEADER_DIR}/internal/catch_run_context.cpp - ${HEADER_DIR}/internal/catch_section.cpp - ${HEADER_DIR}/internal/catch_section_info.cpp - ${HEADER_DIR}/internal/catch_session.cpp - ${HEADER_DIR}/internal/catch_startup_exception_registry.cpp - ${HEADER_DIR}/internal/catch_stream.cpp - ${HEADER_DIR}/internal/catch_stringref.cpp - ${HEADER_DIR}/internal/catch_string_manip.cpp - ${HEADER_DIR}/internal/catch_tag_alias.cpp - ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.cpp - ${HEADER_DIR}/internal/catch_tag_alias_registry.cpp - ${HEADER_DIR}/internal/catch_test_case_info.cpp - ${HEADER_DIR}/internal/catch_test_case_registry_impl.cpp - ${HEADER_DIR}/internal/catch_test_case_tracker.cpp - ${HEADER_DIR}/internal/catch_test_registry.cpp - ${HEADER_DIR}/internal/catch_test_spec.cpp - ${HEADER_DIR}/internal/catch_test_spec_parser.cpp - ${HEADER_DIR}/internal/catch_timer.cpp - ${HEADER_DIR}/internal/catch_tostring.cpp - ${HEADER_DIR}/internal/catch_totals.cpp - ${HEADER_DIR}/internal/catch_uncaught_exceptions.cpp - ${HEADER_DIR}/internal/catch_version.cpp - ${HEADER_DIR}/internal/catch_wildcard_pattern.cpp - ${HEADER_DIR}/internal/catch_xmlwriter.cpp - ) -set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS}) -CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal) - -# Please keep these ordered alphabetically -set(REPORTER_HEADERS - ${HEADER_DIR}/reporters/catch_reporter_automake.hpp - ${HEADER_DIR}/reporters/catch_reporter_bases.hpp - ${HEADER_DIR}/reporters/catch_reporter_compact.h - ${HEADER_DIR}/reporters/catch_reporter_console.h - ${HEADER_DIR}/reporters/catch_reporter_junit.h - ${HEADER_DIR}/reporters/catch_reporter_listening.h - ${HEADER_DIR}/reporters/catch_reporter_tap.hpp - ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp - ${HEADER_DIR}/reporters/catch_reporter_xml.h - ) -set(REPORTER_SOURCES - ${HEADER_DIR}/reporters/catch_reporter_bases.cpp - ${HEADER_DIR}/reporters/catch_reporter_compact.cpp - ${HEADER_DIR}/reporters/catch_reporter_console.cpp - ${HEADER_DIR}/reporters/catch_reporter_junit.cpp - ${HEADER_DIR}/reporters/catch_reporter_listening.cpp - ${HEADER_DIR}/reporters/catch_reporter_xml.cpp - ) -set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES}) -CheckFileList(REPORTER_FILES ${HEADER_DIR}/reporters) - -# Specify the headers, too, so CLion recognises them as project files -set(HEADERS - ${TOP_LEVEL_HEADERS} - ${EXTERNAL_HEADERS} - ${INTERNAL_HEADERS} - ${REPORTER_HEADERS} - ) - -# Provide some groupings for IDEs -SOURCE_GROUP("Tests" FILES ${TEST_SOURCES}) -SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES}) - - -# Projects consuming Catch via ExternalProject_Add might want to use install step -# without building all of our selftests. - -if(DEFINED NO_SELFTEST) - message(DEPRECATION "*** CMake option NO_SELFTEST is deprecated; use BUILD_TESTING instead") - if (NO_SELFTEST) - set(BUILD_TESTING OFF CACHE BOOL "Disable Catch2 internal testsuite" FORCE) - else() - set(BUILD_TESTING ON CACHE BOOL "Disable Catch2 internal testsuite" FORCE) - endif() -endif() - -include(CTest) - if (BUILD_TESTING AND NOT_SUBPROJECT) - add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS}) - target_include_directories(SelfTest PRIVATE ${HEADER_DIR}) - - if(USE_CPP14) - message(STATUS "Enabling C++14") - set_property(TARGET SelfTest PROPERTY CXX_STANDARD 14) - else() - message(STATUS "Enabling C++11") - set_property(TARGET SelfTest PROPERTY CXX_STANDARD 11) - endif() - - set_property(TARGET SelfTest PROPERTY CXX_STANDARD_REQUIRED ON) - set_property(TARGET SelfTest PROPERTY CXX_EXTENSIONS OFF) - - if (CATCH_ENABLE_COVERAGE) - set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE) - list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/CMake") - find_package(codecov) - add_coverage(SelfTest) - list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'") - coverage_evaluate() - endif() - - # Add per compiler options - if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" ) - target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic) - if (CATCH_ENABLE_WERROR) - target_compile_options( SelfTest PRIVATE -Werror) - endif() - endif() - # Clang specific options go here - if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) - target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn ) - endif() - if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) - STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level - target_compile_options( SelfTest PRIVATE /w44265 /w44061 /w44062 ) - if (CATCH_ENABLE_WERROR) - target_compile_options( SelfTest PRIVATE /WX) - endif() - # Force MSVC to consider everything as encoded in utf-8 - target_compile_options( SelfTest PRIVATE /utf-8 ) - endif() - - - # configure unit tests via CTest - include(CTest) - add_test(NAME RunTests COMMAND $) - - add_test(NAME ListTests COMMAND $ --list-tests --verbosity high) - set_tests_properties(ListTests PROPERTIES - PASS_REGULAR_EXPRESSION "[0-9]+ test cases" - FAIL_REGULAR_EXPRESSION "Hidden Test" - ) - - add_test(NAME ListTags COMMAND $ --list-tags) - set_tests_properties(ListTags PROPERTIES - PASS_REGULAR_EXPRESSION "[0-9]+ tags" - FAIL_REGULAR_EXPRESSION "[.]") - - add_test(NAME ListReporters COMMAND $ --list-reporters) - set_tests_properties(ListReporters PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:") - - add_test(NAME ListTestNamesOnly COMMAND $ --list-test-names-only) - set_tests_properties(ListTestNamesOnly PROPERTIES - PASS_REGULAR_EXPRESSION "Regex string matcher" - FAIL_REGULAR_EXPRESSION "Hidden Test") - - add_test(NAME NoAssertions COMMAND $ -w NoAssertions) - set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case") - - add_test(NAME NoTest COMMAND $ -w NoTests "___nonexistent_test___") - set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched") - - # AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable - add_test(NAME ApprovalTests COMMAND python ${CMAKE_CURRENT_SOURCE_DIR}/scripts/approvalTests.py $) - set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed") - - if (CATCH_USE_VALGRIND) - add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $) - add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $ --list-tests --verbosity high) - set_tests_properties(ValgrindListTests PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks") - add_test(NAME ValgrindListTags COMMAND valgrind --leak-check=full --error-exitcode=1 $ --list-tags) - set_tests_properties(ValgrindListTags PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks") - endif() - -endif() # !NO_SELFTEST - + add_subdirectory(projects) +endif() if(CATCH_BUILD_EXAMPLES) add_subdirectory(examples) endif() -install(DIRECTORY "single_include/" DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/catch") - -install(DIRECTORY docs/ DESTINATION "${CMAKE_INSTALL_DOCDIR}") - -## Provide some pkg-config integration -# Don't bother on Windows -if(NOT WIN32 OR NOT CMAKE_HOST_SYSTEM_NAME MATCHES Windows) - - set(PKGCONFIG_INSTALL_DIR - "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" - CACHE PATH "Path where catch.pc is installed" - ) - - configure_file(${CMAKE_CURRENT_SOURCE_DIR}/catch.pc.in ${CMAKE_CURRENT_BINARY_DIR}/catch.pc @ONLY) - install(FILES ${CMAKE_CURRENT_BINARY_DIR}/catch.pc DESTINATION ${PKGCONFIG_INSTALL_DIR}) - -endif() # add catch as a 'linkable' target -add_library(Catch INTERFACE) +add_library(Catch2 INTERFACE) -# depend on some obvious c++11 features so the dependency is transitively added dependants -target_compile_features(Catch INTERFACE cxx_auto_type cxx_constexpr cxx_noexcept) -target_include_directories(Catch - INTERFACE - $ - $ - $) + +# depend on some obvious c++11 features so the dependency is transitively added dependents +target_compile_features(Catch2 + INTERFACE + cxx_alignas + cxx_alignof + cxx_attributes + cxx_auto_type + cxx_constexpr + cxx_defaulted_functions + cxx_deleted_functions + cxx_final + cxx_lambdas + cxx_noexcept + cxx_override + cxx_range_for + cxx_rvalue_references + cxx_static_assert + cxx_strong_enums + cxx_trailing_return_types + cxx_unicode_literals + cxx_user_literals + cxx_variadic_macros +) + +target_include_directories(Catch2 + INTERFACE + $ + $ +) # provide a namespaced alias for clients to 'link' against if catch is included as a sub-project -add_library(Catch2::Catch ALIAS Catch) +add_library(Catch2::Catch2 ALIAS Catch2) set(CATCH_CMAKE_CONFIG_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/Catch2") # create and install an export set for catch target as Catch2::Catch -install(TARGETS Catch EXPORT Catch2Config DESTINATION ${CMAKE_INSTALL_LIBDIR}) +install( + TARGETS + Catch2 + EXPORT + Catch2Config + DESTINATION ${CMAKE_INSTALL_LIBDIR} +) -install(EXPORT Catch2Config - NAMESPACE Catch2:: - DESTINATION ${CATCH_CMAKE_CONFIG_DESTINATION}) - -# install Catch2ConfigVersion.cmake file to handle versions in find_package -include(CMakePackageConfigHelpers) +install( + EXPORT + Catch2Config + NAMESPACE + Catch2:: + DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} +) write_basic_package_version_file( - "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" - COMPATIBILITY SameMajorVersion) + "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" + COMPATIBILITY + SameMajorVersion +) -install(FILES - "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" - DESTINATION ${CATCH_CMAKE_CONFIG_DESTINATION}) +install( + DIRECTORY + "single_include/" + DESTINATION + "${CMAKE_INSTALL_INCLUDEDIR}" +) + +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" + DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} +) + +# Install documentation +install( + DIRECTORY + docs/ + DESTINATION + "${CMAKE_INSTALL_DOCDIR}" +) + + +## Provide some pkg-config integration +set(PKGCONFIG_INSTALL_DIR + "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig" + CACHE PATH "Path where catch2.pc is installed" +) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/CMake/catch2.pc.in + ${CMAKE_CURRENT_BINARY_DIR}/catch2.pc + @ONLY +) +install( + FILES + "${CMAKE_CURRENT_BINARY_DIR}/catch2.pc" + DESTINATION + ${PKGCONFIG_INSTALL_DIR} +) diff --git a/conanfile.py b/conanfile.py index 716ca420..ba39e6b0 100644 --- a/conanfile.py +++ b/conanfile.py @@ -9,11 +9,11 @@ class CatchConan(ConanFile): author = "philsquared" generators = "cmake" exports_sources = "single_include/*" - url = "https://github.com/philsquared/Catch" + url = "https://github.com/catchorg/Catch2" license = "Boost Software License - Version 1.0. http://www.boost.org/LICENSE_1_0.txt" def package(self): - self.copy(pattern="catch.hpp", src="single_include", dst="include") + self.copy(pattern="catch.hpp", src="single_include/catch2", dst="include/catch2") def package_id(self): self.info.header_only() diff --git a/examples/000-CatchMain.cpp b/examples/000-CatchMain.cpp index c8bf91e4..2894d425 100644 --- a/examples/000-CatchMain.cpp +++ b/examples/000-CatchMain.cpp @@ -6,7 +6,7 @@ // Let Catch provide main(): #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include // That's it diff --git a/examples/010-TestCase.cpp b/examples/010-TestCase.cpp index 16a212a3..c00b8a8f 100644 --- a/examples/010-TestCase.cpp +++ b/examples/010-TestCase.cpp @@ -3,7 +3,7 @@ // Let Catch provide main(): #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include int Factorial( int number ) { return number <= 1 ? number : Factorial( number - 1 ) * number; // fail diff --git a/examples/020-TestCase-1.cpp b/examples/020-TestCase-1.cpp index 0d10276c..ab0249e4 100644 --- a/examples/020-TestCase-1.cpp +++ b/examples/020-TestCase-1.cpp @@ -6,7 +6,7 @@ // Let Catch provide main(): #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include TEST_CASE( "1: All test cases reside in other .cpp files (empty)", "[multi-file:1]" ) { } diff --git a/examples/020-TestCase-2.cpp b/examples/020-TestCase-2.cpp index 2cca3621..08b313e0 100644 --- a/examples/020-TestCase-2.cpp +++ b/examples/020-TestCase-2.cpp @@ -2,7 +2,7 @@ // main() provided by Catch in file 020-TestCase-1.cpp. -#include "catch.hpp" +#include int Factorial( int number ) { return number <= 1 ? number : Factorial( number - 1 ) * number; // fail diff --git a/examples/030-Asn-Require-Check.cpp b/examples/030-Asn-Require-Check.cpp index 35f2ff79..f814a1b3 100644 --- a/examples/030-Asn-Require-Check.cpp +++ b/examples/030-Asn-Require-Check.cpp @@ -10,7 +10,7 @@ // main() provided in 000-CatchMain.cpp -#include "catch.hpp" +#include std::string one() { return "1"; diff --git a/examples/100-Fix-Section.cpp b/examples/100-Fix-Section.cpp index 8cb94bff..d0b9f2da 100644 --- a/examples/100-Fix-Section.cpp +++ b/examples/100-Fix-Section.cpp @@ -6,7 +6,7 @@ // main() provided in 000-CatchMain.cpp -#include "catch.hpp" +#include TEST_CASE( "vectors can be sized and resized", "[vector]" ) { diff --git a/examples/110-Fix-ClassFixture.cpp b/examples/110-Fix-ClassFixture.cpp index 06c2cf32..e42fd175 100644 --- a/examples/110-Fix-ClassFixture.cpp +++ b/examples/110-Fix-ClassFixture.cpp @@ -6,7 +6,7 @@ // main() provided in 000-CatchMain.cpp -#include "catch.hpp" +#include class DBConnection { diff --git a/examples/120-Bdd-ScenarioGivenWhenThen.cpp b/examples/120-Bdd-ScenarioGivenWhenThen.cpp index c45f1f26..d1b9ce55 100644 --- a/examples/120-Bdd-ScenarioGivenWhenThen.cpp +++ b/examples/120-Bdd-ScenarioGivenWhenThen.cpp @@ -2,7 +2,7 @@ // main() provided in 000-CatchMain.cpp -#include "catch.hpp" +#include SCENARIO( "vectors can be sized and resized", "[vector]" ) { diff --git a/examples/210-Evt-EventListeners.cpp b/examples/210-Evt-EventListeners.cpp index 8ba360f5..d1df6b7b 100644 --- a/examples/210-Evt-EventListeners.cpp +++ b/examples/210-Evt-EventListeners.cpp @@ -10,7 +10,7 @@ // Let Catch provide the required interfaces: #define CATCH_CONFIG_EXTERNAL_INTERFACES -#include "catch.hpp" +#include #include // ----------------------------------------------------------------------- diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 7270e933..72d04763 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -68,16 +68,16 @@ set( TARGETS_ALL ${TARGETS_SINGLE_FILE} ${TARGETS_IDIOMATIC_TESTS} 0 # define program targets: -add_library( CatchMain OBJECT ${EXAMPLES_DIR}/${SOURCES_IDIOMATIC_MAIN} ${HEADER_DIR}/catch.hpp ) +add_library( CatchMain OBJECT ${EXAMPLES_DIR}/${SOURCES_IDIOMATIC_MAIN} ${HEADER_DIR}/catch2/catch.hpp ) -add_executable( 020-TestCase ${EXAMPLES_DIR}/020-TestCase-1.cpp ${EXAMPLES_DIR}/020-TestCase-2.cpp ${HEADER_DIR}/catch.hpp ) +add_executable( 020-TestCase ${EXAMPLES_DIR}/020-TestCase-1.cpp ${EXAMPLES_DIR}/020-TestCase-2.cpp ${HEADER_DIR}/catch2/catch.hpp ) foreach( name ${TARGETS_SINGLE_FILE} ) - add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp ${HEADER_DIR}/catch.hpp ) + add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp ${HEADER_DIR}/catch2/catch.hpp ) endforeach() foreach( name ${TARGETS_IDIOMATIC_TESTS} ) - add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp $ ${HEADER_DIR}/catch.hpp ) + add_executable( ${name} ${EXAMPLES_DIR}/${name}.cpp $ ${HEADER_DIR}/catch2/catch.hpp ) endforeach() foreach( name ${TARGETS_ALL} ) diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt new file mode 100644 index 00000000..49888b15 --- /dev/null +++ b/projects/CMakeLists.txt @@ -0,0 +1,329 @@ +include(MiscFunctions) + +# define the sources of the self test +# Please keep these ordered alphabetically +set(TEST_SOURCES + ${SELF_TEST_DIR}/TestMain.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/TagAlias.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/String.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Xml.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Approx.tests.cpp + ${SELF_TEST_DIR}/UsageTests/BDD.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Benchmark.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Class.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Compilation.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Condition.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Decomposition.tests.cpp + ${SELF_TEST_DIR}/UsageTests/EnumToString.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Exception.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Message.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Misc.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringChrono.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringGeneral.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringPair.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringTuple.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringVector.tests.cpp + ${SELF_TEST_DIR}/UsageTests/ToStringWhich.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Tricky.tests.cpp + ${SELF_TEST_DIR}/UsageTests/VariadicMacros.tests.cpp + ${SELF_TEST_DIR}/UsageTests/Matchers.tests.cpp + ) +CheckFileList(TEST_SOURCES ${SELF_TEST_DIR}) + +# A set of impl files that just #include a single header +# Please keep these ordered alphabetically +set(SURROGATE_SOURCES + ${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp + ${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp + ) +CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps) + + +# Please keep these ordered alphabetically +set(TOP_LEVEL_HEADERS + ${HEADER_DIR}/catch.hpp + ${HEADER_DIR}/catch_with_main.hpp + ) +CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR}) + +# Please keep these ordered alphabetically +set(EXTERNAL_HEADERS + ${HEADER_DIR}/external/clara.hpp + ) +CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external) + + +# Please keep these ordered alphabetically +set(INTERNAL_HEADERS + ${HEADER_DIR}/internal/catch_approx.h + ${HEADER_DIR}/internal/catch_assertionhandler.h + ${HEADER_DIR}/internal/catch_assertioninfo.h + ${HEADER_DIR}/internal/catch_assertionresult.h + ${HEADER_DIR}/internal/catch_capture.hpp + ${HEADER_DIR}/internal/catch_capture_matchers.h + ${HEADER_DIR}/internal/catch_clara.h + ${HEADER_DIR}/internal/catch_commandline.h + ${HEADER_DIR}/internal/catch_common.h + ${HEADER_DIR}/internal/catch_compiler_capabilities.h + ${HEADER_DIR}/internal/catch_config.hpp + ${HEADER_DIR}/internal/catch_console_colour.h + ${HEADER_DIR}/internal/catch_context.h + ${HEADER_DIR}/internal/catch_debug_console.h + ${HEADER_DIR}/internal/catch_debugger.h + ${HEADER_DIR}/internal/catch_decomposer.h + ${HEADER_DIR}/internal/catch_default_main.hpp + ${HEADER_DIR}/internal/catch_enforce.h + ${HEADER_DIR}/internal/catch_errno_guard.h + ${HEADER_DIR}/internal/catch_exception_translator_registry.h + ${HEADER_DIR}/internal/catch_external_interfaces.h + ${HEADER_DIR}/internal/catch_fatal_condition.h + ${HEADER_DIR}/internal/catch_impl.hpp + ${HEADER_DIR}/internal/catch_interfaces_capture.h + ${HEADER_DIR}/internal/catch_interfaces_config.h + ${HEADER_DIR}/internal/catch_interfaces_exception.h + ${HEADER_DIR}/internal/catch_interfaces_registry_hub.h + ${HEADER_DIR}/internal/catch_interfaces_reporter.h + ${HEADER_DIR}/internal/catch_interfaces_runner.h + ${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h + ${HEADER_DIR}/internal/catch_interfaces_testcase.h + ${HEADER_DIR}/internal/catch_leak_detector.h + ${HEADER_DIR}/internal/catch_list.h + ${HEADER_DIR}/internal/catch_matchers.h + ${HEADER_DIR}/internal/catch_matchers_floating.h + ${HEADER_DIR}/internal/catch_matchers_generic.hpp + ${HEADER_DIR}/internal/catch_matchers_string.h + ${HEADER_DIR}/internal/catch_matchers_vector.h + ${HEADER_DIR}/internal/catch_message.h + ${HEADER_DIR}/internal/catch_objc.hpp + ${HEADER_DIR}/internal/catch_objc_arc.hpp + ${HEADER_DIR}/internal/catch_option.hpp + ${HEADER_DIR}/internal/catch_output_redirect.h + ${HEADER_DIR}/internal/catch_platform.h + ${HEADER_DIR}/internal/catch_random_number_generator.h + ${HEADER_DIR}/internal/catch_reenable_warnings.h + ${HEADER_DIR}/internal/catch_reporter_registrars.hpp + ${HEADER_DIR}/internal/catch_reporter_registry.h + ${HEADER_DIR}/internal/catch_result_type.h + ${HEADER_DIR}/internal/catch_run_context.h + ${HEADER_DIR}/internal/catch_benchmark.h + ${HEADER_DIR}/internal/catch_section.h + ${HEADER_DIR}/internal/catch_section_info.h + ${HEADER_DIR}/internal/catch_session.h + ${HEADER_DIR}/internal/catch_startup_exception_registry.h + ${HEADER_DIR}/internal/catch_stream.h + ${HEADER_DIR}/internal/catch_stringref.h + ${HEADER_DIR}/internal/catch_string_manip.h + ${HEADER_DIR}/internal/catch_suppress_warnings.h + ${HEADER_DIR}/internal/catch_tag_alias.h + ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.h + ${HEADER_DIR}/internal/catch_tag_alias_registry.h + ${HEADER_DIR}/internal/catch_test_case_info.h + ${HEADER_DIR}/internal/catch_test_case_registry_impl.h + ${HEADER_DIR}/internal/catch_test_case_tracker.h + ${HEADER_DIR}/internal/catch_test_registry.h + ${HEADER_DIR}/internal/catch_test_spec.h + ${HEADER_DIR}/internal/catch_test_spec_parser.h + ${HEADER_DIR}/internal/catch_text.h + ${HEADER_DIR}/internal/catch_timer.h + ${HEADER_DIR}/internal/catch_to_string.hpp + ${HEADER_DIR}/internal/catch_tostring.h + ${HEADER_DIR}/internal/catch_totals.h + ${HEADER_DIR}/internal/catch_uncaught_exceptions.h + ${HEADER_DIR}/internal/catch_user_interfaces.h + ${HEADER_DIR}/internal/catch_version.h + ${HEADER_DIR}/internal/catch_wildcard_pattern.h + ${HEADER_DIR}/internal/catch_windows_h_proxy.h + ${HEADER_DIR}/internal/catch_xmlwriter.h + ) +set(IMPL_SOURCES + ${HEADER_DIR}/internal/catch_approx.cpp + ${HEADER_DIR}/internal/catch_assertionhandler.cpp + ${HEADER_DIR}/internal/catch_assertionresult.cpp + ${HEADER_DIR}/internal/catch_benchmark.cpp + ${HEADER_DIR}/internal/catch_capture_matchers.cpp + ${HEADER_DIR}/internal/catch_commandline.cpp + ${HEADER_DIR}/internal/catch_common.cpp + ${HEADER_DIR}/internal/catch_config.cpp + ${HEADER_DIR}/internal/catch_console_colour.cpp + ${HEADER_DIR}/internal/catch_context.cpp + ${HEADER_DIR}/internal/catch_debug_console.cpp + ${HEADER_DIR}/internal/catch_debugger.cpp + ${HEADER_DIR}/internal/catch_decomposer.cpp + ${HEADER_DIR}/internal/catch_errno_guard.cpp + ${HEADER_DIR}/internal/catch_exception_translator_registry.cpp + ${HEADER_DIR}/internal/catch_fatal_condition.cpp + ${HEADER_DIR}/internal/catch_interfaces_capture.cpp + ${HEADER_DIR}/internal/catch_interfaces_config.cpp + ${HEADER_DIR}/internal/catch_interfaces_exception.cpp + ${HEADER_DIR}/internal/catch_interfaces_registry_hub.cpp + ${HEADER_DIR}/internal/catch_interfaces_runner.cpp + ${HEADER_DIR}/internal/catch_interfaces_testcase.cpp + ${HEADER_DIR}/internal/catch_list.cpp + ${HEADER_DIR}/internal/catch_leak_detector.cpp + ${HEADER_DIR}/internal/catch_matchers.cpp + ${HEADER_DIR}/internal/catch_matchers_floating.cpp + ${HEADER_DIR}/internal/catch_matchers_generic.cpp + ${HEADER_DIR}/internal/catch_matchers_string.cpp + ${HEADER_DIR}/internal/catch_message.cpp + ${HEADER_DIR}/internal/catch_output_redirect.cpp + ${HEADER_DIR}/internal/catch_registry_hub.cpp + ${HEADER_DIR}/internal/catch_interfaces_reporter.cpp + ${HEADER_DIR}/internal/catch_random_number_generator.cpp + ${HEADER_DIR}/internal/catch_reporter_registry.cpp + ${HEADER_DIR}/internal/catch_result_type.cpp + ${HEADER_DIR}/internal/catch_run_context.cpp + ${HEADER_DIR}/internal/catch_section.cpp + ${HEADER_DIR}/internal/catch_section_info.cpp + ${HEADER_DIR}/internal/catch_session.cpp + ${HEADER_DIR}/internal/catch_startup_exception_registry.cpp + ${HEADER_DIR}/internal/catch_stream.cpp + ${HEADER_DIR}/internal/catch_stringref.cpp + ${HEADER_DIR}/internal/catch_string_manip.cpp + ${HEADER_DIR}/internal/catch_tag_alias.cpp + ${HEADER_DIR}/internal/catch_tag_alias_autoregistrar.cpp + ${HEADER_DIR}/internal/catch_tag_alias_registry.cpp + ${HEADER_DIR}/internal/catch_test_case_info.cpp + ${HEADER_DIR}/internal/catch_test_case_registry_impl.cpp + ${HEADER_DIR}/internal/catch_test_case_tracker.cpp + ${HEADER_DIR}/internal/catch_test_registry.cpp + ${HEADER_DIR}/internal/catch_test_spec.cpp + ${HEADER_DIR}/internal/catch_test_spec_parser.cpp + ${HEADER_DIR}/internal/catch_timer.cpp + ${HEADER_DIR}/internal/catch_tostring.cpp + ${HEADER_DIR}/internal/catch_totals.cpp + ${HEADER_DIR}/internal/catch_uncaught_exceptions.cpp + ${HEADER_DIR}/internal/catch_version.cpp + ${HEADER_DIR}/internal/catch_wildcard_pattern.cpp + ${HEADER_DIR}/internal/catch_xmlwriter.cpp + ) +set(INTERNAL_FILES ${IMPL_SOURCES} ${INTERNAL_HEADERS}) +CheckFileList(INTERNAL_FILES ${HEADER_DIR}/internal) + +# Please keep these ordered alphabetically +set(REPORTER_HEADERS + ${HEADER_DIR}/reporters/catch_reporter_automake.hpp + ${HEADER_DIR}/reporters/catch_reporter_bases.hpp + ${HEADER_DIR}/reporters/catch_reporter_compact.h + ${HEADER_DIR}/reporters/catch_reporter_console.h + ${HEADER_DIR}/reporters/catch_reporter_junit.h + ${HEADER_DIR}/reporters/catch_reporter_listening.h + ${HEADER_DIR}/reporters/catch_reporter_tap.hpp + ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp + ${HEADER_DIR}/reporters/catch_reporter_xml.h + ) +set(REPORTER_SOURCES + ${HEADER_DIR}/reporters/catch_reporter_bases.cpp + ${HEADER_DIR}/reporters/catch_reporter_compact.cpp + ${HEADER_DIR}/reporters/catch_reporter_console.cpp + ${HEADER_DIR}/reporters/catch_reporter_junit.cpp + ${HEADER_DIR}/reporters/catch_reporter_listening.cpp + ${HEADER_DIR}/reporters/catch_reporter_xml.cpp + ) +set(REPORTER_FILES ${REPORTER_HEADERS} ${REPORTER_SOURCES}) +CheckFileList(REPORTER_FILES ${HEADER_DIR}/reporters) + +# Specify the headers, too, so CLion recognises them as project files +set(HEADERS + ${TOP_LEVEL_HEADERS} + ${EXTERNAL_HEADERS} + ${INTERNAL_HEADERS} + ${REPORTER_HEADERS} + ) + +# Provide some groupings for IDEs +SOURCE_GROUP("Tests" FILES ${TEST_SOURCES}) +SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES}) + +include(CTest) + +add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS}) +target_include_directories(SelfTest PRIVATE ${HEADER_DIR}) + +if(USE_CPP14) + message(STATUS "Enabling C++14") + set_property(TARGET SelfTest PROPERTY CXX_STANDARD 14) +else() + message(STATUS "Enabling C++11") + set_property(TARGET SelfTest PROPERTY CXX_STANDARD 11) +endif() + +set_property(TARGET SelfTest PROPERTY CXX_STANDARD_REQUIRED ON) +set_property(TARGET SelfTest PROPERTY CXX_EXTENSIONS OFF) + +if (CATCH_ENABLE_COVERAGE) + set(ENABLE_COVERAGE ON CACHE BOOL "Enable coverage build." FORCE) + find_package(codecov) + add_coverage(SelfTest) + list(APPEND LCOV_REMOVE_PATTERNS "'/usr/*'") + coverage_evaluate() +endif() + +# Add per compiler options +if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" ) + target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code -Wpedantic) + if (CATCH_ENABLE_WERROR) + target_compile_options( SelfTest PRIVATE -Werror) + endif() +endif() +# Clang specific options go here +if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" ) + target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn ) +endif() +if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" ) + STRING(REGEX REPLACE "/W[0-9]" "/W4" CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS}) # override default warning level + target_compile_options( SelfTest PRIVATE /w44265 /w44061 /w44062 ) + if (CATCH_ENABLE_WERROR) + target_compile_options( SelfTest PRIVATE /WX) + endif() + # Force MSVC to consider everything as encoded in utf-8 + target_compile_options( SelfTest PRIVATE /utf-8 ) +endif() + + +# configure unit tests via CTest +add_test(NAME RunTests COMMAND $) + +add_test(NAME ListTests COMMAND $ --list-tests --verbosity high) +set_tests_properties(ListTests PROPERTIES + PASS_REGULAR_EXPRESSION "[0-9]+ test cases" + FAIL_REGULAR_EXPRESSION "Hidden Test" +) + +add_test(NAME ListTags COMMAND $ --list-tags) +set_tests_properties(ListTags PROPERTIES + PASS_REGULAR_EXPRESSION "[0-9]+ tags" + FAIL_REGULAR_EXPRESSION "[.]") + +add_test(NAME ListReporters COMMAND $ --list-reporters) +set_tests_properties(ListReporters PROPERTIES PASS_REGULAR_EXPRESSION "Available reporters:") + +add_test(NAME ListTestNamesOnly COMMAND $ --list-test-names-only) +set_tests_properties(ListTestNamesOnly PROPERTIES + PASS_REGULAR_EXPRESSION "Regex string matcher" + FAIL_REGULAR_EXPRESSION "Hidden Test") + +add_test(NAME NoAssertions COMMAND $ -w NoAssertions) +set_tests_properties(NoAssertions PROPERTIES PASS_REGULAR_EXPRESSION "No assertions in test case") + +add_test(NAME NoTest COMMAND $ -w NoTests "___nonexistent_test___") +set_tests_properties(NoTest PROPERTIES PASS_REGULAR_EXPRESSION "No test cases matched") + +# AppVeyor has a Python 2.7 in path, but doesn't have .py files as autorunnable +add_test(NAME ApprovalTests COMMAND python ${CATCH_DIR}/scripts/approvalTests.py $) +set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed") + +if (CATCH_USE_VALGRIND) + add_test(NAME ValgrindRunTests COMMAND valgrind --leak-check=full --error-exitcode=1 $) + add_test(NAME ValgrindListTests COMMAND valgrind --leak-check=full --error-exitcode=1 $ --list-tests --verbosity high) + set_tests_properties(ValgrindListTests PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks") + add_test(NAME ValgrindListTags COMMAND valgrind --leak-check=full --error-exitcode=1 $ --list-tags) + set_tests_properties(ValgrindListTags PROPERTIES PASS_REGULAR_EXPRESSION "definitely lost: 0 bytes in 0 blocks") +endif() diff --git a/scripts/generateSingleHeader.py b/scripts/generateSingleHeader.py index c3ce1aec..22b882ab 100755 --- a/scripts/generateSingleHeader.py +++ b/scripts/generateSingleHeader.py @@ -24,7 +24,7 @@ def generate(v): seenHeaders = set([]) rootPath = os.path.join( catchPath, 'include/' ) - outputPath = os.path.join( catchPath, 'single_include/catch.hpp' ) + outputPath = os.path.join( catchPath, 'single_include/catch2/catch.hpp' ) globals = { 'includeImpl' : True, diff --git a/scripts/releaseCommon.py b/scripts/releaseCommon.py index 6e44da24..1a8ee2c8 100644 --- a/scripts/releaseCommon.py +++ b/scripts/releaseCommon.py @@ -169,7 +169,7 @@ def performUpdates(version): import shutil for rep in ('automake', 'tap', 'teamcity'): sourceFile = os.path.join(catchPath, 'include/reporters/catch_reporter_{}.hpp'.format(rep)) - destFile = os.path.join(catchPath, 'single_include/catch_reporter_{}.hpp'.format(rep)) + destFile = os.path.join(catchPath, 'single_include', 'catch2', 'catch_reporter_{}.hpp'.format(rep)) shutil.copyfile(sourceFile, destFile) updateReadmeFile(version) diff --git a/scripts/updateWandbox.py b/scripts/updateWandbox.py index 5785feb4..564f9489 100644 --- a/scripts/updateWandbox.py +++ b/scripts/updateWandbox.py @@ -34,7 +34,7 @@ def uploadFiles(): 'code': main_file, 'codes': [{ 'file': 'catch.hpp', - 'code': open(os.path.join(catchPath, 'single_include', 'catch.hpp')).read() + 'code': open(os.path.join(catchPath, 'single_include', 'catch2', 'catch.hpp')).read() }], 'options': 'c++11,cpp-no-pedantic,boost-nothing', 'compiler-option-raw': '-DCATCH_CONFIG_FAST_COMPILE', diff --git a/single_include/catch.hpp b/single_include/catch2/catch.hpp similarity index 99% rename from single_include/catch.hpp rename to single_include/catch2/catch.hpp index 28448ddb..6fac1e7c 100644 --- a/single_include/catch.hpp +++ b/single_include/catch2/catch.hpp @@ -1,6 +1,6 @@ /* * Catch v2.2.3 - * Generated: 2018-06-06 23:11:57.601416 + * Generated: 2018-06-11 22:16:30.128800 * ---------------------------------------------------------- * This file has been merged from multiple headers. Please don't edit it directly * Copyright (c) 2018 Two Blue Cubes Ltd. All rights reserved. diff --git a/single_include/catch_reporter_automake.hpp b/single_include/catch2/catch_reporter_automake.hpp similarity index 100% rename from single_include/catch_reporter_automake.hpp rename to single_include/catch2/catch_reporter_automake.hpp diff --git a/single_include/catch_reporter_tap.hpp b/single_include/catch2/catch_reporter_tap.hpp similarity index 100% rename from single_include/catch_reporter_tap.hpp rename to single_include/catch2/catch_reporter_tap.hpp diff --git a/single_include/catch_reporter_teamcity.hpp b/single_include/catch2/catch_reporter_teamcity.hpp similarity index 100% rename from single_include/catch_reporter_teamcity.hpp rename to single_include/catch2/catch_reporter_teamcity.hpp diff --git a/test_package/MainTest.cpp b/test_package/MainTest.cpp index b8ed744e..010feba2 100644 --- a/test_package/MainTest.cpp +++ b/test_package/MainTest.cpp @@ -6,7 +6,7 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #define CATCH_CONFIG_MAIN -#include "catch.hpp" +#include unsigned int Factorial( unsigned int number ) { return number > 1 ? Factorial(number-1)*number : 1;