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/Catch2Config.cmake.in b/CMake/Catch2Config.cmake.in new file mode 100644 index 00000000..c485219c --- /dev/null +++ b/CMake/Catch2Config.cmake.in @@ -0,0 +1,10 @@ +@PACKAGE_INIT@ + + +# Avoid repeatedly including the targets +if(NOT TARGET Catch2::Catch2) + # Provide path for scripts + list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}") + + include(${CMAKE_CURRENT_LIST_DIR}/Catch2Targets.cmake) +endif() 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/CMake/catch2.pc.in b/CMake/catch2.pc.in new file mode 100644 index 00000000..3ac9fbd1 --- /dev/null +++ b/CMake/catch2.pc.in @@ -0,0 +1,7 @@ +includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ + +Name: Catch2 +Description: A modern, C++-native, header-only, test framework for C++11 +URL: https://github.com/catchorg/Catch2 +Version: @Catch2_VERSION@ +Cflags: -I${includedir} diff --git a/CMakeLists.txt b/CMakeLists.txt index 9fdb5086..76494710 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,12 +8,20 @@ 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) option(CATCH_ENABLE_COVERAGE "Generate coverage for codecov.io" OFF) option(CATCH_ENABLE_WERROR "Enable all warnings as errors" ON) +option(CATCH_INSTALL_DOCS "Install documentation alongside library" ON) +option(CATCH_INSTALL_HELPERS "Install contrib alongside library" ON) + set_property(GLOBAL PROPERTY USE_FOLDERS ON) @@ -27,433 +35,149 @@ 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(EXPORT Catch2Config - NAMESPACE Catch2:: - DESTINATION ${CATCH_CMAKE_CONFIG_DESTINATION}) - -# install Catch2ConfigVersion.cmake file to handle versions in find_package include(CMakePackageConfigHelpers) +configure_package_config_file( + ${CMAKE_CURRENT_LIST_DIR}/CMake/Catch2Config.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/Catch2Config.cmake + INSTALL_DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} +) + + +# create and install an export set for catch target as Catch2::Catch +install( + TARGETS + Catch2 + EXPORT + Catch2Targets + DESTINATION + ${CMAKE_INSTALL_LIBDIR} +) + + +install( + EXPORT + Catch2Targets + 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}/Catch2Config.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/Catch2ConfigVersion.cmake" + DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} +) + +# Install documentation +if(CATCH_INSTALL_DOCS) + install( + DIRECTORY + docs/ + DESTINATION + "${CMAKE_INSTALL_DOCDIR}" + ) +endif() + +if(CATCH_INSTALL_HELPERS) +# Install CMake scripts +install( + FILES + "contrib/ParseAndAddCatchTests.cmake" + "contrib/Catch.cmake" + "contrib/CatchAddTests.cmake" + DESTINATION + ${CATCH_CMAKE_CONFIG_DESTINATION} +) + +# Install debugger helpers +install( + FILES + "contrib/gdbinit" + "contrib/lldbinit" + DESTINATION + ${CMAKE_INSTALL_DATAROOTDIR}/Catch2 +) +endif() + +## 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/catch.pc.in b/catch.pc.in deleted file mode 100644 index c2496d29..00000000 --- a/catch.pc.in +++ /dev/null @@ -1,6 +0,0 @@ -includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@ - -Name: Catch -Description: Testing library for C++ -Version: @Catch2_VERSION@ -Cflags: -I${includedir} -I${includedir}/catch diff --git a/conanfile.py b/conanfile.py index 716ca420..ea9b9a13 100644 --- a/conanfile.py +++ b/conanfile.py @@ -1,5 +1,5 @@ #!/usr/bin/env python -from conans import ConanFile +from conans import ConanFile, CMake class CatchConan(ConanFile): @@ -8,12 +8,24 @@ class CatchConan(ConanFile): description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD" author = "philsquared" generators = "cmake" - exports_sources = "single_include/*" - url = "https://github.com/philsquared/Catch" + # Only needed until conan 1.5 is released + settings = "compiler", "arch" + exports_sources = "single_include/*", "CMakeLists.txt", "CMake/catch2.pc.in", "LICENSE.txt" + url = "https://github.com/catchorg/Catch2" license = "Boost Software License - Version 1.0. http://www.boost.org/LICENSE_1_0.txt" + def build(self): + pass + def package(self): - self.copy(pattern="catch.hpp", src="single_include", dst="include") + cmake = CMake(self) + cmake.definitions["BUILD_TESTING"] = "OFF" + cmake.definitions["CATCH_INSTALL_DOCS"] = "OFF" + cmake.definitions["CATCH_INSTALL_HELPERS"] = "OFF" + cmake.configure() + cmake.install() + + self.copy(pattern="LICENSE.txt", dst="licenses") def package_id(self): - self.info.header_only() + self.info.header_only() diff --git a/docs/Readme.md b/docs/Readme.md index be7d1cd1..07968403 100644 --- a/docs/Readme.md +++ b/docs/Readme.md @@ -20,7 +20,10 @@ Fine tuning: Running: * [Command line](command-line.md#top) -* [CI and Build system integration](build-systems.md#top) + +Odds and ends: +* [CMake integration](cmake-integration.md#top) +* [CI and other miscellaneous pieces](ci-and-misc.md#top) FAQ: * [Why are my tests slow to compile?](slow-compiles.md#top) diff --git a/docs/build-systems.md b/docs/ci-and-misc.md similarity index 59% rename from docs/build-systems.md rename to docs/ci-and-misc.md index 2873bc62..97d5c839 100644 --- a/docs/build-systems.md +++ b/docs/ci-and-misc.md @@ -1,6 +1,7 @@ -# CI and build system integration +# CI and other odd pieces +This page talks about how Catch integrates with Continuous Integration Build Systems may refer to low-level tools, like CMake, or larger systems that run on servers, like Jenkins or TeamCity. This page will talk about both. ## Continuous Integration systems @@ -71,105 +72,31 @@ Catch offers prototypal support for being included in precompiled headers, but b * include "catch.hpp" again -### CMake - -In general we recommend "vendoring" Catch's single-include releases inside your own repository. If you do this, the following example shows a minimal CMake project: -```CMake -cmake_minimum_required(VERSION 3.0) - -project(cmake_test) - -# Prepare "Catch" library for other executables -set(CATCH_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/catch) -add_library(Catch INTERFACE) -target_include_directories(Catch INTERFACE ${CATCH_INCLUDE_DIR}) - -# Make test executable -set(TEST_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/main.cpp) -add_executable(tests ${TEST_SOURCES}) -target_link_libraries(tests Catch) -``` -Note that it assumes that the path to the Catch's header is `catch/catch.hpp` from the `CMakeLists.txt` file. - - -You can also use the following CMake snippet to automatically fetch the entire Catch repository from github and configure it as an external project: -```CMake -cmake_minimum_required(VERSION 2.8.8) -project(catch_builder CXX) -include(ExternalProject) -find_package(Git REQUIRED) - -ExternalProject_Add( - catch - PREFIX ${CMAKE_BINARY_DIR}/catch - GIT_REPOSITORY https://github.com/philsquared/Catch.git - TIMEOUT 10 - UPDATE_COMMAND ${GIT_EXECUTABLE} pull - CONFIGURE_COMMAND "" - BUILD_COMMAND "" - INSTALL_COMMAND "" - LOG_DOWNLOAD ON - ) - -# Expose required variable (CATCH_INCLUDE_DIR) to parent scope -ExternalProject_Get_Property(catch source_dir) -set(CATCH_INCLUDE_DIR ${source_dir}/single_include CACHE INTERNAL "Path to include folder for Catch") -``` - -If you put it in, e.g., `${PROJECT_SRC_DIR}/${EXT_PROJECTS_DIR}/catch/`, you can use it in your project by adding the following to your root CMake file: - -```CMake -# Includes Catch in the project: -add_subdirectory(${EXT_PROJECTS_DIR}/catch) -include_directories(${CATCH_INCLUDE_DIR} ${COMMON_INCLUDES}) -enable_testing(true) # Enables unit-testing. -``` - -The advantage of this approach is that you can always automatically update Catch to the latest release. The disadvantage is that it means bringing in lot more than you need. - - -### Automatic test registration -We provide 2 CMake scripts that can automatically register Catch-based -tests with CTest, - * `contrib/ParseAndAddCatchTests.cmake` - * `contrib/CatchAddTests.cmake` - -The first is based on parsing the test implementation files, and attempts -to register all `TEST_CASE`s using their tags as labels. This means that -these: - -```cpp -TEST_CASE("Test1", "[unit]") { - int a = 1; - int b = 2; - REQUIRE(a == b); -} - -TEST_CASE("Test2") { - int a = 1; - int b = 2; - REQUIRE(a == b); -} - -TEST_CASE("Test3", "[a][b][c]") { - int a = 1; - int b = 2; - REQUIRE(a == b); -} -``` -would be registered as 3 tests, `Test1`, `Test2` and `Test3`, -and 4 CTest labels would be created, `a`, `b`, `c` and `unit`. - - -The second is based on parsing the output of a Catch binary given -`--list-test-names-only`. This means that it deals with inactive -(e.g. commented-out) tests better, but requires CMake 3.10 for full -functionality. - ### CodeCoverage module (GCOV, LCOV...) If you are using GCOV tool to get testing coverage of your code, and are not sure how to integrate it with CMake and Catch, there should be an external example over at https://github.com/fkromer/catch_cmake_coverage + +### pkg-config + +Catch2 provides a rudimentary pkg-config integration, by registering itself +under the name `catch2`. This means that after Catch2 is installed, you +can use `pkg-config` to get its include path: `pkg-config --cflags catch2`. + +### gdb and lldb scripts + +Catch2's `contrib` folder also contains two simple debugger scripts, +`gdbinit` for `gdb` and `lldbinit` for `lldb`. If loaded into their +respective debugger, these will tell it to step over Catch2's internals +when stepping through code. + + +## CMake + +[As it has been getting kinda long, the documentation of Catch2's +integration with CMake has been moved to its own page.](cmake-integration.md#top) + + --- [Home](Readme.md#top) diff --git a/docs/cmake-integration.md b/docs/cmake-integration.md new file mode 100644 index 00000000..7120d163 --- /dev/null +++ b/docs/cmake-integration.md @@ -0,0 +1,185 @@ + +# CMake integration + +Because we use CMake to build Catch2, we also provide a couple of +integration points for our users. + +1) Catch2 exports a (namespaced) CMake target +2) Catch2's repository contains CMake scripts for automatic registration +of `TEST_CASE`s in CTest + +## CMake target + +Catch2's CMake build exports an interface target `Catch2::Catch2`. Linking +against it will add the proper include path and all necessary capabilities +to the resulting binary. + +This means that if Catch2 has been installed on the system, it should be +enough to do: +```cmake +find_package(Catch2 REQUIRED) +target_link_libraries(tests Catch2::Catch2) +``` + + +This target is also provided when Catch2 is used as a subdirectory. +Assuming that Catch2 has been cloned to `lib/Catch2`: +```cmake +add_subdirectory(lib/Catch2) +target_link_libraries(tests Catch2::Catch2) +``` + +## Automatic test registration + +Catch2's repository also contains two CMake scripts that help users +with automatically registering their `TEST_CASE`s with CTest. They +can be found in the `contrib` folder, and are + +1) `Catch.cmake` (and its dependency `CatchAddTests.cmake`) +2) `ParseAndAddCatchTests.cmake` + +If Catch2 has been installed in system, both of these can be used after +doing `find_package(Catch2 REQUIRED)`. Otherwise you need to add them +to your CMake module path. + +### `Catch.cmake` and `AddCatchTests.cmake` + +`Catch.cmake` provides function `catch_discover_tests` to get tests from +a target. This function works by running the resulting executable with +`--list-test-names-only` flag, and then parsing the output to find all +existing tests. + +#### Usage +```cmake +cmake_minimum_required(VERSION 3.5) + +project(baz LANGUAGES CXX VERSION 0.0.1) + +find_package(Catch2 REQUIRED) +add_executable(foo test.cpp) +target_link_libraries(foo Catch2::Catch2) + +include(CTest) +include(Catch) +catch_discover_tests(foo) +``` + + +#### Customization +`catch_discover_tests` can be given several extra argumets: +```cmake +catch_discover_tests(target + [TEST_SPEC arg1...] + [EXTRA_ARGS arg1...] + [WORKING_DIRECTORY dir] + [TEST_PREFIX prefix] + [TEST_SUFFIX suffix] + [PROPERTIES name1 value1...] + [TEST_LIST var] +) +``` + +* `TEST_SPEC arg1...` + +Specifies test cases, wildcarded test cases, tags and tag expressions to +pass to the Catch executable alongside the `--list-test-names-only` flag. + + +* `EXTRA_ARGS arg1...` + +Any extra arguments to pass on the command line to each test case. + + +* `WORKING_DIRECTORY dir` + +Specifies the directory in which to run the discovered test cases. If this +option is not provided, the current binary directory is used. + + +* `TEST_PREFIX prefix` + +Specifies a _prefix_ to be added to the name of each discovered test case. +This can be useful when the same test executable is being used in multiple +calls to `catch_discover_tests()`, with different `TEST_SPEC` or `EXTRA_ARGS`. + + +* `TEST_SUFFIX suffix` + +Same as `TEST_PREFIX`, except it specific the _suffix_ for the test names. +Both `TEST_PREFIX` and `TEST_SUFFIX` can be specified at the same time. + + +* `PROPERTIES name1 value1...` + +Specifies additional properties to be set on all tests discovered by this +invocation of `catch_discover_tests`. + + +* `TEST_LIST var` + +Make the list of tests available in the variable `var`, rather than the +default `_TESTS`. This can be useful when the same test +executable is being used in multiple calls to `catch_discover_tests()`. +Note that this variable is only available in CTest. + + +### `ParseAndAddCatchTests.cmake` + +`ParseAndAddCatchTests` works by parsing all implementation files +associated with the provided target, and registering them via CTest's +`add_test`. This approach has some limitations, such as the fact that +commented-out tests will be registered anyway. + + +#### Usage + +```cmake +cmake_minimum_required(VERSION 3.5) + +project(baz LANGUAGES CXX VERSION 0.0.1) + +find_package(Catch2 REQUIRED) +add_executable(foo test.cpp) +target_link_libraries(foo Catch2::Catch2) + +include(CTest) +include(ParseAndAddCatchTests) +ParseAndAddCatchTests(foo) +``` + + +#### Customization + +`ParseAndAddCatchTests` provides some customization points: +* `PARSE_CATCH_TESTS_VERBOSE` -- When `ON`, the script prints debug +messages. Defaults to `OFF`. +* `PARSE_CATCH_TESTS_NO_HIDDEN_TESTS` -- When `ON`, hidden tests (tests +tagged with any of `[!hide]`, `[.]` or `[.foo]`) will not be registered. +Defaults to `OFF`. +* `PARSE_CATCH_TESTS_ADD_FIXTURE_IN_TEST_NAME` -- When `ON`, adds fixture +class name to the test name in CTest. Defaults to `ON`. +* `PARSE_CATCH_TESTS_ADD_TARGET_IN_TEST_NAME` -- When `ON`, adds target +name to the test name in CTest. Defaults to `ON`. +* `PARSE_CATCH_TESTS_ADD_TO_CONFIGURE_DEPENDS` -- When `ON`, adds test +file to `CMAKE_CONFIGURE_DEPENDS`. This means that the CMake configuration +step will be re-ran when the test files change, letting new tests be +automatically discovered. Defaults to `OFF`. + + +## CMake project options + +Catch2's CMake project also provides some options for other projects +that consume it. These are + +* `CATCH_BUILD_EXAMPLES` -- When `ON`, Catch2's usage examples will be +built. Defaults to `OFF`. +* `CATCH_INSTALL_DOCS` -- When `ON`, Catch2's documentation will be +included in the installation. Defaults to `ON`. +* `CATCH_INSTALL_HELPERS` -- When `ON`, Catch2's contrib folder will be +included in the installation. Defaults to `ON`. +* `BUILD_TESTING` -- When `ON` and the project is not used as a subproject, +Catch2's test binary will be built. Defaults to `ON`. + +--- + +[Home](Readme.md#top) diff --git a/docs/tutorial.md b/docs/tutorial.md index d55355c6..90dd2193 100644 --- a/docs/tutorial.md +++ b/docs/tutorial.md @@ -14,6 +14,9 @@ The simplest way to get Catch2 is to download the latest [single header version](https://raw.githubusercontent.com/CatchOrg/Catch2/master/single_include/catch.hpp). The single header is generated by merging a set of individual headers but it is still just normal source code in a header file. +Alternative ways of getting Catch2 include using your system package +manager, or installing it using its CMake package. + The full source for Catch2, including test projects, documentation, and other things, is hosted on GitHub. [http://catch-lib.net](http://catch-lib.net) will redirect you there. @@ -23,6 +26,9 @@ Catch2 is header only. All you need to do is drop the file somewhere reachable f The rest of this tutorial will assume that the Catch2 single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary. +_If you have installed Catch2 from system package manager, or CMake +package, you need to include the header as `#include `_ + ## Writing tests Let's start with a really simple example ([code](../examples/010-TestCase.cpp)). Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now). 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..7df93d71 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 // ----------------------------------------------------------------------- @@ -187,8 +187,7 @@ void print( std::ostream& os, int const level, std::string const& title, Catch:: void print( std::ostream& os, int const level, std::string const& title, Catch::SectionInfo const& info ) { os << ws(level ) << title << ":\n" - << ws(level+1) << "- name: " << info.name << "\n" - << ws(level+1) << "- description: '" << info.description << "'\n"; + << ws(level+1) << "- name: " << info.name << "\n"; print( os, level+1 , "- lineInfo", info.lineInfo ); } 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/include/catch.hpp b/include/catch.hpp index 0c92ed3a..517dbd3d 100644 --- a/include/catch.hpp +++ b/include/catch.hpp @@ -135,6 +135,7 @@ #define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) #define CATCH_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define CATCH_DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) #define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) #define CATCH_FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) @@ -144,11 +145,11 @@ // "BDD-style" convenience wrappers #define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ ) #define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc ) -#define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc ) -#define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) -#define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc ) -#define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + desc ) +#define CATCH_GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) +#define CATCH_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) +#define CATCH_AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And when: " << desc ) +#define CATCH_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) +#define CATCH_AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) // If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required #else @@ -194,6 +195,7 @@ #define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ ) #define REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ ) #define SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ ) +#define DYNAMIC_SECTION( ... ) INTERNAL_CATCH_DYNAMIC_SECTION( __VA_ARGS__ ) #define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __VA_ARGS__ ) #define FAIL_CHECK( ... ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) #define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ ) @@ -207,15 +209,16 @@ #define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ ) #define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ ) -#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc ) -#define WHEN( desc ) SECTION( std::string(" When: ") + desc ) -#define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc ) -#define THEN( desc ) SECTION( std::string(" Then: ") + desc ) -#define AND_THEN( desc ) SECTION( std::string(" And: ") + desc ) +#define GIVEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Given: " << desc ) +#define WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " When: " << desc ) +#define AND_WHEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( "And when: " << desc ) +#define THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " Then: " << desc ) +#define AND_THEN( desc ) INTERNAL_CATCH_DYNAMIC_SECTION( " And: " << desc ) using Catch::Detail::Approx; -#else +#else // CATCH_CONFIG_DISABLE + ////// // If this config identifier is defined then all CATCH macros are prefixed with CATCH_ #ifdef CATCH_CONFIG_PREFIX_ALL @@ -260,6 +263,7 @@ using Catch::Detail::Approx; #define CATCH_METHOD_AS_TEST_CASE( method, ... ) #define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0) #define CATCH_SECTION( ... ) +#define CATCH_DYNAMIC_SECTION( ... ) #define CATCH_FAIL( ... ) (void)(0) #define CATCH_FAIL_CHECK( ... ) (void)(0) #define CATCH_SUCCEED( ... ) (void)(0) @@ -319,6 +323,7 @@ using Catch::Detail::Approx; #define METHOD_AS_TEST_CASE( method, ... ) #define REGISTER_TEST_CASE( Function, ... ) (void)(0) #define SECTION( ... ) +#define DYNAMIC_SECTION( ... ) #define FAIL( ... ) (void)(0) #define FAIL_CHECK( ... ) (void)(0) #define SUCCEED( ... ) (void)(0) diff --git a/include/internal/catch_random_number_generator.cpp b/include/internal/catch_random_number_generator.cpp index 412faeba..ec8a5eb9 100644 --- a/include/internal/catch_random_number_generator.cpp +++ b/include/internal/catch_random_number_generator.cpp @@ -9,23 +9,21 @@ #include "catch_context.h" #include "catch_interfaces_config.h" -#include - namespace Catch { - void seedRng( IConfig const& config ) { - if( config.rngSeed() != 0 ) - std::srand( config.rngSeed() ); + std::mt19937& rng() { + static std::mt19937 s_rng; + return s_rng; } + + void seedRng( IConfig const& config ) { + if( config.rngSeed() != 0 ) { + std::srand( config.rngSeed() ); + rng().seed( config.rngSeed() ); + } + } + unsigned int rngSeed() { return getCurrentContext().getConfig()->rngSeed(); } - - RandomNumberGenerator::result_type RandomNumberGenerator::operator()( result_type n ) const { - return std::rand() % n; - } - RandomNumberGenerator::result_type RandomNumberGenerator::operator()() const { - return std::rand() % (max)(); - } - } diff --git a/include/internal/catch_random_number_generator.h b/include/internal/catch_random_number_generator.h index d18cffd5..817b7841 100644 --- a/include/internal/catch_random_number_generator.h +++ b/include/internal/catch_random_number_generator.h @@ -8,31 +8,16 @@ #define TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED #include +#include namespace Catch { struct IConfig; + std::mt19937& rng(); void seedRng( IConfig const& config ); - unsigned int rngSeed(); - struct RandomNumberGenerator { - using result_type = unsigned int; - - static constexpr result_type (min)() { return 0; } - static constexpr result_type (max)() { return 1000000; } - - result_type operator()( result_type n ) const; - result_type operator()() const; - - template - static void shuffle( V& vector ) { - RandomNumberGenerator rng; - std::shuffle( vector.begin(), vector.end(), rng ); - } - }; - } #endif // TWOBLUECUBES_CATCH_RANDOM_NUMBER_GENERATOR_H_INCLUDED diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp index 97700bef..73558521 100644 --- a/include/internal/catch_run_context.cpp +++ b/include/internal/catch_run_context.cpp @@ -208,7 +208,7 @@ namespace Catch { // Recreate section for test case (as we will lose the one that was in scope) auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); Counts assertions; assertions.failed = 1; @@ -246,7 +246,7 @@ namespace Catch { void RunContext::runCurrentTest(std::string & redirectedCout, std::string & redirectedCerr) { auto const& testCaseInfo = m_activeTestCase->getTestCaseInfo(); - SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name, testCaseInfo.description); + SectionInfo testCaseSection(testCaseInfo.lineInfo, testCaseInfo.name); m_reporter->sectionStarting(testCaseSection); Counts prevAssertions = m_totals.assertions; double duration = 0; diff --git a/include/internal/catch_section.cpp b/include/internal/catch_section.cpp index 72a57d51..0646d36f 100644 --- a/include/internal/catch_section.cpp +++ b/include/internal/catch_section.cpp @@ -21,7 +21,7 @@ namespace Catch { Section::~Section() { if( m_sectionIncluded ) { - SectionEndInfo endInfo( m_info, m_assertions, m_timer.getElapsedSeconds() ); + SectionEndInfo endInfo{ m_info, m_assertions, m_timer.getElapsedSeconds() }; if( uncaught_exceptions() ) getResultCapture().sectionEndedEarly( endInfo ); else diff --git a/include/internal/catch_section.h b/include/internal/catch_section.h index 1e5b1c3c..562aeef8 100644 --- a/include/internal/catch_section.h +++ b/include/internal/catch_section.h @@ -35,7 +35,10 @@ namespace Catch { } // end namespace Catch - #define INTERNAL_CATCH_SECTION( ... ) \ - if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) +#define INTERNAL_CATCH_SECTION( ... ) \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, __VA_ARGS__ ) ) + +#define INTERNAL_CATCH_DYNAMIC_SECTION( ... ) \ + if( Catch::Section const& INTERNAL_CATCH_UNIQUE_NAME( catch_internal_Section ) = Catch::SectionInfo( CATCH_INTERNAL_LINEINFO, (Catch::ReusableStringStream() << __VA_ARGS__).str() ) ) #endif // TWOBLUECUBES_CATCH_SECTION_H_INCLUDED diff --git a/include/internal/catch_section_info.cpp b/include/internal/catch_section_info.cpp index e2846b8a..89714e35 100644 --- a/include/internal/catch_section_info.cpp +++ b/include/internal/catch_section_info.cpp @@ -11,15 +11,9 @@ namespace Catch { SectionInfo::SectionInfo ( SourceLineInfo const& _lineInfo, - std::string const& _name, - std::string const& _description ) + std::string const& _name ) : name( _name ), - description( _description ), lineInfo( _lineInfo ) {} - SectionEndInfo::SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ) - : sectionInfo( _sectionInfo ), prevAssertions( _prevAssertions ), durationInSeconds( _durationInSeconds ) - {} - } // end namespace Catch diff --git a/include/internal/catch_section_info.h b/include/internal/catch_section_info.h index 86681ba7..9cf792e8 100644 --- a/include/internal/catch_section_info.h +++ b/include/internal/catch_section_info.h @@ -16,19 +16,22 @@ namespace Catch { struct SectionInfo { + SectionInfo + ( SourceLineInfo const& _lineInfo, + std::string const& _name ); + + // Deprecated SectionInfo ( SourceLineInfo const& _lineInfo, std::string const& _name, - std::string const& _description = std::string() ); + std::string const& ) : SectionInfo( _lineInfo, _name ) {} std::string name; - std::string description; + std::string description; // !Deprecated: this will always be empty SourceLineInfo lineInfo; }; struct SectionEndInfo { - SectionEndInfo( SectionInfo const& _sectionInfo, Counts const& _prevAssertions, double _durationInSeconds ); - SectionInfo sectionInfo; Counts prevAssertions; double durationInSeconds; diff --git a/include/internal/catch_test_case_registry_impl.cpp b/include/internal/catch_test_case_registry_impl.cpp index b30b112a..a6b7f570 100644 --- a/include/internal/catch_test_case_registry_impl.cpp +++ b/include/internal/catch_test_case_registry_impl.cpp @@ -28,7 +28,7 @@ namespace Catch { break; case RunTests::InRandomOrder: seedRng( config ); - RandomNumberGenerator::shuffle( sorted ); + std::shuffle( sorted.begin(), sorted.end(), rng() ); break; case RunTests::InDeclarationOrder: // already in declaration order diff --git a/include/internal/catch_test_case_tracker.cpp b/include/internal/catch_test_case_tracker.cpp index 8502b405..c6759438 100644 --- a/include/internal/catch_test_case_tracker.cpp +++ b/include/internal/catch_test_case_tracker.cpp @@ -73,8 +73,8 @@ namespace TestCaseTracking { TrackerBase::TrackerHasName::TrackerHasName( NameAndLocation const& nameAndLocation ) : m_nameAndLocation( nameAndLocation ) {} bool TrackerBase::TrackerHasName::operator ()( ITrackerPtr const& tracker ) const { return - tracker->nameAndLocation().name == m_nameAndLocation.name && - tracker->nameAndLocation().location == m_nameAndLocation.location; + tracker->nameAndLocation().location == m_nameAndLocation.location && + tracker->nameAndLocation().name == m_nameAndLocation.name; } TrackerBase::TrackerBase( NameAndLocation const& nameAndLocation, TrackerContext& ctx, ITracker* parent ) diff --git a/include/reporters/catch_reporter_xml.cpp b/include/reporters/catch_reporter_xml.cpp index b721d449..b6c7d052 100644 --- a/include/reporters/catch_reporter_xml.cpp +++ b/include/reporters/catch_reporter_xml.cpp @@ -80,8 +80,7 @@ namespace Catch { StreamingReporterBase::sectionStarting( sectionInfo ); if( m_sectionDepth++ > 0 ) { m_xml.startElement( "Section" ) - .writeAttribute( "name", trim( sectionInfo.name ) ) - .writeAttribute( "description", sectionInfo.description ); + .writeAttribute( "name", trim( sectionInfo.name ) ); writeSourceInfo( sectionInfo.lineInfo ); m_xml.ensureTagClosed(); } 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/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 24d9b1b7..89db0837 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -988,6 +988,15 @@ Misc.tests.cpp:: passed: l == std::numeric_limits::max() == 9223372036854775807 (0x) Misc.tests.cpp:: failed: b > a for: 0 > 1 +Misc.tests.cpp:: failed: b > a for: 1 > 1 +Misc.tests.cpp:: passed: b > a for: 2 > 1 +Misc.tests.cpp:: passed: b > a for: 3 > 1 +Misc.tests.cpp:: passed: b > a for: 4 > 1 +Misc.tests.cpp:: passed: b > a for: 5 > 1 +Misc.tests.cpp:: passed: b > a for: 6 > 1 +Misc.tests.cpp:: passed: b > a for: 7 > 1 +Misc.tests.cpp:: passed: b > a for: 8 > 1 +Misc.tests.cpp:: passed: b > a for: 9 > 1 Misc.tests.cpp:: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[0] (1) is even' Misc.tests.cpp:: failed: ( fib[i] % 2 ) == 0 for: 1 == 0 with 1 message: 'Testing if fib[1] (1) is even' Misc.tests.cpp:: passed: ( fib[i] % 2 ) == 0 for: 0 == 0 with 1 message: 'Testing if fib[2] (2) is even' @@ -1144,5 +1153,5 @@ Misc.tests.cpp:: passed: v.size() == 5 for: 5 == 5 Misc.tests.cpp:: passed: v.capacity() >= 5 for: 5 >= 5 Misc.tests.cpp:: passed: Misc.tests.cpp:: passed: -Failed 62 test cases, failed 121 assertions. +Failed 62 test cases, failed 122 assertions. diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 1992fb9f..4a2554c2 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -968,7 +968,7 @@ explicitly with message: ------------------------------------------------------------------------------- looped SECTION tests - s1 + b is currently: 0 ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -978,6 +978,18 @@ Misc.tests.cpp:: FAILED: with expansion: 0 > 1 +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 1 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: FAILED: + CHECK( b > a ) +with expansion: + 1 > 1 + ------------------------------------------------------------------------------- looped tests ------------------------------------------------------------------------------- @@ -1028,8 +1040,8 @@ with message: ------------------------------------------------------------------------------- more nested SECTION tests - s1 - s2 + doesn't equal + equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -1085,5 +1097,5 @@ due to unexpected exception with message: =============================================================================== test cases: 208 | 155 passed | 49 failed | 4 failed as expected -assertions: 1065 | 937 passed | 107 failed | 21 failed as expected +assertions: 1074 | 945 passed | 108 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 047c7163..161fa23f 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -4130,7 +4130,7 @@ with expansion: ------------------------------------------------------------------------------- Process can be configured on command line test lists - 1 test + Specify one test case using ------------------------------------------------------------------------------- CmdLine.tests.cpp: ............................................................................... @@ -7754,7 +7754,7 @@ with expansion: ------------------------------------------------------------------------------- looped SECTION tests - s1 + b is currently: 0 ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -7764,6 +7764,122 @@ Misc.tests.cpp:: FAILED: with expansion: 0 > 1 +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 1 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: FAILED: + CHECK( b > a ) +with expansion: + 1 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 2 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 2 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 3 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 3 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 4 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 4 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 5 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 5 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 6 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 6 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 7 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 7 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 8 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 8 > 1 + +------------------------------------------------------------------------------- +looped SECTION tests + b is currently: 9 +------------------------------------------------------------------------------- +Misc.tests.cpp: +............................................................................... + +Misc.tests.cpp:: +PASSED: + CHECK( b > a ) +with expansion: + 9 > 1 + ------------------------------------------------------------------------------- looped tests ------------------------------------------------------------------------------- @@ -7830,8 +7946,8 @@ with message: ------------------------------------------------------------------------------- more nested SECTION tests - s1 - s2 + doesn't equal + equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -7843,8 +7959,8 @@ with expansion: ------------------------------------------------------------------------------- more nested SECTION tests - s1 - s3 + doesn't equal + not equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -7857,8 +7973,8 @@ with expansion: ------------------------------------------------------------------------------- more nested SECTION tests - s1 - s4 + doesn't equal + less than ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -7871,7 +7987,7 @@ with expansion: ------------------------------------------------------------------------------- nested SECTION tests - s1 + doesn't equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -7890,8 +8006,8 @@ with expansion: ------------------------------------------------------------------------------- nested SECTION tests - s1 - s2 + doesn't equal + not equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -7993,7 +8109,7 @@ with expansion: ------------------------------------------------------------------------------- random SECTION tests - s1 + doesn't equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -8012,7 +8128,7 @@ with expansion: ------------------------------------------------------------------------------- random SECTION tests - s2 + not equal ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -8973,7 +9089,9 @@ with expansion: ------------------------------------------------------------------------------- xmlentitycheck - embedded xml + embedded xml: it should be possible to embed xml characters, such as <, + " or &, or even whole documents within an attribute + ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -8983,7 +9101,7 @@ PASSED: ------------------------------------------------------------------------------- xmlentitycheck - encoded chars + encoded chars: these should all be encoded: &&&"""<<<&"<<&" ------------------------------------------------------------------------------- Misc.tests.cpp: ............................................................................... @@ -8993,5 +9111,5 @@ PASSED: =============================================================================== test cases: 208 | 142 passed | 62 failed | 4 failed as expected -assertions: 1079 | 937 passed | 121 failed | 21 failed as expected +assertions: 1088 | 945 passed | 122 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 50c54060..c20b36a5 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -485,7 +485,7 @@ Message.tests.cpp: - + @@ -784,11 +784,24 @@ Message.tests.cpp: - + Misc.tests.cpp: + + +Misc.tests.cpp: + + + + + + + + + + Testing if fib[0] (1) is even @@ -816,16 +829,16 @@ Misc.tests.cpp: - + Misc.tests.cpp: - - + + - - + + @@ -834,8 +847,8 @@ Misc.tests.cpp: - - + + @@ -915,8 +928,8 @@ Exception.tests.cpp: - - + + A string sent directly to stdout Message from section one diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 5452f2fa..43534b18 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -4808,7 +4808,7 @@
-
+
result @@ -8691,7 +8691,7 @@ loose text artifact -
+
b > a @@ -8702,6 +8702,105 @@ loose text artifact
+
+ + + b > a + + + 1 > 1 + + + +
+
+ + + b > a + + + 2 > 1 + + + +
+
+ + + b > a + + + 3 > 1 + + + +
+
+ + + b > a + + + 4 > 1 + + + +
+
+ + + b > a + + + 5 > 1 + + + +
+
+ + + b > a + + + 6 > 1 + + + +
+
+ + + b > a + + + 7 > 1 + + + +
+
+ + + b > a + + + 8 > 1 + + + +
+
+ + + b > a + + + 9 > 1 + + + +
@@ -8796,8 +8895,8 @@ loose text artifact -
-
+
+
a == b @@ -8810,8 +8909,8 @@ loose text artifact
-
-
+
+
a != b @@ -8824,8 +8923,8 @@ loose text artifact
-
-
+
+
a < b @@ -8841,7 +8940,7 @@ loose text artifact -
+
a != b @@ -8858,7 +8957,7 @@ loose text artifact 2 != 1 -
+
a != b @@ -8953,7 +9052,7 @@ loose text artifact -
+
a != b @@ -8972,7 +9071,7 @@ loose text artifact
-
+
a != b @@ -9928,15 +10027,15 @@ loose text artifact -
+
-
+
- + - + diff --git a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp index 1da3fa08..cb635ead 100644 --- a/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp +++ b/projects/SelfTest/IntrospectiveTests/CmdLine.tests.cpp @@ -295,7 +295,7 @@ TEST_CASE( "Process can be configured on command line", "[config][command-line]" } SECTION("test lists") { - SECTION("1 test", "Specify one test case using") { + SECTION("Specify one test case using") { auto result = cli.parse({"test", "test1"}); CHECK(result); diff --git a/projects/SelfTest/UsageTests/Misc.tests.cpp b/projects/SelfTest/UsageTests/Misc.tests.cpp index e5059e9f..820e8019 100644 --- a/projects/SelfTest/UsageTests/Misc.tests.cpp +++ b/projects/SelfTest/UsageTests/Misc.tests.cpp @@ -67,12 +67,12 @@ TEST_CASE( "random SECTION tests", "[.][sections][failing]" ) { int a = 1; int b = 2; - SECTION( "s1", "doesn't equal" ) { + SECTION( "doesn't equal" ) { REQUIRE( a != b ); REQUIRE( b != a ); } - SECTION( "s2", "not equal" ) { + SECTION( "not equal" ) { REQUIRE( a != b); } } @@ -81,11 +81,11 @@ TEST_CASE( "nested SECTION tests", "[.][sections][failing]" ) { int a = 1; int b = 2; - SECTION( "s1", "doesn't equal" ) { + SECTION( "doesn't equal" ) { REQUIRE( a != b ); REQUIRE( b != a ); - SECTION( "s2", "not equal" ) { + SECTION( "not equal" ) { REQUIRE( a != b); } } @@ -95,15 +95,15 @@ TEST_CASE( "more nested SECTION tests", "[sections][failing][.]" ) { int a = 1; int b = 2; - SECTION( "s1", "doesn't equal" ) { - SECTION( "s2", "equal" ) { + SECTION( "doesn't equal" ) { + SECTION( "equal" ) { REQUIRE( a == b ); } - SECTION( "s3", "not equal" ) { + SECTION( "not equal" ) { REQUIRE( a != b ); } - SECTION( "s4", "less than" ) { + SECTION( "less than" ) { REQUIRE( a < b ); } } @@ -112,16 +112,16 @@ TEST_CASE( "more nested SECTION tests", "[sections][failing][.]" ) { TEST_CASE( "even more nested SECTION tests", "[sections]" ) { SECTION( "c" ) { SECTION( "d (leaf)" ) { - SUCCEED(""); // avoid failing due to no tests + SUCCEED(); // avoid failing due to no tests } SECTION( "e (leaf)" ) { - SUCCEED(""); // avoid failing due to no tests + SUCCEED(); // avoid failing due to no tests } } SECTION( "f (leaf)" ) { - SUCCEED(""); // avoid failing due to no tests + SUCCEED(); // avoid failing due to no tests } } @@ -129,9 +129,7 @@ TEST_CASE( "looped SECTION tests", "[.][failing][sections]" ) { int a = 1; for( int b = 0; b < 10; ++b ) { - std::ostringstream oss; - oss << "b is currently: " << b; - SECTION( "s1", oss.str() ) { + DYNAMIC_SECTION( "b is currently: " << b ) { CHECK( b > a ); } } @@ -174,11 +172,11 @@ TEST_CASE( "checkedElse, failing", "[failing][.]" ) { } TEST_CASE( "xmlentitycheck" ) { - SECTION( "embedded xml", "it should be possible to embed xml characters, such as <, \" or &, or even whole documents within an attribute" ) { - SUCCEED(""); // We need this here to stop it failing due to no tests + SECTION( "embedded xml: it should be possible to embed xml characters, such as <, \" or &, or even whole documents within an attribute" ) { + SUCCEED(); // We need this here to stop it failing due to no tests } - SECTION( "encoded chars", "these should all be encoded: &&&\"\"\"<<<&\"<<&\"" ) { - SUCCEED(""); // We need this here to stop it failing due to no tests + SECTION( "encoded chars: these should all be encoded: &&&\"\"\"<<<&\"<<&\"" ) { + SUCCEED(); // We need this here to stop it failing due to no tests } } @@ -265,8 +263,8 @@ TEST_CASE( "vectors can be sized and resized", "[vector]" ) { // https://github.com/philsquared/Catch/issues/166 TEST_CASE("A couple of nested sections followed by a failure", "[failing][.]") { - SECTION("Outer", "") - SECTION("Inner", "") + SECTION("Outer") + SECTION("Inner") SUCCEED("that's not flying - that's failing in style"); FAIL("to infinity and beyond"); @@ -274,7 +272,7 @@ TEST_CASE("A couple of nested sections followed by a failure", "[failing][.]") { TEST_CASE("not allowed", "[!throws]") { // This test case should not be included if you run with -e on the command line - SUCCEED( "" ); + SUCCEED(); } //TEST_CASE( "Is big endian" ) { diff --git a/projects/SelfTest/UsageTests/Tricky.tests.cpp b/projects/SelfTest/UsageTests/Tricky.tests.cpp index 1c352ce9..180ad00e 100644 --- a/projects/SelfTest/UsageTests/Tricky.tests.cpp +++ b/projects/SelfTest/UsageTests/Tricky.tests.cpp @@ -232,28 +232,28 @@ struct is_true TEST_CASE( "(unimplemented) static bools can be evaluated", "[Tricky]" ) { - SECTION("compare to true","") + SECTION("compare to true") { REQUIRE( is_true::value == true ); REQUIRE( true == is_true::value ); } - SECTION("compare to false","") + SECTION("compare to false") { REQUIRE( is_true::value == false ); REQUIRE( false == is_true::value ); } - SECTION("negation", "") + SECTION("negation") { REQUIRE( !is_true::value ); } - SECTION("double negation","") + SECTION("double negation") { REQUIRE( !!is_true::value ); } - SECTION("direct","") + SECTION("direct") { REQUIRE( is_true::value ); REQUIRE_FALSE( is_true::value ); 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/scriptCommon.py b/scripts/scriptCommon.py index 1415be0b..4b70f961 100644 --- a/scripts/scriptCommon.py +++ b/scripts/scriptCommon.py @@ -6,7 +6,7 @@ import subprocess catchPath = os.path.dirname(os.path.realpath( os.path.dirname(sys.argv[0]))) def getBuildExecutable(): - dir = os.environ.get('CATCH_DEV_OUT_DIR', "cmake-build-debug/SelfTest") + dir = os.environ.get('CATCH_DEV_OUT_DIR', "cmake-build-debug/projects/SelfTest") return dir def runAndCapture( args ): 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;