mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Merge branch 'catch2'
This commit is contained in:
commit
46c7c9d3a0
43
.travis.yml
43
.travis.yml
@ -5,19 +5,6 @@ matrix:
|
|||||||
include:
|
include:
|
||||||
|
|
||||||
# 1/ Linux Clang Builds
|
# 1/ Linux Clang Builds
|
||||||
- os: linux
|
|
||||||
compiler: clang
|
|
||||||
addons: &clang34
|
|
||||||
apt:
|
|
||||||
sources: ['llvm-toolchain-precise', 'ubuntu-toolchain-r-test']
|
|
||||||
packages: ['clang']
|
|
||||||
env: COMPILER='clang++' BUILD_TYPE='Release'
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: clang
|
|
||||||
addons: *clang34
|
|
||||||
env: COMPILER='clang++' BUILD_TYPE='Debug'
|
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: clang
|
compiler: clang
|
||||||
addons: &clang35
|
addons: &clang35
|
||||||
@ -75,34 +62,6 @@ matrix:
|
|||||||
|
|
||||||
|
|
||||||
# 2/ Linux GCC Builds
|
# 2/ Linux GCC Builds
|
||||||
- os: linux
|
|
||||||
compiler: gcc
|
|
||||||
addons: &gcc44
|
|
||||||
apt:
|
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
|
||||||
packages: ['g++-4.4']
|
|
||||||
env: COMPILER='g++-4.4' BUILD_TYPE='Release'
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: gcc
|
|
||||||
addons: *gcc44
|
|
||||||
env: COMPILER='g++-4.4' BUILD_TYPE='Debug'
|
|
||||||
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: gcc
|
|
||||||
addons: &gcc47
|
|
||||||
apt:
|
|
||||||
sources: ['ubuntu-toolchain-r-test']
|
|
||||||
packages: ['g++-4.7']
|
|
||||||
env: COMPILER='g++-4.7' BUILD_TYPE='Release'
|
|
||||||
|
|
||||||
- os: linux
|
|
||||||
compiler: gcc
|
|
||||||
addons: *gcc47
|
|
||||||
env: COMPILER='g++-4.7' BUILD_TYPE='Debug'
|
|
||||||
|
|
||||||
|
|
||||||
- os: linux
|
- os: linux
|
||||||
compiler: gcc
|
compiler: gcc
|
||||||
addons: &gcc48
|
addons: &gcc48
|
||||||
@ -191,7 +150,7 @@ matrix:
|
|||||||
addons: *gcc6
|
addons: *gcc6
|
||||||
env: COMPILER='g++-6' BUILD_TYPE='Debug' CPP14=1
|
env: COMPILER='g++-6' BUILD_TYPE='Debug' CPP14=1
|
||||||
|
|
||||||
# 4b/ Linux C++14 Clang builds
|
# # 4b/ Linux C++14 Clang builds
|
||||||
# - os: linux
|
# - os: linux
|
||||||
# compiler: clang
|
# compiler: clang
|
||||||
# addons: *clang38
|
# addons: *clang38
|
||||||
|
235
CMakeLists.txt
235
CMakeLists.txt
@ -9,14 +9,15 @@ set(CATCH_DIR ${CMAKE_CURRENT_SOURCE_DIR})
|
|||||||
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
set(SELF_TEST_DIR ${CATCH_DIR}/projects/SelfTest)
|
||||||
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
|
set(BENCHMARK_DIR ${CATCH_DIR}/projects/Benchmark)
|
||||||
set(HEADER_DIR ${CATCH_DIR}/include)
|
set(HEADER_DIR ${CATCH_DIR}/include)
|
||||||
|
set(CATCH_VERSION_NUMBER 2.0.1)
|
||||||
|
|
||||||
if(USE_CPP11)
|
if(USE_CPP14)
|
||||||
## We can't turn this on by default, since it breaks on travis
|
|
||||||
message(STATUS "Enabling C++11")
|
|
||||||
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
|
||||||
elseif(USE_CPP14)
|
|
||||||
message(STATUS "Enabling C++14")
|
message(STATUS "Enabling C++14")
|
||||||
set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
|
set(CMAKE_CXX_FLAGS "-std=c++14 ${CMAKE_CXX_FLAGS}")
|
||||||
|
else()
|
||||||
|
message(STATUS "Enabling C++11")
|
||||||
|
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||||
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
if(USE_WMAIN)
|
if(USE_WMAIN)
|
||||||
@ -55,6 +56,7 @@ endfunction()
|
|||||||
set(TEST_SOURCES
|
set(TEST_SOURCES
|
||||||
${SELF_TEST_DIR}/ApproxTests.cpp
|
${SELF_TEST_DIR}/ApproxTests.cpp
|
||||||
${SELF_TEST_DIR}/BDDTests.cpp
|
${SELF_TEST_DIR}/BDDTests.cpp
|
||||||
|
${SELF_TEST_DIR}/Benchmark.tests.cpp
|
||||||
${SELF_TEST_DIR}/ClassTests.cpp
|
${SELF_TEST_DIR}/ClassTests.cpp
|
||||||
${SELF_TEST_DIR}/CmdLineTests.cpp
|
${SELF_TEST_DIR}/CmdLineTests.cpp
|
||||||
${SELF_TEST_DIR}/CompilationTests.cpp
|
${SELF_TEST_DIR}/CompilationTests.cpp
|
||||||
@ -62,12 +64,12 @@ set(TEST_SOURCES
|
|||||||
${SELF_TEST_DIR}/DecompositionTests.cpp
|
${SELF_TEST_DIR}/DecompositionTests.cpp
|
||||||
${SELF_TEST_DIR}/EnumToString.cpp
|
${SELF_TEST_DIR}/EnumToString.cpp
|
||||||
${SELF_TEST_DIR}/ExceptionTests.cpp
|
${SELF_TEST_DIR}/ExceptionTests.cpp
|
||||||
${SELF_TEST_DIR}/GeneratorTests.cpp
|
|
||||||
${SELF_TEST_DIR}/MessageTests.cpp
|
${SELF_TEST_DIR}/MessageTests.cpp
|
||||||
${SELF_TEST_DIR}/MiscTests.cpp
|
${SELF_TEST_DIR}/MiscTests.cpp
|
||||||
${SELF_TEST_DIR}/PartTrackerTests.cpp
|
${SELF_TEST_DIR}/PartTrackerTests.cpp
|
||||||
${SELF_TEST_DIR}/TagAliasTests.cpp
|
${SELF_TEST_DIR}/TagAliasTests.cpp
|
||||||
${SELF_TEST_DIR}/TestMain.cpp
|
${SELF_TEST_DIR}/TestMain.cpp
|
||||||
|
${SELF_TEST_DIR}/ToStringChrono.cpp
|
||||||
${SELF_TEST_DIR}/ToStringGeneralTests.cpp
|
${SELF_TEST_DIR}/ToStringGeneralTests.cpp
|
||||||
${SELF_TEST_DIR}/ToStringPair.cpp
|
${SELF_TEST_DIR}/ToStringPair.cpp
|
||||||
${SELF_TEST_DIR}/ToStringTuple.cpp
|
${SELF_TEST_DIR}/ToStringTuple.cpp
|
||||||
@ -76,157 +78,195 @@ set(TEST_SOURCES
|
|||||||
${SELF_TEST_DIR}/TrickyTests.cpp
|
${SELF_TEST_DIR}/TrickyTests.cpp
|
||||||
${SELF_TEST_DIR}/VariadicMacrosTests.cpp
|
${SELF_TEST_DIR}/VariadicMacrosTests.cpp
|
||||||
${SELF_TEST_DIR}/MatchersTests.cpp
|
${SELF_TEST_DIR}/MatchersTests.cpp
|
||||||
|
${SELF_TEST_DIR}/StringRef.tests.cpp
|
||||||
)
|
)
|
||||||
CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
|
CheckFileList(TEST_SOURCES ${SELF_TEST_DIR})
|
||||||
|
|
||||||
# A set of impl files that just #include a single header
|
# A set of impl files that just #include a single header
|
||||||
# Please keep these ordered alphabetically
|
# Please keep these ordered alphabetically
|
||||||
set(IMPL_SOURCES
|
set(SURROGATE_SOURCES
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_common.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_console_colour.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_debugger.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_capture.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_config.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_exception.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_generators.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_registry_hub.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_reporter.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_runner.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_interfaces_testcase.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_message.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_option.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_ptr.cpp
|
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_stream.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_streambuf.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_test_spec.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
|
${SELF_TEST_DIR}/SurrogateCpps/catch_xmlwriter.cpp
|
||||||
${SELF_TEST_DIR}/SurrogateCpps/catch_test_case_tracker.cpp
|
|
||||||
)
|
)
|
||||||
CheckFileList(IMPL_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
|
CheckFileList(SURROGATE_SOURCES ${SELF_TEST_DIR}/SurrogateCpps)
|
||||||
|
|
||||||
|
|
||||||
# Please keep these ordered alphabetically
|
# Please keep these ordered alphabetically
|
||||||
set(TOP_LEVEL_HEADERS
|
set(TOP_LEVEL_HEADERS
|
||||||
${HEADER_DIR}/catch.hpp
|
${HEADER_DIR}/catch.hpp
|
||||||
${HEADER_DIR}/catch_session.hpp
|
|
||||||
${HEADER_DIR}/catch_with_main.hpp
|
${HEADER_DIR}/catch_with_main.hpp
|
||||||
)
|
)
|
||||||
CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
|
CheckFileList(TOP_LEVEL_HEADERS ${HEADER_DIR})
|
||||||
|
|
||||||
# Please keep these ordered alphabetically
|
# Please keep these ordered alphabetically
|
||||||
set(EXTERNAL_HEADERS
|
set(EXTERNAL_HEADERS
|
||||||
${HEADER_DIR}/external/clara.h
|
${HEADER_DIR}/external/clara.hpp
|
||||||
${HEADER_DIR}/external/tbc_text_format.h
|
|
||||||
)
|
)
|
||||||
CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
|
CheckFileList(EXTERNAL_HEADERS ${HEADER_DIR}/external)
|
||||||
|
|
||||||
|
|
||||||
# Please keep these ordered alphabetically
|
# Please keep these ordered alphabetically
|
||||||
set(INTERNAL_HEADERS
|
set(INTERNAL_HEADERS
|
||||||
${HEADER_DIR}/internal/catch_approx.hpp
|
${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_assertionresult.h
|
||||||
${HEADER_DIR}/internal/catch_assertionresult.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_capture.hpp
|
${HEADER_DIR}/internal/catch_capture.hpp
|
||||||
|
${HEADER_DIR}/internal/catch_capture_matchers.h
|
||||||
${HEADER_DIR}/internal/catch_clara.h
|
${HEADER_DIR}/internal/catch_clara.h
|
||||||
${HEADER_DIR}/internal/catch_commandline.hpp
|
${HEADER_DIR}/internal/catch_commandline.h
|
||||||
${HEADER_DIR}/internal/catch_common.h
|
${HEADER_DIR}/internal/catch_common.h
|
||||||
${HEADER_DIR}/internal/catch_common.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_compiler_capabilities.h
|
${HEADER_DIR}/internal/catch_compiler_capabilities.h
|
||||||
${HEADER_DIR}/internal/catch_config.hpp
|
${HEADER_DIR}/internal/catch_config.hpp
|
||||||
${HEADER_DIR}/internal/catch_console_colour.hpp
|
${HEADER_DIR}/internal/catch_console_colour.h
|
||||||
${HEADER_DIR}/internal/catch_console_colour_impl.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_context.h
|
${HEADER_DIR}/internal/catch_context.h
|
||||||
${HEADER_DIR}/internal/catch_context_impl.hpp
|
${HEADER_DIR}/internal/catch_debug_console.h
|
||||||
${HEADER_DIR}/internal/catch_debugger.h
|
${HEADER_DIR}/internal/catch_debugger.h
|
||||||
${HEADER_DIR}/internal/catch_debugger.hpp
|
${HEADER_DIR}/internal/catch_decomposer.h
|
||||||
${HEADER_DIR}/internal/catch_default_main.hpp
|
${HEADER_DIR}/internal/catch_default_main.hpp
|
||||||
${HEADER_DIR}/internal/catch_errno_guard.hpp
|
${HEADER_DIR}/internal/catch_enforce.h
|
||||||
${HEADER_DIR}/internal/catch_evaluate.hpp
|
${HEADER_DIR}/internal/catch_errno_guard.h
|
||||||
${HEADER_DIR}/internal/catch_exception_translator_registry.hpp
|
${HEADER_DIR}/internal/catch_exception_translator_registry.h
|
||||||
${HEADER_DIR}/internal/catch_expression_lhs.hpp
|
${HEADER_DIR}/internal/catch_external_interfaces.h
|
||||||
${HEADER_DIR}/internal/catch_fatal_condition.hpp
|
${HEADER_DIR}/internal/catch_fatal_condition.h
|
||||||
${HEADER_DIR}/internal/catch_generators.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_generators_impl.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_impl.hpp
|
${HEADER_DIR}/internal/catch_impl.hpp
|
||||||
${HEADER_DIR}/internal/catch_interfaces_capture.h
|
${HEADER_DIR}/internal/catch_interfaces_capture.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_config.h
|
${HEADER_DIR}/internal/catch_interfaces_config.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_exception.h
|
${HEADER_DIR}/internal/catch_interfaces_exception.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_generators.h
|
|
||||||
${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
|
${HEADER_DIR}/internal/catch_interfaces_registry_hub.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_reporter.h
|
${HEADER_DIR}/internal/catch_interfaces_reporter.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_runner.h
|
${HEADER_DIR}/internal/catch_interfaces_runner.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
|
${HEADER_DIR}/internal/catch_interfaces_tag_alias_registry.h
|
||||||
${HEADER_DIR}/internal/catch_interfaces_testcase.h
|
${HEADER_DIR}/internal/catch_interfaces_testcase.h
|
||||||
${HEADER_DIR}/internal/catch_legacy_reporter_adapter.h
|
${HEADER_DIR}/internal/catch_leak_detector.h
|
||||||
${HEADER_DIR}/internal/catch_legacy_reporter_adapter.hpp
|
${HEADER_DIR}/internal/catch_list.h
|
||||||
${HEADER_DIR}/internal/catch_list.hpp
|
${HEADER_DIR}/internal/catch_matchers.h
|
||||||
${HEADER_DIR}/internal/catch_matchers.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_matchers_string.h
|
${HEADER_DIR}/internal/catch_matchers_string.h
|
||||||
${HEADER_DIR}/internal/catch_matchers_string.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_matchers_vector.h
|
${HEADER_DIR}/internal/catch_matchers_vector.h
|
||||||
${HEADER_DIR}/internal/catch_message.h
|
${HEADER_DIR}/internal/catch_message.h
|
||||||
${HEADER_DIR}/internal/catch_message.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_notimplemented_exception.h
|
|
||||||
${HEADER_DIR}/internal/catch_notimplemented_exception.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_objc.hpp
|
${HEADER_DIR}/internal/catch_objc.hpp
|
||||||
${HEADER_DIR}/internal/catch_objc_arc.hpp
|
${HEADER_DIR}/internal/catch_objc_arc.hpp
|
||||||
${HEADER_DIR}/internal/catch_option.hpp
|
${HEADER_DIR}/internal/catch_option.hpp
|
||||||
${HEADER_DIR}/internal/catch_platform.h
|
${HEADER_DIR}/internal/catch_platform.h
|
||||||
${HEADER_DIR}/internal/catch_ptr.hpp
|
${HEADER_DIR}/internal/catch_random_number_generator.h
|
||||||
${HEADER_DIR}/internal/catch_reenable_warnings.h
|
${HEADER_DIR}/internal/catch_reenable_warnings.h
|
||||||
${HEADER_DIR}/internal/catch_registry_hub.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_reporter_registrars.hpp
|
${HEADER_DIR}/internal/catch_reporter_registrars.hpp
|
||||||
${HEADER_DIR}/internal/catch_reporter_registry.hpp
|
${HEADER_DIR}/internal/catch_reporter_registry.h
|
||||||
${HEADER_DIR}/internal/catch_result_builder.h
|
|
||||||
${HEADER_DIR}/internal/catch_result_builder.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_result_type.h
|
${HEADER_DIR}/internal/catch_result_type.h
|
||||||
${HEADER_DIR}/internal/catch_run_context.hpp
|
${HEADER_DIR}/internal/catch_run_context.h
|
||||||
|
${HEADER_DIR}/internal/catch_benchmark.h
|
||||||
${HEADER_DIR}/internal/catch_section.h
|
${HEADER_DIR}/internal/catch_section.h
|
||||||
${HEADER_DIR}/internal/catch_section.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_section_info.h
|
${HEADER_DIR}/internal/catch_section_info.h
|
||||||
${HEADER_DIR}/internal/catch_section_info.hpp
|
${HEADER_DIR}/internal/catch_session.h
|
||||||
|
${HEADER_DIR}/internal/catch_startup_exception_registry.h
|
||||||
${HEADER_DIR}/internal/catch_stream.h
|
${HEADER_DIR}/internal/catch_stream.h
|
||||||
${HEADER_DIR}/internal/catch_stream.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_streambuf.h
|
${HEADER_DIR}/internal/catch_streambuf.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_suppress_warnings.h
|
||||||
${HEADER_DIR}/internal/catch_tag_alias.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_tag_alias_registry.h
|
||||||
${HEADER_DIR}/internal/catch_tag_alias_registry.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_test_case_info.h
|
${HEADER_DIR}/internal/catch_test_case_info.h
|
||||||
${HEADER_DIR}/internal/catch_test_case_info.hpp
|
${HEADER_DIR}/internal/catch_test_case_registry_impl.h
|
||||||
${HEADER_DIR}/internal/catch_test_case_registry_impl.hpp
|
${HEADER_DIR}/internal/catch_test_case_tracker.h
|
||||||
${HEADER_DIR}/internal/catch_test_case_tracker.hpp
|
${HEADER_DIR}/internal/catch_test_registry.h
|
||||||
${HEADER_DIR}/internal/catch_test_registry.hpp
|
${HEADER_DIR}/internal/catch_test_spec.h
|
||||||
${HEADER_DIR}/internal/catch_test_spec.hpp
|
${HEADER_DIR}/internal/catch_test_spec_parser.h
|
||||||
${HEADER_DIR}/internal/catch_test_spec_parser.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_text.h
|
${HEADER_DIR}/internal/catch_text.h
|
||||||
${HEADER_DIR}/internal/catch_timer.h
|
${HEADER_DIR}/internal/catch_timer.h
|
||||||
${HEADER_DIR}/internal/catch_timer.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_tostring.h
|
${HEADER_DIR}/internal/catch_tostring.h
|
||||||
${HEADER_DIR}/internal/catch_tostring.hpp
|
${HEADER_DIR}/internal/catch_totals.h
|
||||||
${HEADER_DIR}/internal/catch_totals.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_type_traits.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_version.h
|
${HEADER_DIR}/internal/catch_version.h
|
||||||
${HEADER_DIR}/internal/catch_version.hpp
|
${HEADER_DIR}/internal/catch_wildcard_pattern.h
|
||||||
${HEADER_DIR}/internal/catch_wildcard_pattern.hpp
|
|
||||||
${HEADER_DIR}/internal/catch_windows_h_proxy.h
|
${HEADER_DIR}/internal/catch_windows_h_proxy.h
|
||||||
${HEADER_DIR}/internal/catch_xmlwriter.hpp
|
${HEADER_DIR}/internal/catch_xmlwriter.h
|
||||||
)
|
)
|
||||||
CheckFileList(INTERNAL_HEADERS ${HEADER_DIR}/internal)
|
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_string.cpp
|
||||||
|
${HEADER_DIR}/internal/catch_message.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_streambuf.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_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
|
# Please keep these ordered alphabetically
|
||||||
set(REPORTER_HEADERS
|
set(REPORTER_HEADERS
|
||||||
${HEADER_DIR}/reporters/catch_reporter_automake.hpp
|
${HEADER_DIR}/reporters/catch_reporter_automake.hpp
|
||||||
${HEADER_DIR}/reporters/catch_reporter_bases.hpp
|
${HEADER_DIR}/reporters/catch_reporter_bases.hpp
|
||||||
${HEADER_DIR}/reporters/catch_reporter_compact.hpp
|
${HEADER_DIR}/reporters/catch_reporter_multi.h
|
||||||
${HEADER_DIR}/reporters/catch_reporter_console.hpp
|
|
||||||
${HEADER_DIR}/reporters/catch_reporter_junit.hpp
|
|
||||||
${HEADER_DIR}/reporters/catch_reporter_multi.hpp
|
|
||||||
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
|
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
|
||||||
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
|
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
|
||||||
${HEADER_DIR}/reporters/catch_reporter_xml.hpp
|
|
||||||
)
|
)
|
||||||
CheckFileList(REPORTER_HEADERS ${HEADER_DIR}/reporters)
|
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_multi.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
|
# Specify the headers, too, so CLion recognises them as project files
|
||||||
set(HEADERS
|
set(HEADERS
|
||||||
@ -236,17 +276,9 @@ set(HEADERS
|
|||||||
${REPORTER_HEADERS}
|
${REPORTER_HEADERS}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
set(BENCH_SOURCES
|
|
||||||
${BENCHMARK_DIR}/BenchMain.cpp
|
|
||||||
${BENCHMARK_DIR}/StringificationBench.cpp
|
|
||||||
)
|
|
||||||
CheckFileList(BENCH_SOURCES ${BENCHMARK_DIR})
|
|
||||||
|
|
||||||
# Provide some groupings for IDEs
|
# Provide some groupings for IDEs
|
||||||
SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
|
SOURCE_GROUP("Tests" FILES ${TEST_SOURCES})
|
||||||
SOURCE_GROUP("Surrogates" FILES ${IMPL_SOURCES})
|
SOURCE_GROUP("Surrogates" FILES ${SURROGATE_SOURCES})
|
||||||
SOURCE_GROUP("Benchmarks" FILES ${BENCH_SOURCES})
|
|
||||||
|
|
||||||
# configure the executable
|
# configure the executable
|
||||||
include_directories(${HEADER_DIR})
|
include_directories(${HEADER_DIR})
|
||||||
@ -254,17 +286,19 @@ include_directories(${HEADER_DIR})
|
|||||||
# Projects consuming Catch via ExternalProject_Add might want to use install step
|
# Projects consuming Catch via ExternalProject_Add might want to use install step
|
||||||
# without building all of our selftests.
|
# without building all of our selftests.
|
||||||
if (NOT NO_SELFTEST)
|
if (NOT NO_SELFTEST)
|
||||||
add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${HEADERS})
|
add_executable(SelfTest ${TEST_SOURCES} ${IMPL_SOURCES} ${REPORTER_SOURCES} ${SURROGATE_SOURCES} ${HEADERS})
|
||||||
add_executable(Benchmark ${BENCH_SOURCES} ${HEADERS})
|
|
||||||
|
|
||||||
# Add desired warnings
|
# Add desired warnings
|
||||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang|AppleClang|GNU" )
|
||||||
target_compile_options( SelfTest PRIVATE -Wall -Wextra )
|
target_compile_options( SelfTest PRIVATE -Wall -Wextra -Wunreachable-code )
|
||||||
target_compile_options( Benchmark PRIVATE -Wall -Wextra )
|
endif()
|
||||||
|
# Clang specific warning go here
|
||||||
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "Clang" )
|
||||||
|
# Actually keep these
|
||||||
|
target_compile_options( SelfTest PRIVATE -Wweak-vtables -Wexit-time-destructors -Wglobal-constructors -Wmissing-noreturn )
|
||||||
endif()
|
endif()
|
||||||
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
if ( CMAKE_CXX_COMPILER_ID MATCHES "MSVC" )
|
||||||
target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX )
|
target_compile_options( SelfTest PRIVATE /W4 /w44265 /WX /w44061 /w44062 )
|
||||||
target_compile_options( Benchmark PRIVATE /W4 )
|
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
@ -278,7 +312,24 @@ if (NOT NO_SELFTEST)
|
|||||||
add_test(NAME ListTags COMMAND SelfTest --list-tags)
|
add_test(NAME ListTags COMMAND SelfTest --list-tags)
|
||||||
set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
|
set_tests_properties(ListTags PROPERTIES PASS_REGULAR_EXPRESSION "[0-9]+ tags")
|
||||||
|
|
||||||
|
# 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 $<TARGET_FILE:SelfTest>)
|
||||||
|
set_tests_properties(ApprovalTests PROPERTIES FAIL_REGULAR_EXPRESSION "Results differed")
|
||||||
endif() # !NO_SELFTEST
|
endif() # !NO_SELFTEST
|
||||||
|
|
||||||
|
|
||||||
install(DIRECTORY "single_include/" DESTINATION "include/catch")
|
install(DIRECTORY "single_include/" DESTINATION "include/catch")
|
||||||
|
|
||||||
|
## 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_PREFIX}/share/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()
|
||||||
|
26
README.md
26
README.md
@ -1,28 +1,28 @@
|
|||||||
|
<a id="top"></a>
|
||||||
![catch logo](catch-logo-small.png)
|
![catch logo](catch-logo-small.png)
|
||||||
|
|
||||||
[![Github Releases](https://img.shields.io/github/release/philsquared/catch.svg)](https://github.com/philsquared/catch/releases)
|
[![Github Releases](https://img.shields.io/github/release/philsquared/catch.svg)](https://github.com/philsquared/catch/releases)
|
||||||
[![Build Status](https://travis-ci.org/philsquared/Catch.svg?branch=master)](https://travis-ci.org/philsquared/Catch)
|
[![Build Status](https://travis-ci.org/philsquared/Catch.svg?branch=catch2)](https://travis-ci.org/philsquared/Catch?branch=catch2)
|
||||||
[![Build status](https://ci.appveyor.com/api/projects/status/hrtk60hv6tw6fght/branch/master?svg=true)](https://ci.appveyor.com/project/philsquared/catch/branch/master)
|
[![Build status](https://ci.appveyor.com/api/projects/status/hrtk60hv6tw6fght/branch/catch2?svg=true)](https://ci.appveyor.com/project/philsquared/catch/branch/catch2)
|
||||||
[![Try online](https://img.shields.io/badge/try-online-blue.svg)](https://wandbox.org/permlink/EyEbEIfp8CnnjguW)
|
|
||||||
|
|
||||||
<a href="https://github.com/philsquared/Catch/releases/download/v1.11.0/catch.hpp">The latest, single header, version can be downloaded directly using this link</a>
|
<a href="https://github.com/philsquared/Catch/releases/download/v2.0.0-develop.6/catch.hpp">The latest version of the single header can be downloaded directly using this link</a>
|
||||||
|
|
||||||
## What's the Catch?
|
## What's the Catch?
|
||||||
|
|
||||||
Catch stands for C++ Automated Test Cases in Headers and is a multi-paradigm automated test framework for C++ and Objective-C (and, maybe, C). It is implemented entirely in a set of header files, but is packaged up as a single header for extra convenience.
|
Catch stands for C++ Automated Test Cases in Headers and is a
|
||||||
|
multi-paradigm test framework for C++. which also supports Objective-C
|
||||||
|
and, maybe, C.
|
||||||
|
It is primarily distributed as a single header file, although certain
|
||||||
|
extensions may require additional headers.
|
||||||
|
|
||||||
## How to use it
|
## How to use it
|
||||||
This documentation comprises these three parts:
|
This documentation comprises these three parts:
|
||||||
|
|
||||||
* [Why do we need yet another C++ Test Framework?](docs/why-catch.md)
|
* [Why do we need yet another C++ Test Framework?](docs/why-catch.md#top)
|
||||||
* [Tutorial](docs/tutorial.md) - getting started
|
* [Tutorial](docs/tutorial.md#top) - getting started
|
||||||
* [Reference section](docs/Readme.md) - all the details
|
* [Reference section](docs/Readme.md#top) - all the details
|
||||||
|
|
||||||
## More
|
## More
|
||||||
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/philsquared/Catch/issues)
|
* Issues and bugs can be raised on the [Issue tracker on GitHub](https://github.com/philsquared/Catch/issues)
|
||||||
* For discussion or questions please use [the dedicated Google Groups forum](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)
|
* For discussion or questions please use [the dedicated Google Groups forum](https://groups.google.com/forum/?fromgroups#!forum/catch-forum)
|
||||||
* See [who else is using Catch](docs/opensource-users.md)
|
* See [who else is using Catch](docs/opensource-users.md#top)
|
||||||
|
|
||||||
## Help us out
|
|
||||||
We're currently running [a survey](https://www.surveymonkey.co.uk/r/TLLYQJW) to help us shape the future of Catch.
|
|
||||||
Please take a few moments to fill it out (there's only ten questions).
|
|
||||||
|
@ -4,7 +4,6 @@ version: "{build}"
|
|||||||
os:
|
os:
|
||||||
- Visual Studio 2017
|
- Visual Studio 2017
|
||||||
- Visual Studio 2015
|
- Visual Studio 2015
|
||||||
- Visual Studio 2013
|
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
matrix:
|
matrix:
|
||||||
|
9
catch.pc.in
Normal file
9
catch.pc.in
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
prefix=@CMAKE_INSTALL_PREFIX@
|
||||||
|
exec_prefix=${prefix}
|
||||||
|
|
||||||
|
Name: Catch
|
||||||
|
Description: Testing library for C++
|
||||||
|
Requires:
|
||||||
|
Version: @CATCH_VERSION_NUMBER@
|
||||||
|
Libs:
|
||||||
|
Cflags: -I${prefix}/@INCLUDE_INSTALL_DIR@/include
|
@ -4,7 +4,7 @@ from conans import ConanFile
|
|||||||
|
|
||||||
class CatchConan(ConanFile):
|
class CatchConan(ConanFile):
|
||||||
name = "Catch"
|
name = "Catch"
|
||||||
version = "1.11.0"
|
version = "2.0.1"
|
||||||
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
|
description = "A modern, C++-native, header-only, framework for unit-tests, TDD and BDD"
|
||||||
author = "philsquared"
|
author = "philsquared"
|
||||||
generators = "cmake"
|
generators = "cmake"
|
||||||
|
@ -1,30 +1,33 @@
|
|||||||
To get the most out of Catch, start with the [tutorial](tutorial.md).
|
<a id="top"></a>
|
||||||
|
# Reference
|
||||||
|
|
||||||
|
To get the most out of Catch, start with the [tutorial](tutorial.md#top).
|
||||||
Once you're up and running consider the following reference material.
|
Once you're up and running consider the following reference material.
|
||||||
|
|
||||||
Writing tests:
|
Writing tests:
|
||||||
* [Assertion macros](assertions.md)
|
* [Assertion macros](assertions.md#top)
|
||||||
* [Matchers](matchers.md)
|
* [Matchers](matchers.md#top)
|
||||||
* [Logging macros](logging.md)
|
* [Logging macros](logging.md#top)
|
||||||
* [Test cases and sections](test-cases-and-sections.md)
|
* [Test cases and sections](test-cases-and-sections.md#top)
|
||||||
* [Test fixtures](test-fixtures.md)
|
* [Test fixtures](test-fixtures.md#top)
|
||||||
* [Reporters](reporters.md)
|
* [Reporters](reporters.md#top)
|
||||||
* [Event Listeners](event-listeners.md)
|
* [Event Listeners](event-listeners.md#top)
|
||||||
|
|
||||||
Fine tuning:
|
Fine tuning:
|
||||||
* [Supplying your own main()](own-main.md)
|
* [Supplying your own main()](own-main.md#top)
|
||||||
* [Compile-time configuration](configuration.md)
|
* [Compile-time configuration](configuration.md#top)
|
||||||
* [String Conversions](tostring.md)
|
* [String Conversions](tostring.md#top)
|
||||||
|
|
||||||
Running:
|
Running:
|
||||||
* [Command line](command-line.md)
|
* [Command line](command-line.md#top)
|
||||||
* [CI and Build system integration](build-systems.md)
|
* [CI and Build system integration](build-systems.md#top)
|
||||||
|
|
||||||
FAQ:
|
FAQ:
|
||||||
* [Why are my tests slow to compile?](slow-compiles.md)
|
* [Why are my tests slow to compile?](slow-compiles.md#top)
|
||||||
* [Known limitations](limitations.md)
|
* [Known limitations](limitations.md#top)
|
||||||
|
|
||||||
Other:
|
Other:
|
||||||
* [Why Catch?](why-catch.md)
|
* [Why Catch?](why-catch.md#top)
|
||||||
* [Open Source Projects using Catch](opensource-users.md)
|
* [Open Source Projects using Catch](opensource-users.md#top)
|
||||||
* [Contributing](contributing.md)
|
* [Contributing](contributing.md#top)
|
||||||
* [Release Notes](release-notes.md)
|
* [Release Notes](release-notes.md#top)
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Assertion Macros
|
# Assertion Macros
|
||||||
|
|
||||||
|
**Contents**<br>
|
||||||
|
[Natural Expressions](#natural-expressions)<br>
|
||||||
|
[Exceptions](#exceptions)<br>
|
||||||
|
[Matcher expressions](#matcher-expressions)<br>
|
||||||
|
[Thread Safety](#thread-safety)<br>
|
||||||
|
|
||||||
Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (```_EQUALS```, ```_NOTEQUALS```, ```_GREATER_THAN``` etc).
|
Most test frameworks have a large collection of assertion macros to capture all possible conditional forms (```_EQUALS```, ```_NOTEQUALS```, ```_GREATER_THAN``` etc).
|
||||||
|
|
||||||
Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there are a rich set of auxilliary macros as well. We'll describe all of these here.
|
Catch is different. Because it decomposes natural C-style conditional expressions most of these forms are reduced to one or two that you will use all the time. That said there are a rich set of auxilliary macros as well. We'll describe all of these here.
|
||||||
@ -57,7 +64,7 @@ This way `Approx` is constructed with reasonable defaults, covering most simple
|
|||||||
|
|
||||||
* __epsilon__ - epsilon serves to set the percentage by which a result can be erroneous, before it is rejected. By default set to `std::numeric_limits<float>::epsilon()*100`.
|
* __epsilon__ - epsilon serves to set the percentage by which a result can be erroneous, before it is rejected. By default set to `std::numeric_limits<float>::epsilon()*100`.
|
||||||
* __margin__ - margin serves to set the the absolute value by which a result can be erroneous before it is rejected. By default set to `0.0`.
|
* __margin__ - margin serves to set the the absolute value by which a result can be erroneous before it is rejected. By default set to `0.0`.
|
||||||
* __scale__ - scale serves to adjust the base for comparison used by epsilon. By default set to `1.0`.
|
* __scale__ - scale serves to adjust the epsilon's multiplicator. By default set to `0.0`.
|
||||||
|
|
||||||
#### epsilon example
|
#### epsilon example
|
||||||
```cpp
|
```cpp
|
||||||
@ -77,7 +84,12 @@ Approx target = Approx(100).margin(5);
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### scale
|
#### scale
|
||||||
Scale can be useful if the computation leading to the result worked on different scale, than is used by the results (and thus expected errors are on a different scale than would be expected based on the results alone), i.e. an additional not scaling difference will be accepted, because | current - target | < eps_rel + eps_abs (while eps_rel = max(current, target) * epsilon, eps_abs = epsilon * scale) will be checked.
|
Scale can be useful if the computation leading to the result worked
|
||||||
|
on different scale than is used by the results. Since allowed difference
|
||||||
|
between Approx's value and compared value is based primarily on Approx's value
|
||||||
|
(the allowed difference is computed as
|
||||||
|
`(Approx::scale + Approx::value) * epsilon`), the resulting comparison could
|
||||||
|
need rescaling to be correct.
|
||||||
|
|
||||||
|
|
||||||
## Exceptions
|
## Exceptions
|
||||||
@ -95,7 +107,7 @@ Expects that an exception (of any type) is be thrown during evaluation of the ex
|
|||||||
* **REQUIRE_THROWS_AS(** _expression_, _exception type_ **)** and
|
* **REQUIRE_THROWS_AS(** _expression_, _exception type_ **)** and
|
||||||
* **CHECK_THROWS_AS(** _expression_, _exception type_ **)**
|
* **CHECK_THROWS_AS(** _expression_, _exception type_ **)**
|
||||||
|
|
||||||
Expects that an exception of the _specified type_ is thrown during evaluation of the expression. Note that the _exception type_ is used verbatim and you should include (const) reference.
|
Expects that an exception of the _specified type_ is thrown during evaluation of the expression. Note that the _exception type_ is extended with `const&` and you should not include it yourself.
|
||||||
|
|
||||||
* **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and
|
* **REQUIRE_THROWS_WITH(** _expression_, _string or string matcher_ **)** and
|
||||||
* **CHECK_THROWS_WITH(** _expression_, _string or string matcher_ **)**
|
* **CHECK_THROWS_WITH(** _expression_, _string or string matcher_ **)**
|
||||||
@ -108,8 +120,13 @@ REQUIRE_THROWS_WITH( openThePodBayDoors(), Contains( "afraid" ) && Contains( "ca
|
|||||||
REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
|
REQUIRE_THROWS_WITH( dismantleHal(), "My mind is going" );
|
||||||
```
|
```
|
||||||
|
|
||||||
|
* **REQUIRE_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)** and
|
||||||
|
* **CHECK_THROWS_MATCHES(** _expression_, _exception type_, _matcher for given exception type_ **)**
|
||||||
|
|
||||||
Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function.
|
Expects that exception of _exception type_ is thrown and it matches provided matcher (see next section for Matchers).
|
||||||
|
|
||||||
|
|
||||||
|
_Please note that the `THROW` family of assertions expects to be passed a single expression, not a statement or series of statements. If you want to check a more complicated sequence of operations, you can use a C++11 lambda function._
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
REQUIRE_NOTHROW([&](){
|
REQUIRE_NOTHROW([&](){
|
||||||
@ -122,9 +139,11 @@ REQUIRE_NOTHROW([&](){
|
|||||||
}());
|
}());
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## Matcher expressions
|
## Matcher expressions
|
||||||
|
|
||||||
To support Matchers a slightly different form is used. Matchers have [their own documentation](matchers.md).
|
To support Matchers a slightly different form is used. Matchers have [their own documentation](matchers.md#top).
|
||||||
|
|
||||||
* **REQUIRE_THAT(** _lhs_, _matcher expression_ **)** and
|
* **REQUIRE_THAT(** _lhs_, _matcher expression_ **)** and
|
||||||
* **CHECK_THAT(** _lhs_, _matcher expression_ **)**
|
* **CHECK_THAT(** _lhs_, _matcher expression_ **)**
|
||||||
@ -138,4 +157,4 @@ For more details, along with workarounds, see the section on [the limitations pa
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# CI and build system integration
|
# CI and build system 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.
|
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
|
## Continuous Integration systems
|
||||||
|
|
||||||
Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP and Automake reporters).
|
Probably the most important aspect to using Catch with a build server is the use of different reporters. Catch comes bundled with three reporters that should cover the majority of build servers out there - although adding more for better integration with some is always a possibility (currently we also offer TeamCity, TAP and Automake reporters).
|
||||||
|
|
||||||
Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them.
|
Two of these reporters are built in (XML and JUnit) and the third (TeamCity) is included as a separate header. It's possible that the other two may be split out in the future too - as that would make the core of Catch smaller for those that don't need them.
|
||||||
|
|
||||||
## XML Reporter
|
### XML Reporter
|
||||||
```-r xml```
|
```-r xml```
|
||||||
|
|
||||||
The XML Reporter writes in an XML format that is specific to Catch.
|
The XML Reporter writes in an XML format that is specific to Catch.
|
||||||
@ -17,7 +18,7 @@ The advantage of this format is that it corresponds well to the way Catch works
|
|||||||
|
|
||||||
The disadvantage is that, being specific to Catch, no existing build servers understand the format natively. It can be used as input to an XSLT transformation that could convert it to, say, HTML - although this loses the streaming advantage, of course.
|
The disadvantage is that, being specific to Catch, no existing build servers understand the format natively. It can be used as input to an XSLT transformation that could convert it to, say, HTML - although this loses the streaming advantage, of course.
|
||||||
|
|
||||||
## JUnit Reporter
|
### JUnit Reporter
|
||||||
```-r junit```
|
```-r junit```
|
||||||
|
|
||||||
The JUnit Reporter writes in an XML format that mimics the JUnit ANT schema.
|
The JUnit Reporter writes in an XML format that mimics the JUnit ANT schema.
|
||||||
@ -52,9 +53,9 @@ The Automake Reporter writes out the [meta tags](https://www.gnu.org/software/au
|
|||||||
|
|
||||||
Because of the incremental nature of Catch's test suites and ability to run specific tests, our implementation of TAP reporter writes out the number of tests in a suite last.
|
Because of the incremental nature of Catch's test suites and ability to run specific tests, our implementation of TAP reporter writes out the number of tests in a suite last.
|
||||||
|
|
||||||
# Low-level tools
|
## Low-level tools
|
||||||
|
|
||||||
## CMake
|
### 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:
|
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
|
||||||
@ -140,4 +141,4 @@ If you are using GCOV tool to get testing coverage of your code, and are not sur
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,30 @@
|
|||||||
|
<a id="top"></a>
|
||||||
|
# Command line
|
||||||
|
|
||||||
|
**Contents**<br>
|
||||||
|
[Specifying which tests to run](#specifying-which-tests-to-run)<br>
|
||||||
|
[Choosing a reporter to use](#choosing-a-reporter-to-use)<br>
|
||||||
|
[Breaking into the debugger](#breaking-into-the-debugger)<br>
|
||||||
|
[Showing results for successful tests](#showing-results-for-successful-tests)<br>
|
||||||
|
[Aborting after a certain number of failures](#aborting-after-a-certain-number-of-failures)<br>
|
||||||
|
[Listing available tests, tags or reporters](#listing-available-tests-tags-or-reporters)<br>
|
||||||
|
[Sending output to a file](#sending-output-to-a-file)<br>
|
||||||
|
[Naming a test run](#naming-a-test-run)<br>
|
||||||
|
[Eliding assertions expected to throw](#eliding-assertions-expected-to-throw)<br>
|
||||||
|
[Make whitespace visible](#make-whitespace-visible)<br>
|
||||||
|
[Warnings](#warnings)<br>
|
||||||
|
[Reporting timings](#reporting-timings)<br>
|
||||||
|
[Load test names to run from a file](#load-test-names-to-run-from-a-file)<br>
|
||||||
|
[Just test names](#just-test-names)<br>
|
||||||
|
[Specify the order test cases are run](#specify-the-order-test-cases-are-run)<br>
|
||||||
|
[Specify a seed for the Random Number Generator](#specify-a-seed-for-the-random-number-generator)<br>
|
||||||
|
[Identify framework and version according to the libIdentify standard](#identify-framework-and-version-according-to-the-libidentify-standard)<br>
|
||||||
|
[Wait for key before continuing](#wait-for-key-before-continuing)<br>
|
||||||
|
[Specify multiples of clock resolution to run benchmarks for](#specify-multiples-of-clock-resolution-to-run-benchmarks-for)<br>
|
||||||
|
[Usage](#usage)<br>
|
||||||
|
[Specify the section to run](#specify-the-section-to-run)<br>
|
||||||
|
[Filenames as tags](#filenames-as-tags)<br>
|
||||||
|
|
||||||
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
|
Catch works quite nicely without any command line options at all - but for those times when you want greater control the following options are available.
|
||||||
Click one of the followings links to take you straight to that option - or scroll on to browse the available options.
|
Click one of the followings links to take you straight to that option - or scroll on to browse the available options.
|
||||||
|
|
||||||
@ -29,6 +56,7 @@ Click one of the followings links to take you straight to that option - or scrol
|
|||||||
<a href="#rng-seed"> ` --rng-seed`</a><br />
|
<a href="#rng-seed"> ` --rng-seed`</a><br />
|
||||||
<a href="#libidentify"> ` --libidentify`</a><br />
|
<a href="#libidentify"> ` --libidentify`</a><br />
|
||||||
<a href="#wait-for-keypress"> ` --wait-for-keypress`</a><br />
|
<a href="#wait-for-keypress"> ` --wait-for-keypress`</a><br />
|
||||||
|
<a href="#benchmark-resolution-multiple"> ` --benchmark-resolution-multiple`</a><br />
|
||||||
|
|
||||||
</br>
|
</br>
|
||||||
|
|
||||||
@ -228,6 +256,13 @@ See [The LibIdentify repo for more information and examples](https://github.com/
|
|||||||
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing -
|
Will cause the executable to print a message and wait until the return/ enter key is pressed before continuing -
|
||||||
either before running any tests, after running all tests - or both, depending on the argument.
|
either before running any tests, after running all tests - or both, depending on the argument.
|
||||||
|
|
||||||
|
<a id="benchmark-resolution-multiple"></a>
|
||||||
|
## Specify multiples of clock resolution to run benchmarks for
|
||||||
|
<pre>--benchmark-resolution-multiple <multiplier></pre>
|
||||||
|
|
||||||
|
When running benchmarks the clock resolution is estimated. Benchmarks are then run for exponentially increasing
|
||||||
|
numbers of iterations until some multiple of the estimated resolution is exceed. By default that multiple is 100, but
|
||||||
|
it can be overriden here.
|
||||||
|
|
||||||
<a id="usage"></a>
|
<a id="usage"></a>
|
||||||
## Usage
|
## Usage
|
||||||
@ -290,4 +325,4 @@ So, for example, tests within the file `~\Dev\MyProject\Ferrets.cpp` would be t
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Commercial users of Catch
|
# Commercial users of Catch
|
||||||
|
|
||||||
As well as [Open Source](opensource-users.md) users Catch is widely used within proprietary code bases too.
|
As well as [Open Source](opensource-users.md#top) users Catch is widely used within proprietary code bases too.
|
||||||
Many organisations like to keep this information internal, and that's fine,
|
Many organisations like to keep this information internal, and that's fine,
|
||||||
but if you're more open it would be great if we could list the names of as
|
but if you're more open it would be great if we could list the names of as
|
||||||
many organisations as possible that use Catch somewhere in their codebase.
|
many organisations as possible that use Catch somewhere in their codebase.
|
||||||
|
@ -1,22 +1,43 @@
|
|||||||
|
<a id="top"></a>
|
||||||
|
# Compile-time configuration
|
||||||
|
|
||||||
|
**Contents**<br>
|
||||||
|
[main()/ implementation](#main-implementation)<br>
|
||||||
|
[Prefixing Catch macros](#prefixing-catch-macros)<br>
|
||||||
|
[Terminal colour](#terminal-colour)<br>
|
||||||
|
[Console width](#console-width)<br>
|
||||||
|
[stdout](#stdout)<br>
|
||||||
|
[Other toggles](#other-toggles)<br>
|
||||||
|
[Windows header clutter](#windows-header-clutter)<br>
|
||||||
|
[Enabling stringification](#enabling-stringification)<br>
|
||||||
|
|
||||||
Catch is designed to "just work" as much as possible. For most people the only configuration needed is telling Catch which source file should host all the implementation code (```CATCH_CONFIG_MAIN```).
|
Catch is designed to "just work" as much as possible. For most people the only configuration needed is telling Catch which source file should host all the implementation code (```CATCH_CONFIG_MAIN```).
|
||||||
|
|
||||||
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
|
Nonetheless there are still some occasions where finer control is needed. For these occasions Catch exposes a set of macros for configuring how it is built.
|
||||||
|
|
||||||
# main()/ implementation
|
## main()/ implementation
|
||||||
|
|
||||||
CATCH_CONFIG_MAIN // Designates this as implementation file and defines main()
|
CATCH_CONFIG_MAIN // Designates this as implementation file and defines main()
|
||||||
CATCH_CONFIG_RUNNER // Designates this as implementation file
|
CATCH_CONFIG_RUNNER // Designates this as implementation file
|
||||||
|
|
||||||
Although Catch is header only it still, internally, maintains a distinction between interface headers and headers that contain implementation. Only one source file in your test project should compile the implementation headers and this is controlled through the use of one of these macros - one of these identifiers should be defined before including Catch in *exactly one implementation file in your project*.
|
Although Catch is header only it still, internally, maintains a distinction between interface headers and headers that contain implementation. Only one source file in your test project should compile the implementation headers and this is controlled through the use of one of these macros - one of these identifiers should be defined before including Catch in *exactly one implementation file in your project*.
|
||||||
|
|
||||||
# Prefixing Catch macros
|
# Reporter / Listener interfaces
|
||||||
|
|
||||||
|
CATCH_CONFIG_EXTERNAL_INTERFACES // Brings in neccessary headers for Reporter/Listener implementation
|
||||||
|
|
||||||
|
Brings in various parts of Catch that are required for user defined Reporters and Listeners. This means that new Reporters and Listeners can be defined in this file as well as in the main file.
|
||||||
|
|
||||||
|
Implied by both `CATCH_CONFIG_MAIN` and `CATCH_CONFIG_RUNNER`.
|
||||||
|
|
||||||
|
## Prefixing Catch macros
|
||||||
|
|
||||||
CATCH_CONFIG_PREFIX_ALL
|
CATCH_CONFIG_PREFIX_ALL
|
||||||
|
|
||||||
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
|
To keep test code clean and uncluttered Catch uses short macro names (e.g. ```TEST_CASE``` and ```REQUIRE```). Occasionally these may conflict with identifiers from platform headers or the system under test. In this case the above identifier can be defined. This will cause all the Catch user macros to be prefixed with ```CATCH_``` (e.g. ```CATCH_TEST_CASE``` and ```CATCH_REQUIRE```).
|
||||||
|
|
||||||
|
|
||||||
# Terminal colour
|
## Terminal colour
|
||||||
|
|
||||||
CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
|
CATCH_CONFIG_COLOUR_NONE // completely disables all text colouring
|
||||||
CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
|
CATCH_CONFIG_COLOUR_WINDOWS // forces the Win32 console API to be used
|
||||||
@ -32,14 +53,14 @@ Note that when ANSI colour codes are used "unistd.h" must be includable - along
|
|||||||
|
|
||||||
Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
|
Typically you should place the ```#define``` before #including "catch.hpp" in your main source file - but if you prefer you can define it for your whole project by whatever your IDE or build system provides for you to do so.
|
||||||
|
|
||||||
# Console width
|
## Console width
|
||||||
|
|
||||||
CATCH_CONFIG_CONSOLE_WIDTH = x // where x is a number
|
CATCH_CONFIG_CONSOLE_WIDTH = x // where x is a number
|
||||||
|
|
||||||
Catch formats output intended for the console to fit within a fixed number of characters. This is especially important as indentation is used extensively and uncontrolled line wraps break this.
|
Catch formats output intended for the console to fit within a fixed number of characters. This is especially important as indentation is used extensively and uncontrolled line wraps break this.
|
||||||
By default a console width of 80 is assumed but this can be controlled by defining the above identifier to be a different value.
|
By default a console width of 80 is assumed but this can be controlled by defining the above identifier to be a different value.
|
||||||
|
|
||||||
# stdout
|
## stdout
|
||||||
|
|
||||||
CATCH_CONFIG_NOSTDOUT
|
CATCH_CONFIG_NOSTDOUT
|
||||||
|
|
||||||
@ -51,63 +72,18 @@ Catch does not use ```std::cout```, ```std::cerr``` and ```std::clog``` directly
|
|||||||
|
|
||||||
This can be useful on certain platforms that do not provide the standard iostreams, such as certain embedded systems.
|
This can be useful on certain platforms that do not provide the standard iostreams, such as certain embedded systems.
|
||||||
|
|
||||||
# Default reporter
|
|
||||||
|
|
||||||
CATCH_CONFIG_DEFAULT_REPORTER <reporter>
|
|
||||||
|
|
||||||
The default reporter (reporter used when no reporters are explicitly specified) can be overriden during compilation time by using the above macro. Note that desired value of the macro is a C string and quotes have to be escaped during compilation: `clang++ test.cpp -DCATCH_CONFIG_DEFAULT_REPORTER=\"xml\"`.
|
## Other toggles
|
||||||
|
|
||||||
# C++ conformance toggles
|
|
||||||
|
|
||||||
CATCH_CONFIG_CPP11_NULLPTR // nullptr is supported?
|
|
||||||
CATCH_CONFIG_CPP11_NOEXCEPT // noexcept is supported?
|
|
||||||
CATCH_CONFIG_CPP11_GENERATED_METHODS // delete and default keywords for methods
|
|
||||||
CATCH_CONFIG_CPP11_IS_ENUM // std::is_enum is supported?
|
|
||||||
CATCH_CONFIG_CPP11_TUPLE // std::tuple is supported
|
|
||||||
CATCH_CONFIG_VARIADIC_MACROS // Usually pre-C++11 compiler extensions are sufficient
|
|
||||||
CATCH_CONFIG_CPP11_LONG_LONG // generates overloads for the long long type
|
|
||||||
CATCH_CONFIG_CPP11_OVERRIDE // CATCH_OVERRIDE expands to override (for virtual function implementations)
|
|
||||||
CATCH_CONFIG_CPP11_UNIQUE_PTR // Use std::unique_ptr instead of std::auto_ptr
|
|
||||||
CATCH_CONFIG_CPP11_SHUFFLE // Use std::shuffle instead of std::random_shuffle
|
|
||||||
CATCH_CONFIG_CPP11_TYPE_TRAITS // Use std::enable_if and <type_traits>
|
|
||||||
CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK // Use C++11 expression SFINAE to check if class can be inserted to std::ostream
|
|
||||||
|
|
||||||
Catch has some basic compiler detection that will attempt to select the appropriate mix of these macros. However being incomplete - and often without access to the respective compilers - this detection tends to be conservative.
|
|
||||||
So overriding control is given to the user. If a compiler supports a feature (and Catch does not already detect it) then one or more of these may be defined to enable it (or suppress it, in some cases). If you do do this please raise an issue, specifying your compiler version (ideally with an idea of how to detect it) and stating that it has such support.
|
|
||||||
You may also suppress any of these features by using the `_NO_` form, e.g. `CATCH_CONFIG_CPP11_NO_NULLPTR`.
|
|
||||||
|
|
||||||
All C++11 support can be disabled with `CATCH_CONFIG_NO_CPP11`
|
|
||||||
|
|
||||||
## `CATCH_CONFIG_CPP11_STREAM_INSERTABLE_CHECK`
|
|
||||||
|
|
||||||
This flag is off by default, but allows you to resolve problems caused by types with private base class that are streamable, but the classes themselves are not. Without it, the following code will cause a compilation error:
|
|
||||||
```cpp
|
|
||||||
#define CATCH_CONFIG_MAIN
|
|
||||||
#include <catch.hpp>
|
|
||||||
struct A {};
|
|
||||||
std::ostream &operator<< (std::ostream &o, const A &v) { return o << 0; }
|
|
||||||
|
|
||||||
struct B : private A {
|
|
||||||
bool operator==(int){ return true;}
|
|
||||||
};
|
|
||||||
|
|
||||||
B f ();
|
|
||||||
std::ostream g ();
|
|
||||||
|
|
||||||
TEST_CASE ("Error in streamable check") {
|
|
||||||
B x;
|
|
||||||
REQUIRE (x == 4);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
# Other toggles
|
|
||||||
|
|
||||||
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
|
CATCH_CONFIG_COUNTER // Use __COUNTER__ to generate unique names for test cases
|
||||||
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
|
CATCH_CONFIG_WINDOWS_SEH // Enable SEH handling on Windows
|
||||||
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
|
CATCH_CONFIG_FAST_COMPILE // Sacrifices some (rather minor) features for compilation speed
|
||||||
|
CATCH_CONFIG_DISABLE_MATCHERS // Do not compile Matchers in this compilation unit
|
||||||
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
CATCH_CONFIG_POSIX_SIGNALS // Enable handling POSIX signals
|
||||||
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
CATCH_CONFIG_WINDOWS_CRTDBG // Enable leak checking using Windows's CRT Debug Heap
|
||||||
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
CATCH_CONFIG_DISABLE_STRINGIFICATION // Disable stringifying the original expression
|
||||||
|
CATCH_CONFIG_DISABLE // Disables assertions and test case registration
|
||||||
|
|
||||||
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
|
Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC, because some versions of MinGW do not have the necessary Win32 API support.
|
||||||
|
|
||||||
@ -115,26 +91,48 @@ Currently Catch enables `CATCH_CONFIG_WINDOWS_SEH` only when compiled with MSVC,
|
|||||||
|
|
||||||
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running.
|
`CATCH_CONFIG_WINDOWS_CRTDBG` is off by default. If enabled, Windows's CRT is used to check for memory leaks, and displays them after the tests finish running.
|
||||||
|
|
||||||
Just as with the C++11 conformance toggles, these toggles can be disabled by using `_NO_` form of the toggle, e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
These toggles can be disabled by using `_NO_` form of the toggle, e.g. `CATCH_CONFIG_NO_WINDOWS_SEH`.
|
||||||
|
|
||||||
## `CATCH_CONFIG_FAST_COMPILE`
|
### `CATCH_CONFIG_FAST_COMPILE`
|
||||||
Defining this flag speeds up compilation of test files by ~20%, by making 2 changes:
|
Defining this flag speeds up compilation of test files by ~20%, by making 2 changes:
|
||||||
* The `-b` (`--break`) flag no longer makes Catch break into debugger in the same stack frame as the failed test, but rather in a stack frame *below*.
|
* The `-b` (`--break`) flag no longer makes Catch break into debugger in the same stack frame as the failed test, but rather in a stack frame *below*.
|
||||||
* The `REQUIRE` family of macros (`REQUIRE`, `REQUIRE_FALSE` and `REQUIRE_THAT`) no longer uses local try-catch block. This disables exception translation, but should not lead to false negatives.
|
* Non-exception family of macros ({`REQUIRE`,`CHECK`}{`_`,`_FALSE`, `_FALSE`}, no longer use local try-cache block. This disables exception translation, but should not lead to false negatives.
|
||||||
|
|
||||||
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined, in all translation units that are linked into single test binary, or the behaviour of setting `-b` flag and throwing unexpected exceptions will be unpredictable.
|
`CATCH_CONFIG_FAST_COMPILE` has to be either defined, or not defined, in all translation units that are linked into single test binary, or the behaviour of setting `-b` flag and throwing unexpected exceptions will be unpredictable.
|
||||||
|
|
||||||
## `CATCH_CONFIG_DISABLE_STRINGIFICATION`
|
### `CATCH_CONFIG_DISABLE_MATCHERS`
|
||||||
This toggle enables a workaround for VS 2017 bug. For details see
|
When `CATCH_CONFIG_DISABLE_MATCHERS` is defined, all mentions of Catch's Matchers are ifdef-ed away from the translation unit. Doing so will speed up compilation of that TU.
|
||||||
[known limitations](limitations.md#visual-studio-2017----raw-string-literal-in-assert-fails-to-compile).
|
|
||||||
|
|
||||||
# Windows header clutter
|
_Note: If you define `CATCH_CONFIG_DISABLE_MATCHERS` in the same file as Catch's main is implemented, your test executable will fail to link if you use Matchers anywhere._
|
||||||
|
|
||||||
|
### `CATCH_CONFIG_DISABLE_STRINGIFICATION`
|
||||||
|
This toggle enables a workaround for VS 2017 bug. For details see [known limitations](limitations.md#visual-studio-2017----raw-string-literal-in-assert-fails-to-compile).
|
||||||
|
|
||||||
|
### `CATCH_CONFIG_DISABLE`
|
||||||
|
This toggle removes most of Catch from given file. This means that `TEST_CASE`s are not registered and assertions are turned into no-ops. Useful for keeping tests within implementation files (ie for functions with internal linkage), instead of in external files.
|
||||||
|
|
||||||
|
This feature is considered experimental and might change at any point.
|
||||||
|
|
||||||
|
_Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`_
|
||||||
|
|
||||||
|
## Windows header clutter
|
||||||
|
|
||||||
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
|
On Windows Catch includes `windows.h`. To minimize global namespace clutter in the implementation file, it defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including it. You can control this behaviour via two macros:
|
||||||
|
|
||||||
CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro
|
CATCH_CONFIG_NO_NOMINMAX // Stops Catch from using NOMINMAX macro
|
||||||
CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro
|
CATCH_CONFIG_NO_WIN32_LEAN_AND_MEAN // Stops Catch from using WIN32_LEAN_AND_MEAN macro
|
||||||
|
|
||||||
|
|
||||||
|
## Enabling stringification
|
||||||
|
|
||||||
|
By default, Catch does not stringify some types from the standard library. This is done to avoid dragging in various standard library headers by default. However, Catch does contain these and can be configured to provide them, using these macros:
|
||||||
|
|
||||||
|
CATCH_CONFIG_ENABLE_PAIR_STRINGMAKER // Provide StringMaker specialization for std::pair
|
||||||
|
CATCH_CONFIG_ENABLE_TUPLE_STRINGMAKER // Provide StringMaker specialization for std::tuple
|
||||||
|
CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER // Provide StringMaker specialization for std::chrono::duration, std::chrono::timepoint
|
||||||
|
CATCH_CONFIG_ENABLE_ALL_STRINGMAKERS // Defines all of the above
|
||||||
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Contributing to Catch
|
# Contributing to Catch
|
||||||
|
|
||||||
So you want to contribute something to Catch? That's great! Whether it's a bug fix, a new feature, support for
|
So you want to contribute something to Catch? That's great! Whether it's a bug fix, a new feature, support for
|
||||||
@ -57,4 +58,4 @@ be fairly self-explanatory.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Event Listeners
|
# Event Listeners
|
||||||
|
|
||||||
A `Listener` is a class you can register with Catch that will then be passed events,
|
A `Listener` is a class you can register with Catch that will then be passed events,
|
||||||
@ -12,10 +13,11 @@ so you are not forced to implement events you're not interested in.
|
|||||||
|
|
||||||
|
|
||||||
## Implementing a Listener
|
## Implementing a Listener
|
||||||
|
Simply derive a class from `Catch::TestEventListenerBase` and implement the methods you are interested in, either in
|
||||||
|
the main source file (i.e. the one that defines `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`), or in a
|
||||||
|
file that defines `CATCH_CONFIG_EXTERNAL_INTERFACES`.
|
||||||
|
|
||||||
In your main source file (i.e. the one that has the `#define` for `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`),
|
Then register it using `CATCH_REGISTER_LISTENER`.
|
||||||
simply derive a class from `Catch::TestEventListenerBase` and implement the methods you are interested in.
|
|
||||||
Then register it using `INTERNAL_CATCH_REGISTER_LISTENER`.
|
|
||||||
|
|
||||||
For example:
|
For example:
|
||||||
|
|
||||||
@ -70,4 +72,4 @@ just look in the source code to see what fields are available.
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,7 +1,22 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Known limitations
|
# Known limitations
|
||||||
|
|
||||||
Catch has some known limitations, that we are not planning to change. Some of these are caused by our desire to support C++98 compilers, some of these are caused by our desire to keep Catch crossplatform, some exist because their priority is seen as low compared to the development effort they would need and some other yet are compiler/runtime bugs.
|
Catch has some known limitations, that we are not planning to change. Some of these are caused by our desire to support C++98 compilers, some of these are caused by our desire to keep Catch crossplatform, some exist because their priority is seen as low compared to the development effort they would need and some other yet are compiler/runtime bugs.
|
||||||
|
|
||||||
|
## Implementation limits
|
||||||
|
### Sections nested in loops
|
||||||
|
|
||||||
|
If you are using `SECTION`s inside loops, you have to create them with different name per loop's iteration. The recommended way to do so is to incorporate the loop's counter into section's name, like so
|
||||||
|
```cpp
|
||||||
|
TEST_CASE( "Looped section" ) {
|
||||||
|
for (char i = '0'; i < '5'; ++i) {
|
||||||
|
SECTION(std::string("Looped section ") + i) {
|
||||||
|
SUCCEED( "Everything is OK" );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
This section outlines some missing features, what is their status and their possible workarounds.
|
This section outlines some missing features, what is their status and their possible workarounds.
|
||||||
|
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Logging macros
|
# Logging macros
|
||||||
|
|
||||||
Additional messages can be logged during a test case. Note that the messages are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
|
Additional messages can be logged during a test case. Note that the messages are scoped and thus will not be reported if failure occurs in scope preceding the message declaration. An example:
|
||||||
@ -79,4 +80,4 @@ These macros are now deprecated and are just aliases for INFO and CAPTURE (which
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Matchers
|
# Matchers
|
||||||
|
|
||||||
Matchers are an alternative way to do assertions which are easily extensible and composable.
|
Matchers are an alternative way to do assertions which are easily extensible and composable.
|
||||||
@ -101,4 +102,4 @@ with expansion:
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Open Source projects using Catch
|
# Open Source projects using Catch
|
||||||
|
|
||||||
Catch is great for open source. With its [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
|
Catch is great for open source. With its [liberal license](../LICENSE.txt) and single-header, dependency-free, distribution
|
||||||
@ -83,4 +84,4 @@ Standardese aims to be a nextgen Doxygen
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Supplying main() yourself
|
# Supplying main() yourself
|
||||||
|
|
||||||
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
|
The easiest way to use Catch is to let it supply ```main()``` for you and handle configuring itself from the command line.
|
||||||
@ -16,15 +17,14 @@ If you just need to have code that executes before and/ or after Catch this is t
|
|||||||
#define CATCH_CONFIG_RUNNER
|
#define CATCH_CONFIG_RUNNER
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] ) {
|
||||||
{
|
|
||||||
// global setup...
|
// global setup...
|
||||||
|
|
||||||
int result = Catch::Session().run( argc, argv );
|
int result = Catch::Session().run( argc, argv );
|
||||||
|
|
||||||
// global clean-up...
|
// global clean-up...
|
||||||
|
|
||||||
return ( result < 0xff ? result : 0xff );
|
return result;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -39,23 +39,24 @@ If you still want Catch to process the command line, but you want to programatic
|
|||||||
int main( int argc, char* argv[] )
|
int main( int argc, char* argv[] )
|
||||||
{
|
{
|
||||||
Catch::Session session; // There must be exactly one instance
|
Catch::Session session; // There must be exactly one instance
|
||||||
|
|
||||||
// writing to session.configData() here sets defaults
|
// writing to session.configData() here sets defaults
|
||||||
// this is the preferred way to set them
|
// this is the preferred way to set them
|
||||||
|
|
||||||
int returnCode = session.applyCommandLine( argc, argv );
|
int returnCode = session.applyCommandLine( argc, argv );
|
||||||
if( returnCode != 0 ) // Indicates a command line error
|
if( returnCode != 0 ) // Indicates a command line error
|
||||||
return returnCode;
|
return returnCode;
|
||||||
|
|
||||||
// writing to session.configData() or session.Config() here
|
// writing to session.configData() or session.Config() here
|
||||||
// overrides command line args
|
// overrides command line args
|
||||||
// only do this if you know you need to
|
// only do this if you know you need to
|
||||||
|
|
||||||
int numFailed = session.run();
|
int numFailed = session.run();
|
||||||
// Note that on unices only the lower 8 bits are usually used, clamping
|
|
||||||
// the return value to 255 prevents false negative when some multiple
|
// numFailed is clamped to 255 as some unices only use the lower 8 bits.
|
||||||
// of 256 tests has failed
|
// This clamping has already been applied, so just return it here
|
||||||
return ( numFailed < 0xff ? numFailed : 0xff );
|
// You can also do any post run clean-up here
|
||||||
|
return numFailed;
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -65,8 +66,45 @@ To take full control of the config simply omit the call to ```applyCommandLine()
|
|||||||
|
|
||||||
## Adding your own command line options
|
## Adding your own command line options
|
||||||
|
|
||||||
Catch embeds a powerful command line parser which you can also use to parse your own options out. This capability is still in active development but will be documented here when it is ready.
|
Catch embeds a powerful command line parser called [Clara](https://github.com/philsquared/Clara).
|
||||||
|
As of Catch2 (and Clara 1.0) Clara allows you to write _composable_ option and argument parsers,
|
||||||
|
so extending Catch's own command line options is now easy.
|
||||||
|
|
||||||
|
```c++
|
||||||
|
#define CATCH_CONFIG_RUNNER
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
int main( int argc, char* argv[] )
|
||||||
|
{
|
||||||
|
Catch::Session session; // There must be exactly one instance
|
||||||
|
|
||||||
|
int height = 0; // Some user variable you want to be able to set
|
||||||
|
|
||||||
|
// Build a new parser on top of Catch's
|
||||||
|
auto cli
|
||||||
|
= session.cli() // Get Catch's composite command line parser
|
||||||
|
| Opt( height, "height" ) // bind variable to a new option, with a hint string
|
||||||
|
["-g"]["--height"] // the option names it will respond to
|
||||||
|
("how high?"); // description string for the help output
|
||||||
|
|
||||||
|
// Now pass the new composite back to Catch so it uses that
|
||||||
|
session.cli( cli );
|
||||||
|
|
||||||
|
// Let Catch (using Clara) parse the command line
|
||||||
|
int returnCode = session.applyCommandLine( argc, argv );
|
||||||
|
if( returnCode != 0 ) // Indicates a command line error
|
||||||
|
return returnCode;
|
||||||
|
|
||||||
|
// if set on the command line then 'height' is now set at this point
|
||||||
|
if( height > 0 )
|
||||||
|
std::cout << "height: " << height << std::endl;
|
||||||
|
|
||||||
|
return session.run();
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
See the [Clara documentation](https://github.com/philsquared/Clara/blob/master/README.md) for more details.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,70 +1,106 @@
|
|||||||
# 1.11.0
|
<a id="top"></a>
|
||||||
|
# 2.0.1
|
||||||
|
|
||||||
### Fixes
|
## Breaking changes
|
||||||
* The original expression in `REQUIRE_FALSE( expr )` is now reporter properly as `!( expr )` (#1051)
|
* Removed C++98 support
|
||||||
* Previously the parentheses were missing and `x != y` would be expanded as `!x != x`
|
* Removed legacy reporter support
|
||||||
* `Approx::Margin` is now inclusive (#952)
|
* Removed legacy generator support
|
||||||
* Previously it was meant and documented as inclusive, but the check itself wasn't
|
* Generator support will come back later, reworked
|
||||||
* This means that `REQUIRE( 0.25f == Approx( 0.0f ).margin( 0.25f ) )` passes, instead of fails
|
* Removed `Catch::toString` support
|
||||||
* `RandomNumberGenerator::result_type` is now unsigned (#1050)
|
* The new stringification machinery uses `Catch::StringMaker` specializations first and `operator<<` overloads second.
|
||||||
|
* Removed legacy `SCOPED_MSG` and `SCOPED_INFO` macros
|
||||||
### Improvements
|
* Removed `INTERNAL_CATCH_REGISTER_REPORTER`
|
||||||
* `__JETBRAINS_IDE__` macro handling is now CLion version specific (#1017)
|
* `CATCH_REGISTER_REPORTER` should be used to register reporters
|
||||||
* When CLion 2017.3 or newer is detected, `__COUNTER__` is used instead of
|
* Removed legacy `[hide]` tag
|
||||||
* TeamCity reporter now explicitly flushes output stream after each report (#1057)
|
* `[.]`, `[.foo]` and `[!hide]` are still supported
|
||||||
* On some platforms, output from redirected streams would show up only after the tests finished running
|
* Output into debugger is now colourized
|
||||||
* `ParseAndAddCatchTests` now can add test files as dependency to CMake configuration
|
* `*_THROWS_AS(expr, exception_type)` now unconditionally appends `const&` to the exception type.
|
||||||
* This means you do not have to manually rerun CMake configuration step to detect new tests
|
* `CATCH_CONFIG_FAST_COMPILE` now affects the `CHECK_` family of assertions as well as `REQUIRE_` family of assertions
|
||||||
|
* This is most noticeable in `CHECK(throws())`, which would previously report failure, properly stringify the exception and continue. Now it will report failure and stop executing current section.
|
||||||
|
* Removed deprecated matcher utility functions `Not`, `AllOf` and `AnyOf`.
|
||||||
|
* They are superseded by operators `!`, `&&` and `||`, which are natural and do not have limited arity
|
||||||
|
* Removed support for non-const comparison operators
|
||||||
|
* Non-const comparison operators are an abomination that should not exist
|
||||||
|
* They were breaking support for comparing function to function pointer
|
||||||
|
* `std::pair` and `std::tuple` are no longer stringified by default
|
||||||
|
* This is done to avoid dragging in `<tuple>` and `<utility>` headers in common path
|
||||||
|
* Their stringification can be enabled per-file via new configuration macros
|
||||||
|
* `Approx` is subtly different and hopefully behaves more as users would expect
|
||||||
|
* `Approx::scale` defaults to `0.0`
|
||||||
|
* `Approx::epsilon` no longer applies to the larger of the two compared values, but only to the `Approx`'s value
|
||||||
|
* `INFINITY == Approx(INFINITY)` returns true
|
||||||
|
|
||||||
|
|
||||||
# 1.10.0
|
## Improvements
|
||||||
|
* Reporters and Listeners can be defined in files different from the main file
|
||||||
### Fixes
|
* The file has to define `CATCH_CONFIG_EXTERNAL_INTERFACES` before including catch.hpp.
|
||||||
* Evaluation layer has been rewritten (backported from Catch 2)
|
* Errors that happen during set up before main are now caught and properly reported once main is entered
|
||||||
* The new layer is much simpler and fixes some issues (#981)
|
* If you are providing your own main, you can access and use these as well.
|
||||||
* Implemented workaround for VS 2017 raw string literal stringification bug (#995)
|
* New assertion macros, *_THROWS_WITH(expr, exception_type, matcher) are provided
|
||||||
* Fixed interaction between `[!shouldfail]` and `[!mayfail]` tags and sections
|
* As the arguments suggest, these allow you to assert that an expression throws desired type of exception and pass the exception to a matcher.
|
||||||
* Previously sections with failing assertions would be marked as failed, not failed-but-ok
|
* JUnit reporter no longer has significantly different output for test cases with and without sections
|
||||||
|
* Most assertions now support expressions containing commas (ie `REQUIRE(foo() == std::vector<int>{1, 2, 3});`)
|
||||||
### Improvements
|
* Catch now contains experimental micro benchmarking support
|
||||||
* Added [libidentify](https://github.com/janwilmans/LibIdentify) support
|
* See `projects/SelfTest/Benchmark.tests.cpp` for examples
|
||||||
* Added "wait-for-keypress" option
|
* The support being experiment means that it can be changed without prior notice
|
||||||
|
* Catch uses new CLI parsing library (Clara)
|
||||||
|
* Users can now easily add new command line options to the final executable
|
||||||
|
* This also leads to some changes in `Catch::Session` interface
|
||||||
|
* All parts of matchers can be removed from a TU by defining `CATCH_CONFIG_DISABLE_MATCHERS`
|
||||||
|
* This can be used to somewhat speed up compilation times
|
||||||
|
* An experimental implementation of `CATCH_CONFIG_DISABLE` has been added
|
||||||
|
* Inspired by Doctest's `DOCTEST_CONFIG_DISABLE`
|
||||||
|
* Useful for implementing tests in source files
|
||||||
|
* ie for functions in anonymous namespaces
|
||||||
|
* Removes all assertions
|
||||||
|
* Prevents `TEST_CASE` registrations
|
||||||
|
* Exception translators are not registered
|
||||||
|
* Reporters are not registered
|
||||||
|
* Listeners are not registered
|
||||||
|
* Reporters/Listeners are now notified of fatal errors
|
||||||
|
* This means specific signals or structured exceptions
|
||||||
|
* The Reporter/Listener interface provides default, empty, implementation to preserve backward compatibility
|
||||||
|
* Stringification of `std::chrono::duration` and `std::chrono::time_point` is now supported
|
||||||
|
* Needs to be enabled by a per-file compile time configuration option
|
||||||
|
* Add `pkg-config` support to CMake install command
|
||||||
|
|
||||||
|
|
||||||
# 1.9.7
|
## Fixes
|
||||||
|
* Don't use console colour if running in XCode
|
||||||
### Fixes
|
* Explicit constructor in reporter base class
|
||||||
* Various warnings from clang-tidy, Resharper-C++ and PVS Studio have been addressed (#957)
|
* Swept out `-Wweak-vtables`, `-Wexit-time-destructors`, `-Wglobal-constructors` warnings
|
||||||
* Dynamically generated sections are now properly reported (#963)
|
* Compilation for Universal Windows Platform (UWP) is supported
|
||||||
* Writes to `std::clog` are redirected for reporters (#989)
|
* SEH handling and colorized output are disabled when compiling for UWP
|
||||||
* Previously only `std::cerr` writes were redirected
|
* Implemented a workaround for `std::uncaught_exception` issues in libcxxrt
|
||||||
* Interleaved writes to `std::cerr` and `std::clog` are combined properly
|
* These issues caused incorrect section traversals
|
||||||
* Assertions failed before signals/structured exceptions fails test case are properly reported as failed (#990)
|
* The workaround is only partial, user's test can still trigger the issue by using `throw;` to rethrow an exception
|
||||||
|
* Suppressed C4061 warning under MSVC
|
||||||
### Improvements
|
|
||||||
* Catch's runtime overhead has been decreased further (#940)
|
|
||||||
* Added support for IBM i ILE c++ compiler (#976)
|
|
||||||
* This means that AS/400 is now supported.
|
|
||||||
* The default reporter can be configured at compile time (#978)
|
|
||||||
* That is, the reporter used if no reporter is explicitly specified
|
|
||||||
|
|
||||||
### Other
|
|
||||||
* `ParseAndAddCatchTests` cmake script has couple new customization options
|
|
||||||
|
|
||||||
|
|
||||||
|
## Internal changes
|
||||||
|
* The development version now uses .cpp files instead of header files containing implementation.
|
||||||
|
* This makes partial rebuilds much faster during development
|
||||||
|
* The expression decomposition layer has been rewritten
|
||||||
|
* The evaluation layer has been rewritten
|
||||||
|
* New library (TextFlow) is used for formatting text to output
|
||||||
|
|
||||||
# 1.9.6
|
|
||||||
|
|
||||||
### Improvements
|
# Older versions
|
||||||
|
|
||||||
|
## 1.9.x
|
||||||
|
|
||||||
|
### 1.9.6
|
||||||
|
|
||||||
|
#### Improvements
|
||||||
* Catch's runtime overhead has been significantly decreased (#937, #939)
|
* Catch's runtime overhead has been significantly decreased (#937, #939)
|
||||||
* Added `--list-extra-info` cli option (#934).
|
* Added `--list-extra-info` cli option (#934).
|
||||||
* It lists all tests together with extra information, ie filename, line number and description.
|
* It lists all tests together with extra information, ie filename, line number and description.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 1.9.5
|
### 1.9.5
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
* Truthy expressions are now reconstructed properly, not as booleans (#914)
|
* Truthy expressions are now reconstructed properly, not as booleans (#914)
|
||||||
* Various warnings are no longer erroneously suppressed in test files (files that include `catch.hpp`, but do not define `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`) (#871)
|
* Various warnings are no longer erroneously suppressed in test files (files that include `catch.hpp`, but do not define `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`) (#871)
|
||||||
* Catch no longer fails to link when main is compiled as C++, but linked against Objective-C (#855)
|
* Catch no longer fails to link when main is compiled as C++, but linked against Objective-C (#855)
|
||||||
@ -72,35 +108,35 @@
|
|||||||
* Previously any GCC with minor version less than 3 would be incorrectly classified as not supporting `__COUNTER__`.
|
* Previously any GCC with minor version less than 3 would be incorrectly classified as not supporting `__COUNTER__`.
|
||||||
* Suppressed C4996 warning caused by upcoming updated to MSVC 2017, marking `std::uncaught_exception` as deprecated. (#927)
|
* Suppressed C4996 warning caused by upcoming updated to MSVC 2017, marking `std::uncaught_exception` as deprecated. (#927)
|
||||||
|
|
||||||
### Improvements
|
#### Improvements
|
||||||
* CMake integration script now incorporates debug messages and registers tests in an improved way (#911)
|
* CMake integration script now incorporates debug messages and registers tests in an improved way (#911)
|
||||||
* Various documentation improvements
|
* Various documentation improvements
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 1.9.4
|
### 1.9.4
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
* `CATCH_FAIL` macro no longer causes compilation error without variadic macro support
|
* `CATCH_FAIL` macro no longer causes compilation error without variadic macro support
|
||||||
* `INFO` messages are no longer cleared after being reported once
|
* `INFO` messages are no longer cleared after being reported once
|
||||||
|
|
||||||
### Improvements and minor changes
|
#### Improvements and minor changes
|
||||||
* Catch now uses `wmain` when compiled under Windows and `UNICODE` is defined.
|
* Catch now uses `wmain` when compiled under Windows and `UNICODE` is defined.
|
||||||
* Note that Catch still officially supports only ASCII
|
* Note that Catch still officially supports only ASCII
|
||||||
|
|
||||||
# 1.9.3
|
### 1.9.3
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
* Completed the fix for (lack of) uint64_t in earlier Visual Studios
|
* Completed the fix for (lack of) uint64_t in earlier Visual Studios
|
||||||
|
|
||||||
# 1.9.2
|
### 1.9.2
|
||||||
|
|
||||||
### Improvements and minor changes
|
#### Improvements and minor changes
|
||||||
* All of `Approx`'s member functions now accept strong typedefs in C++11 mode (#888)
|
* All of `Approx`'s member functions now accept strong typedefs in C++11 mode (#888)
|
||||||
* Previously `Approx::scale`, `Approx::epsilon`, `Approx::margin` and `Approx::operator()` didn't.
|
* Previously `Approx::scale`, `Approx::epsilon`, `Approx::margin` and `Approx::operator()` didn't.
|
||||||
|
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
* POSIX signals are now disabled by default under QNX (#889)
|
* POSIX signals are now disabled by default under QNX (#889)
|
||||||
* QNX does not support current enough (2001) POSIX specification
|
* QNX does not support current enough (2001) POSIX specification
|
||||||
* JUnit no longer counts exceptions as failures if given test case is marked as ok to fail.
|
* JUnit no longer counts exceptions as failures if given test case is marked as ok to fail.
|
||||||
@ -108,22 +144,22 @@
|
|||||||
* Catch no longer attempts to define `uint64_t` on windows (#862)
|
* Catch no longer attempts to define `uint64_t` on windows (#862)
|
||||||
* This was causing trouble when compiled under Cygwin
|
* This was causing trouble when compiled under Cygwin
|
||||||
|
|
||||||
### Other
|
#### Other
|
||||||
* Catch is now compiled under MSVC 2017 using `std:c++latest` (C++17 mode) in CI
|
* Catch is now compiled under MSVC 2017 using `std:c++latest` (C++17 mode) in CI
|
||||||
* We now provide cmake script that autoregisters Catch tests into ctest.
|
* We now provide cmake script that autoregisters Catch tests into ctest.
|
||||||
* See `contrib` folder.
|
* See `contrib` folder.
|
||||||
|
|
||||||
|
|
||||||
# 1.9.1
|
### 1.9.1
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
* Unexpected exceptions are no longer ignored by default (#885, #887)
|
* Unexpected exceptions are no longer ignored by default (#885, #887)
|
||||||
|
|
||||||
|
|
||||||
# 1.9.0
|
### 1.9.0
|
||||||
|
|
||||||
|
|
||||||
### Improvements and minor changes
|
#### Improvements and minor changes
|
||||||
* Catch no longer attempts to ensure the exception type passed by user in `REQUIRE_THROWS_AS` is a constant reference.
|
* Catch no longer attempts to ensure the exception type passed by user in `REQUIRE_THROWS_AS` is a constant reference.
|
||||||
* It was causing trouble when `REQUIRE_THROWS_AS` was used inside templated functions
|
* It was causing trouble when `REQUIRE_THROWS_AS` was used inside templated functions
|
||||||
* This actually reverts changes made in v1.7.2
|
* This actually reverts changes made in v1.7.2
|
||||||
@ -137,7 +173,7 @@
|
|||||||
* When Catch is compiled using C++11, `Approx` is now constructible with anything that can be explicitly converted to `double`.
|
* When Catch is compiled using C++11, `Approx` is now constructible with anything that can be explicitly converted to `double`.
|
||||||
* Captured messages are now printed on unexpected exceptions
|
* Captured messages are now printed on unexpected exceptions
|
||||||
|
|
||||||
### Fixes:
|
#### Fixes:
|
||||||
* Clang's `-Wexit-time-destructors` should be suppressed for Catch's internals
|
* Clang's `-Wexit-time-destructors` should be suppressed for Catch's internals
|
||||||
* GCC's `-Wparentheses` is now suppressed for all TU's that include `catch.hpp`.
|
* GCC's `-Wparentheses` is now suppressed for all TU's that include `catch.hpp`.
|
||||||
* This is functionally a revert of changes made in 1.8.0, where we tried using `_Pragma` based suppression. This should have kept the suppression local to Catch's assertions, but bugs in GCC's handling of `_Pragma`s in C++ mode meant that it did not always work.
|
* This is functionally a revert of changes made in 1.8.0, where we tried using `_Pragma` based suppression. This should have kept the suppression local to Catch's assertions, but bugs in GCC's handling of `_Pragma`s in C++ mode meant that it did not always work.
|
||||||
@ -146,16 +182,18 @@
|
|||||||
* [Details can be found in documentation](configuration.md#catch_config_cpp11_stream_insertable_check)
|
* [Details can be found in documentation](configuration.md#catch_config_cpp11_stream_insertable_check)
|
||||||
|
|
||||||
|
|
||||||
### Other notes:
|
#### Other notes:
|
||||||
* We have added VS 2017 to our CI
|
* We have added VS 2017 to our CI
|
||||||
* Work on Catch 2 should start soon
|
* Work on Catch 2 should start soon
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 1.8.2
|
## 1.8.x
|
||||||
|
|
||||||
|
### 1.8.2
|
||||||
|
|
||||||
|
|
||||||
### Improvements and minor changes
|
#### Improvements and minor changes
|
||||||
* TAP reporter now behaves as if `-s` was always set
|
* TAP reporter now behaves as if `-s` was always set
|
||||||
* This should be more consistent with the protocol desired behaviour.
|
* This should be more consistent with the protocol desired behaviour.
|
||||||
* Compact reporter now obeys `-d yes` argument (#780)
|
* Compact reporter now obeys `-d yes` argument (#780)
|
||||||
@ -165,11 +203,11 @@
|
|||||||
* This means it reports `INFO` messages on success, if output on success (`-s`) is enabled.
|
* This means it reports `INFO` messages on success, if output on success (`-s`) is enabled.
|
||||||
* Previously it only reported `INFO` messages on failure.
|
* Previously it only reported `INFO` messages on failure.
|
||||||
* `CAPTURE(expr)` now stringifies `expr` in the same way assertion macros do (#639)
|
* `CAPTURE(expr)` now stringifies `expr` in the same way assertion macros do (#639)
|
||||||
* Listeners are now finally [documented](event-listeners.md).
|
* Listeners are now finally [documented](event-listeners.md#top).
|
||||||
* Listeners provide a way to hook into events generated by running your tests, including start and end of run, every test case, every section and every assertion.
|
* Listeners provide a way to hook into events generated by running your tests, including start and end of run, every test case, every section and every assertion.
|
||||||
|
|
||||||
|
|
||||||
### Fixes:
|
#### Fixes:
|
||||||
* Catch no longer attempts to reconstruct expression that led to a fatal error (#810)
|
* Catch no longer attempts to reconstruct expression that led to a fatal error (#810)
|
||||||
* This fixes possible signal/SEH loop when processing expressions, where the signal was triggered by expression decomposition.
|
* This fixes possible signal/SEH loop when processing expressions, where the signal was triggered by expression decomposition.
|
||||||
* Fixed (C4265) missing virtual destructor warning in Matchers (#844)
|
* Fixed (C4265) missing virtual destructor warning in Matchers (#844)
|
||||||
@ -186,25 +224,25 @@
|
|||||||
* Regression in Objective-C bindings (Matchers) fixed (#854)
|
* Regression in Objective-C bindings (Matchers) fixed (#854)
|
||||||
|
|
||||||
|
|
||||||
### Other notes:
|
#### Other notes:
|
||||||
* We have added VS 2013 and 2015 to our CI
|
* We have added VS 2013 and 2015 to our CI
|
||||||
* Catch Classic (1.x.x) now contains its own, forked, version of Clara (the argument parser).
|
* Catch Classic (1.x.x) now contains its own, forked, version of Clara (the argument parser).
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# 1.8.1
|
### 1.8.1
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
|
|
||||||
Cygwin issue with `gettimeofday` - `#define` was not early enough
|
Cygwin issue with `gettimeofday` - `#define` was not early enough
|
||||||
|
|
||||||
# 1.8.0
|
### 1.8.0
|
||||||
|
|
||||||
### New features/ minor changes
|
#### New features/ minor changes
|
||||||
|
|
||||||
* Matchers have new, simpler (and documented) interface.
|
* Matchers have new, simpler (and documented) interface.
|
||||||
* Catch provides string and vector matchers.
|
* Catch provides string and vector matchers.
|
||||||
* For details see [Matchers documentation](matchers.md).
|
* For details see [Matchers documentation](matchers.md#top).
|
||||||
* Changed console reporter test duration reporting format (#322)
|
* Changed console reporter test duration reporting format (#322)
|
||||||
* Old format: `Some simple comparisons between doubles completed in 0.000123s`
|
* Old format: `Some simple comparisons between doubles completed in 0.000123s`
|
||||||
* New format: `xxx.123s: Some simple comparisons between doubles` _(There will always be exactly 3 decimal places)_
|
* New format: `xxx.123s: Some simple comparisons between doubles` _(There will always be exactly 3 decimal places)_
|
||||||
@ -215,12 +253,12 @@ Cygwin issue with `gettimeofday` - `#define` was not early enough
|
|||||||
* _More changes are coming_
|
* _More changes are coming_
|
||||||
* Added [TAP (Test Anything Protocol)](https://testanything.org/) and [Automake](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) reporters.
|
* Added [TAP (Test Anything Protocol)](https://testanything.org/) and [Automake](https://www.gnu.org/software/automake/manual/html_node/Log-files-generation-and-test-results-recording.html#Log-files-generation-and-test-results-recording) reporters.
|
||||||
* These are not present in the default single-include header and need to be downloaded from GitHub separately.
|
* These are not present in the default single-include header and need to be downloaded from GitHub separately.
|
||||||
* For details see [documentation about integrating with build systems](build-systems.md).
|
* For details see [documentation about integrating with build systems](build-systems.md#top).
|
||||||
* XML reporter now reports filename as part of the `Section` and `TestCase` tags.
|
* XML reporter now reports filename as part of the `Section` and `TestCase` tags.
|
||||||
* `Approx` now supports an optional margin of absolute error
|
* `Approx` now supports an optional margin of absolute error
|
||||||
* It has also received [new documentation](assertions.md).
|
* It has also received [new documentation](assertions.md#top).
|
||||||
|
|
||||||
### Fixes
|
#### Fixes
|
||||||
* Silenced C4312 ("conversion from int to 'ClassName *") warnings in the evaluate layer.
|
* Silenced C4312 ("conversion from int to 'ClassName *") warnings in the evaluate layer.
|
||||||
* Fixed C4512 ("assignment operator could not be generated") warnings under VS2013.
|
* Fixed C4512 ("assignment operator could not be generated") warnings under VS2013.
|
||||||
* Cygwin compatibility fixes
|
* Cygwin compatibility fixes
|
||||||
@ -231,13 +269,15 @@ Cygwin issue with `gettimeofday` - `#define` was not early enough
|
|||||||
* Otherwise it is supressed for the whole TU
|
* Otherwise it is supressed for the whole TU
|
||||||
* Fixed test spec parser issue (with escapes in multiple names)
|
* Fixed test spec parser issue (with escapes in multiple names)
|
||||||
|
|
||||||
### Other
|
#### Other
|
||||||
* Various documentation fixes and improvements
|
* Various documentation fixes and improvements
|
||||||
|
|
||||||
|
|
||||||
# 1.7.2
|
## 1.7.x
|
||||||
|
|
||||||
### Fixes and minor improvements
|
### 1.7.2
|
||||||
|
|
||||||
|
#### Fixes and minor improvements
|
||||||
Xml:
|
Xml:
|
||||||
|
|
||||||
(technically the first two are breaking changes but are also fixes and arguably break few if any people)
|
(technically the first two are breaking changes but are also fixes and arguably break few if any people)
|
||||||
@ -256,26 +296,26 @@ Other:
|
|||||||
* Silenced a few more warnings in different circumstances
|
* Silenced a few more warnings in different circumstances
|
||||||
* Travis improvements
|
* Travis improvements
|
||||||
|
|
||||||
# 1.7.1
|
### 1.7.1
|
||||||
|
|
||||||
### Fixes:
|
#### Fixes:
|
||||||
* Fixed inconsistency in defining `NOMINMAX` and `WIN32_LEAN_AND_MEAN` inside `catch.hpp`.
|
* Fixed inconsistency in defining `NOMINMAX` and `WIN32_LEAN_AND_MEAN` inside `catch.hpp`.
|
||||||
* Fixed SEH-related compilation error under older MinGW compilers, by making Windows SEH handling opt-in for compilers other than MSVC.
|
* Fixed SEH-related compilation error under older MinGW compilers, by making Windows SEH handling opt-in for compilers other than MSVC.
|
||||||
* For specifics, look into the [documentation](configuration.md).
|
* For specifics, look into the [documentation](configuration.md#top).
|
||||||
* Fixed compilation error under MinGW caused by improper compiler detection.
|
* Fixed compilation error under MinGW caused by improper compiler detection.
|
||||||
* Fixed XML reporter sometimes leaving an empty output file when a test ends with signal/structured exception.
|
* Fixed XML reporter sometimes leaving an empty output file when a test ends with signal/structured exception.
|
||||||
* Fixed XML reporter not reporting captured stdout/stderr.
|
* Fixed XML reporter not reporting captured stdout/stderr.
|
||||||
* Fixed possible infinite recursion in Windows SEH.
|
* Fixed possible infinite recursion in Windows SEH.
|
||||||
* Fixed possible compilation error caused by Catch's operator overloads being ambiguous in regards to user-defined templated operators.
|
* Fixed possible compilation error caused by Catch's operator overloads being ambiguous in regards to user-defined templated operators.
|
||||||
|
|
||||||
## 1.7.0
|
### 1.7.0
|
||||||
|
|
||||||
### Features/ Changes:
|
#### Features/ Changes:
|
||||||
* Catch now runs significantly faster for passing tests
|
* Catch now runs significantly faster for passing tests
|
||||||
* Microbenchmark focused on Catch's overhead went from ~3.4s to ~0.7s.
|
* Microbenchmark focused on Catch's overhead went from ~3.4s to ~0.7s.
|
||||||
* Real world test using [JSON for Modern C++](https://github.com/nlohmann/json)'s test suite went from ~6m 25s to ~4m 14s.
|
* Real world test using [JSON for Modern C++](https://github.com/nlohmann/json)'s test suite went from ~6m 25s to ~4m 14s.
|
||||||
* Catch can now run specific sections within test cases.
|
* Catch can now run specific sections within test cases.
|
||||||
* For now the support is only basic (no wildcards or tags), for details see the [documentation](command-line.md).
|
* For now the support is only basic (no wildcards or tags), for details see the [documentation](command-line.md#top).
|
||||||
* Catch now supports SEH on Windows as well as signals on Linux.
|
* Catch now supports SEH on Windows as well as signals on Linux.
|
||||||
* After receiving a signal, Catch reports failing assertion and then passes the signal onto the previous handler.
|
* After receiving a signal, Catch reports failing assertion and then passes the signal onto the previous handler.
|
||||||
* Approx can be used to compare values against strong typedefs (available in C++11 mode only).
|
* Approx can be used to compare values against strong typedefs (available in C++11 mode only).
|
||||||
@ -284,61 +324,63 @@ Other:
|
|||||||
* Certain characters (space, tab, etc) are now pretty printed.
|
* Certain characters (space, tab, etc) are now pretty printed.
|
||||||
* This means that a `char c = ' '; REQUIRE(c == '\t');` would be printed as `' ' == '\t'`, instead of ` == 9`.
|
* This means that a `char c = ' '; REQUIRE(c == '\t');` would be printed as `' ' == '\t'`, instead of ` == 9`.
|
||||||
|
|
||||||
### Fixes:
|
#### Fixes:
|
||||||
* Text formatting no longer attempts to access out-of-bounds characters under certain conditions.
|
* Text formatting no longer attempts to access out-of-bounds characters under certain conditions.
|
||||||
* THROW family of assertions no longer trigger `-Wunused-value` on expressions containing explicit cast.
|
* THROW family of assertions no longer trigger `-Wunused-value` on expressions containing explicit cast.
|
||||||
* Breaking into debugger under OS X works again and no longer required `DEBUG` to be defined.
|
* Breaking into debugger under OS X works again and no longer required `DEBUG` to be defined.
|
||||||
* Compilation no longer breaks under certain compiler if a lambda is used inside assertion macro.
|
* Compilation no longer breaks under certain compiler if a lambda is used inside assertion macro.
|
||||||
|
|
||||||
### Other:
|
#### Other:
|
||||||
* Catch's CMakeLists now defines install command.
|
* Catch's CMakeLists now defines install command.
|
||||||
* Catch's CMakeLists now generates projects with warnings enabled.
|
* Catch's CMakeLists now generates projects with warnings enabled.
|
||||||
|
|
||||||
|
|
||||||
## 1.6.1
|
## 1.6.x
|
||||||
|
|
||||||
### Features/ Changes:
|
### 1.6.1
|
||||||
|
|
||||||
|
#### Features/ Changes:
|
||||||
* Catch now supports breaking into debugger on Linux
|
* Catch now supports breaking into debugger on Linux
|
||||||
|
|
||||||
### Fixes:
|
#### Fixes:
|
||||||
* Generators no longer leak memory (generators are still unsupported in general)
|
* Generators no longer leak memory (generators are still unsupported in general)
|
||||||
* JUnit reporter now reports UTC timestamps, instead of "tbd"
|
* JUnit reporter now reports UTC timestamps, instead of "tbd"
|
||||||
* `CHECK_THAT` macro is now properly defined as `CATCH_CHECK_THAT` when using `CATCH_` prefixed macros
|
* `CHECK_THAT` macro is now properly defined as `CATCH_CHECK_THAT` when using `CATCH_` prefixed macros
|
||||||
|
|
||||||
### Other:
|
#### Other:
|
||||||
* Types with overloaded `&&` operator are no longer evaluated twice when used in an assertion macro.
|
* Types with overloaded `&&` operator are no longer evaluated twice when used in an assertion macro.
|
||||||
* The use of `__COUNTER__` is supressed when Catch is parsed by CLion
|
* The use of `__COUNTER__` is supressed when Catch is parsed by CLion
|
||||||
* This change is not active when compiling a binary
|
* This change is not active when compiling a binary
|
||||||
* Approval tests can now be run on Windows
|
* Approval tests can now be run on Windows
|
||||||
* CMake will now warn if a file is present in the `include` folder but not is not enumerated as part of the project
|
* CMake will now warn if a file is present in the `include` folder but not is not enumerated as part of the project
|
||||||
* Catch now defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including `windows.h`
|
* Catch now defines `NOMINMAX` and `WIN32_LEAN_AND_MEAN` before including `windows.h`
|
||||||
* This can be disabled if needed, see [documentation](configuration.md) for details.
|
* This can be disabled if needed, see [documentation](configuration.md#top) for details.
|
||||||
|
|
||||||
|
|
||||||
## 1.6.0
|
### 1.6.0
|
||||||
|
|
||||||
### Cmake/ projects:
|
#### Cmake/ projects:
|
||||||
* Moved CMakeLists.txt to root, made it friendlier for CLion and generating XCode and VS projects, and removed the manually maintained XCode and VS projects.
|
* Moved CMakeLists.txt to root, made it friendlier for CLion and generating XCode and VS projects, and removed the manually maintained XCode and VS projects.
|
||||||
|
|
||||||
### Features/ Changes:
|
#### Features/ Changes:
|
||||||
* Approx now supports `>=` and `<=`
|
* Approx now supports `>=` and `<=`
|
||||||
* Can now use `\` to escape chars in test names on command line
|
* Can now use `\` to escape chars in test names on command line
|
||||||
* Standardize C++11 feature toggles
|
* Standardize C++11 feature toggles
|
||||||
|
|
||||||
### Fixes:
|
#### Fixes:
|
||||||
* Blue shell colour
|
* Blue shell colour
|
||||||
* Missing argument to `CATCH_CHECK_THROWS`
|
* Missing argument to `CATCH_CHECK_THROWS`
|
||||||
* Don't encode extended ASCII in XML
|
* Don't encode extended ASCII in XML
|
||||||
* use `std::shuffle` on more compilers (fixes deprecation warning/error)
|
* use `std::shuffle` on more compilers (fixes deprecation warning/error)
|
||||||
* Use `__COUNTER__` more consistently (where available)
|
* Use `__COUNTER__` more consistently (where available)
|
||||||
|
|
||||||
### Other:
|
#### Other:
|
||||||
* Tweaks and changes to scripts - particularly for Approval test - to make them more portable
|
* Tweaks and changes to scripts - particularly for Approval test - to make them more portable
|
||||||
|
|
||||||
|
|
||||||
# Older versions
|
# Even Older versions
|
||||||
Release notes were not maintained prior to v1.6.0, but you should be able to work them out from the Git history
|
Release notes were not maintained prior to v1.6.0, but you should be able to work them out from the Git history
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# How to release
|
# How to release
|
||||||
|
|
||||||
When enough changes have accumulated, it is time to release new version of Catch. This document describes the proces in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `scripts/` directory.
|
When enough changes have accumulated, it is time to release new version of Catch. This document describes the proces in doing so, that no steps are forgotten. Note that all referenced scripts can be found in the `scripts/` directory.
|
||||||
@ -16,7 +17,7 @@ There should be no differences, as Approval tests should be updated when changes
|
|||||||
|
|
||||||
### Incrementing version number
|
### Incrementing version number
|
||||||
|
|
||||||
Catch uses a variant of [semantic versioning](http://semver.org/), with breaking API changes (and thus major version increments) being very rare. Thus, the release will usually increment the patch version, when it only contains couple of bugfixes, or minor version, when it contains new functionality, or larger changes in implementation of current functionality.
|
Catch uses a variant of [semantic versioning](http://semver.org/), with breaking API changes (and thus major version increments) being very rare. Thus, the release will usually increment the patch version, when it only contains couple of bugfixes, or minor version, when it contains new functionality, or larger changes in implementation of current functionality.
|
||||||
|
|
||||||
After deciding which part of version number should be incremented, you can use one of the `*Release.py` scripts to perform the required changes to Catch.
|
After deciding which part of version number should be incremented, you can use one of the `*Release.py` scripts to perform the required changes to Catch.
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ Once a release is ready, release notes need to be written. They should summarize
|
|||||||
|
|
||||||
### Commit and push update to GitHub
|
### Commit and push update to GitHub
|
||||||
|
|
||||||
After version number is incremented, single-include header is regenerated and release notes are updated, changes should be commited and pushed to GitHub.
|
After version number is incremented, single-include header is regenerated and release notes are updated, changes should be commited and pushed to GitHub.
|
||||||
|
|
||||||
|
|
||||||
### Release on GitHub
|
### Release on GitHub
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Reporters
|
# Reporters
|
||||||
|
|
||||||
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
|
Catch has a modular reporting system and comes bundled with a handful of useful reporters built in.
|
||||||
@ -17,12 +18,12 @@ There are four reporters built in to the single include:
|
|||||||
|
|
||||||
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
|
* `console` writes as lines of text, formatted to a typical terminal width, with colours if a capable terminal is detected.
|
||||||
* `compact` similar to `console` but optimised for minimal output - each entry on one line
|
* `compact` similar to `console` but optimised for minimal output - each entry on one line
|
||||||
* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit. If you are using Jenkins with Catch 1.x, you can improve quality of output by applying changes in [#923](https://github.com/philsquared/Catch/pull/923).
|
* `junit` writes xml that corresponds to Ant's [junitreport](http://help.catchsoftware.com/display/ET/JUnit+Format) target. Useful for build systems that understand Junit.
|
||||||
Because of the way the junit format is structured the run must complete before anything is written.
|
Because of the way the junit format is structured the run must complete before anything is written.
|
||||||
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
|
* `xml` writes an xml format tailored to Catch. Unlike `junit` this is a streaming format so results are delivered progressively.
|
||||||
|
|
||||||
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
|
There are a few additional reporters, for specific build systems, in the Catch repository (in `include\reporters`) which you can `#include` in your project if you would like to make use of them.
|
||||||
Do this in one source file - typically the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
|
Do this in one source file - the same one you have `CATCH_CONFIG_MAIN` or `CATCH_CONFIG_RUNNER`.
|
||||||
|
|
||||||
* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
|
* `teamcity` writes the native, streaming, format that [TeamCity](https://www.jetbrains.com/teamcity/) understands.
|
||||||
Use this when building as part of a TeamCity build to see results as they happen.
|
Use this when building as part of a TeamCity build to see results as they happen.
|
||||||
@ -42,4 +43,4 @@ but do keep in mind upcoming changes (these will be minor, simplifying, changes
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,5 +1,12 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Why do my tests take so long to compile?
|
# Why do my tests take so long to compile?
|
||||||
|
|
||||||
|
**Contents**<br>
|
||||||
|
[Short answer](#short-answer)<br>
|
||||||
|
[Long answer](#long-answer)<br>
|
||||||
|
[Practical example](#practical-example)<br>
|
||||||
|
[Other possible solutions](#other-possible-solutions)<br>
|
||||||
|
|
||||||
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
|
Several people have reported that test code written with Catch takes much longer to compile than they would expect. Why is that?
|
||||||
|
|
||||||
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
|
Catch is implemented entirely in headers. There is a little overhead due to this - but not as much as you might think - and you can minimise it simply by organising your test code as follows:
|
||||||
@ -18,7 +25,7 @@ Because Catch is implemented *entirely* in headers you might think that the whol
|
|||||||
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch
|
As a result the main source file *does* compile the whole of Catch every time! So it makes sense to dedicate this file to *only* ```#define```-ing the identifier and ```#include```-ing Catch (and implementing the runner code, if you're doing that). Keep all your test cases in other files. This way you won't pay the recompilation cost for the whole of Catch
|
||||||
|
|
||||||
## Practical example
|
## Practical example
|
||||||
Assume you have the `Factorial` function from the [tutorial](tutorial.md) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
|
Assume you have the `Factorial` function from the [tutorial](tutorial.md#top) in `factorial.cpp` (with forward declaration in `factorial.h`) and want to test it and keep the compile times down when adding new tests. Then you should have 2 files, `tests-main.cpp` and `tests-factorial.cpp`:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
// tests-main.cpp
|
// tests-main.cpp
|
||||||
@ -61,4 +68,4 @@ You can also opt to sacrifice some features in order to speed-up Catch's compila
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Test cases and sections
|
# Test cases and sections
|
||||||
|
|
||||||
While Catch fully supports the traditional, xUnit, style of class-based fixtures containing test case methods this is not the preferred style.
|
While Catch fully supports the traditional, xUnit, style of class-based fixtures containing test case methods this is not the preferred style.
|
||||||
@ -11,7 +12,7 @@ Test cases and sections are very easy to use in practice:
|
|||||||
|
|
||||||
_test name_ and _section name_ are free form, quoted, strings. The optional _tags_ argument is a quoted string containing one or more tags enclosed in square brackets. Tags are discussed below. Test names must be unique within the Catch executable.
|
_test name_ and _section name_ are free form, quoted, strings. The optional _tags_ argument is a quoted string containing one or more tags enclosed in square brackets. Tags are discussed below. Test names must be unique within the Catch executable.
|
||||||
|
|
||||||
For examples see the [Tutorial](tutorial.md)
|
For examples see the [Tutorial](tutorial.md#top)
|
||||||
|
|
||||||
## Tags
|
## Tags
|
||||||
|
|
||||||
@ -34,7 +35,7 @@ Tag names are not case sensitive and can contain any ASCII characters. This mean
|
|||||||
|
|
||||||
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
|
All tag names beginning with non-alphanumeric characters are reserved by Catch. Catch defines a number of "special" tags, which have meaning to the test runner itself. These special tags all begin with a symbol character. Following is a list of currently defined special tags and their meanings.
|
||||||
|
|
||||||
* `[!hide]` or `[.]` (or, for legacy reasons, `[hide]`) - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`. Because the hide tag has evolved to have several forms, all forms are added as tags if you use one of them.
|
* `[!hide]` or `[.]` - causes test cases to be skipped from the default list (i.e. when no test cases have been explicitly selected through tag expressions or name wildcards). The hide tag is often combined with another, user, tag (for example `[.][integration]` - so all integration tests are excluded from the default run but can be run by passing `[integration]` on the command line). As a short-cut you can combine these by simply prefixing your user tag with a `.` - e.g. `[.integration]`. Because the hide tag has evolved to have several forms, all forms are added as tags if you use one of them.
|
||||||
|
|
||||||
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
|
* `[!throws]` - lets Catch know that this test is likely to throw an exception even if successful. This causes the test to be excluded when running with `-e` or `--nothrow`.
|
||||||
|
|
||||||
@ -48,6 +49,8 @@ All tag names beginning with non-alphanumeric characters are reserved by Catch.
|
|||||||
|
|
||||||
* `[@<alias>]` - tag aliases all begin with `@` (see below).
|
* `[@<alias>]` - tag aliases all begin with `@` (see below).
|
||||||
|
|
||||||
|
* `[!benchmark]` - this test case is actually a benchmark. This is an experimental feature, and currently has no documentation. If you want to try it out, look at `projects/SelfTest/Benchmark.tests.cpp` for details.
|
||||||
|
|
||||||
## Tag aliases
|
## Tag aliases
|
||||||
|
|
||||||
Between tag expressions and wildcarded test names (as well as combinations of the two) quite complex patterns can be constructed to direct which test cases are run. If a complex pattern is used often it is convenient to be able to create an alias for the expression. This can be done, in code, using the following form:
|
Between tag expressions and wildcarded test names (as well as combinations of the two) quite complex patterns can be constructed to direct which test cases are run. If a complex pattern is used often it is convenient to be able to create an alias for the expression. This can be done, in code, using the following form:
|
||||||
@ -85,4 +88,4 @@ Other than the additional prefixes and the formatting in the console reporter th
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
<a id="top"></a>
|
||||||
|
# Test fixtures
|
||||||
|
|
||||||
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
|
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
@ -29,4 +32,4 @@ The two test cases here will create uniquely-named derived classes of UniqueTest
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# String conversions
|
# String conversions
|
||||||
|
|
||||||
Catch needs to be able to convert types you use in assertions and logging expressions into strings (for logging and reporting purposes).
|
Catch needs to be able to convert types you use in assertions and logging expressions into strings (for logging and reporting purposes).
|
||||||
Most built-in or std types are supported out of the box but there are three ways that you can tell Catch how to convert your own types (or other, third-party types) into strings.
|
Most built-in or std types are supported out of the box but there are two ways that you can tell Catch how to convert your own types (or other, third-party types) into strings.
|
||||||
|
|
||||||
## operator << overload for std::ostream
|
## operator << overload for std::ostream
|
||||||
|
|
||||||
@ -16,34 +17,19 @@ std::ostream& operator << ( std::ostream& os, T const& value ) {
|
|||||||
|
|
||||||
(where ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable - it doesn't have to be in another function).
|
(where ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable - it doesn't have to be in another function).
|
||||||
|
|
||||||
You should put this function in the same namespace as your type and it has to be declared before including Catch's header.
|
You should put this function in the same namespace as your type and have it declared before including Catch's header.
|
||||||
|
|
||||||
## Catch::toString overload
|
|
||||||
|
|
||||||
If you don't want to provide an ```operator <<``` overload, or you want to convert your type differently for testing purposes, you can provide an overload for ```Catch::toString()``` for your type.
|
|
||||||
|
|
||||||
```
|
|
||||||
namespace Catch {
|
|
||||||
std::string toString( T const& value ) {
|
|
||||||
return convertMyTypeToString( value );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
Again ```T``` is your type and ```convertMyTypeToString``` is where you'll write whatever code is necessary to make your type printable. Note that the function must be in the Catch namespace, which itself must be in the global namespace and must be declared _before_ Catch's header is included.
|
|
||||||
|
|
||||||
**Please note that overloading `Catch::toString` is currently considered legacy and will not be supported in the next major version of Catch.**
|
|
||||||
|
|
||||||
## Catch::StringMaker<T> specialisation
|
## Catch::StringMaker<T> specialisation
|
||||||
Another way of telling Catch how to convert a type to string is specialising `Catch::StringMaker` template. This allows you to have separate way of stringifying types for Catch, than you have for writing it to a stream and also doesn't require you to declare it before including Catch's header.
|
If you don't want to provide an ```operator <<``` overload, or you want to convert your type differently for testing purposes, you can provide a specialization for `Catch::StringMaker<T>`:
|
||||||
|
|
||||||
```
|
```
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
template<> struct StringMaker<T> {
|
template<>
|
||||||
|
struct StringMaker<T> {
|
||||||
static std::string convert( T const& value ) {
|
static std::string convert( T const& value ) {
|
||||||
return convertMyTypeToString( value );
|
return convertMyTypeToString( value );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -59,4 +45,4 @@ CATCH_TRANSLATE_EXCEPTION( MyType& ex ) {
|
|||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
# Getting Catch
|
<a id="top"></a>
|
||||||
|
# Tutorial
|
||||||
|
|
||||||
|
**Contents**<br>
|
||||||
|
[Getting Catch](#getting-catch)<br>
|
||||||
|
[Where to put it?](#where-to-put-it)<br>
|
||||||
|
[Writing tests](#writing-tests)<br>
|
||||||
|
[Test cases and sections](#test-cases-and-sections)<br>
|
||||||
|
[BDD-Style](#bdd-style)<br>
|
||||||
|
[Scaling up](#scaling-up)<br>
|
||||||
|
[Next steps](#next-steps)<br>
|
||||||
|
|
||||||
|
## Getting Catch
|
||||||
|
|
||||||
The simplest way to get Catch is to download the latest [single header version](https://raw.githubusercontent.com/philsquared/Catch/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.
|
The simplest way to get Catch is to download the latest [single header version](https://raw.githubusercontent.com/philsquared/Catch/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.
|
||||||
|
|
||||||
@ -11,7 +23,7 @@ Catch is header only. All you need to do is drop the file(s) somewhere reachable
|
|||||||
|
|
||||||
The rest of this tutorial will assume that the Catch single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
|
The rest of this tutorial will assume that the Catch single-include header (or the include folder) is available unqualified - but you may need to prefix it with a folder name if necessary.
|
||||||
|
|
||||||
# Writing tests
|
## Writing tests
|
||||||
|
|
||||||
Let's start with a really simple example. Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).
|
Let's start with a really simple example. Say you have written a function to calculate factorials and now you want to test it (let's leave aside TDD for now).
|
||||||
|
|
||||||
@ -39,7 +51,7 @@ TEST_CASE( "Factorials are computed", "[factorial]" ) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
This will compile to a complete executable which responds to [command line arguments](command-line.md). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
|
This will compile to a complete executable which responds to [command line arguments](command-line.md#top). If you just run it with no arguments it will execute all test cases (in this case there is just one), report any failures, report a summary of how many tests passed and failed and return the number of failed tests (useful for if you just want a yes/ no answer to: "did it work").
|
||||||
|
|
||||||
If you run this as written it will pass. Everything is good. Right?
|
If you run this as written it will pass. Everything is good. Right?
|
||||||
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
|
Well, there is still a bug here. In fact the first version of this tutorial I posted here genuinely had the bug in! So it's not completely contrived (thanks to Daryle Walker (```@CTMacUser```) for pointing this out).
|
||||||
@ -82,12 +94,12 @@ Now all the tests pass.
|
|||||||
|
|
||||||
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
|
Of course there are still more issues to deal with. For example we'll hit problems when the return value starts to exceed the range of an unsigned int. With factorials that can happen quite quickly. You might want to add tests for such cases and decide how to handle them. We'll stop short of doing that here.
|
||||||
|
|
||||||
## What did we do here?
|
### What did we do here?
|
||||||
|
|
||||||
Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take moment to consider those before we move on.
|
Although this was a simple test it's been enough to demonstrate a few things about how Catch is used. Let's take moment to consider those before we move on.
|
||||||
|
|
||||||
1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md)).
|
1. All we did was ```#define``` one identifier and ```#include``` one header and we got everything - even an implementation of ```main()``` that will [respond to command line arguments](command-line.md#top). You can only use that ```#define``` in one implementation file, for (hopefully) obvious reasons. Once you have more than one file with unit tests in you'll just ```#include "catch.hpp"``` and go. Usually it's a good idea to have a dedicated implementation file that just has ```#define CATCH_CONFIG_MAIN``` and ```#include "catch.hpp"```. You can also provide your own implementation of main and drive Catch yourself (see [Supplying-your-own-main()](own-main.md#top)).
|
||||||
2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>, ). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md) for more information on running tests.
|
2. We introduce test cases with the ```TEST_CASE``` macro. This macro takes one or two arguments - a free form test name and, optionally, one or more tags (for more see <a href="#test-cases-and-sections">Test cases and Sections</a>, ). The test name must be unique. You can run sets of tests by specifying a wildcarded test name or a tag expression. See the [command line docs](command-line.md#top) for more information on running tests.
|
||||||
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
|
3. The name and tags arguments are just strings. We haven't had to declare a function or method - or explicitly register the test case anywhere. Behind the scenes a function with a generated name is defined for you, and automatically registered using static registry classes. By abstracting the function name away we can name our tests without the constraints of identifier names.
|
||||||
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
|
4. We write our individual test assertions using the ```REQUIRE``` macro. Rather than a separate macro for each type of condition we express the condition naturally using C/C++ syntax. Behind the scenes a simple set of expression templates captures the left-hand-side and right-hand-side of the expression so we can display the values in our test report. As we'll see later there _are_ other assertion macros - but because of this technique the number of them is drastically reduced.
|
||||||
|
|
||||||
@ -161,7 +173,7 @@ Sections can be nested to an arbitrary depth (limited only by your stack size).
|
|||||||
|
|
||||||
## BDD-Style
|
## BDD-Style
|
||||||
|
|
||||||
If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md).
|
If you name your test cases and sections appropriately you can achieve a BDD-style specification structure. This became such a useful way of working that first class support has been added to Catch. Scenarios can be specified using ```SCENARIO```, ```GIVEN```, ```WHEN``` and ```THEN``` macros, which map on to ```TEST_CASE```s and ```SECTION```s, respectively. For more details see [Test cases and sections](test-cases-and-sections.md#top).
|
||||||
|
|
||||||
The vector example can be adjusted to use these macros like so:
|
The vector example can be adjusted to use these macros like so:
|
||||||
|
|
||||||
@ -224,7 +236,7 @@ Scenario: vectors can be sized and resized
|
|||||||
|
|
||||||
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
|
To keep the tutorial simple we put all our code in a single file. This is fine to get started - and makes jumping into Catch even quicker and easier. As you write more real-world tests, though, this is not really the best approach.
|
||||||
|
|
||||||
The requirement is that the following block of code ([or equivalent](own-main.md)):
|
The requirement is that the following block of code ([or equivalent](own-main.md#top)):
|
||||||
|
|
||||||
```c++
|
```c++
|
||||||
#define CATCH_CONFIG_MAIN
|
#define CATCH_CONFIG_MAIN
|
||||||
@ -233,7 +245,7 @@ The requirement is that the following block of code ([or equivalent](own-main.md
|
|||||||
|
|
||||||
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
|
appears in _exactly one_ source file. Use as many additional cpp files (or whatever you call your implementation files) as you need for your tests, partitioned however makes most sense for your way of working. Each additional file need only ```#include "catch.hpp"``` - do not repeat the ```#define```!
|
||||||
|
|
||||||
In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md).
|
In fact it is usually a good idea to put the block with the ```#define``` [in its own source file](slow-compiles.md#top).
|
||||||
|
|
||||||
Do not write your tests in header files!
|
Do not write your tests in header files!
|
||||||
|
|
||||||
@ -242,8 +254,8 @@ Do not write your tests in header files!
|
|||||||
|
|
||||||
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
|
This has been a brief introduction to get you up and running with Catch, and to point out some of the key differences between Catch and other frameworks you may already be familiar with. This will get you going quite far already and you are now in a position to dive in and write some tests.
|
||||||
|
|
||||||
Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md) for what's available.
|
Of course there is more to learn - most of which you should be able to page-fault in as you go. Please see the ever-growing [Reference section](Readme.md#top) for what's available.
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -1,46 +1,46 @@
|
|||||||
|
<a id="top"></a>
|
||||||
# Why do we need yet another C++ test framework?
|
# Why do we need yet another C++ test framework?
|
||||||
|
|
||||||
Good question. For C++ there are quite a number of established frameworks, including (but not limited to), [CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page), [Google Test](http://code.google.com/p/googletest/), [Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html), [Aeryn](https://launchpad.net/aeryn), [Cute](http://r2.ifs.hsr.ch/cute), [Fructose](http://fructose.sourceforge.net/) and [many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B). Even for Objective-C there are a few, including OCUnit - which now comes bundled with XCode.
|
Good question. For C++ there are quite a number of established frameworks,
|
||||||
|
including (but not limited to),
|
||||||
|
[Google Test](http://code.google.com/p/googletest/),
|
||||||
|
[Boost.Test](http://www.boost.org/doc/libs/1_49_0/libs/test/doc/html/index.html),
|
||||||
|
[CppUnit](http://sourceforge.net/apps/mediawiki/cppunit/index.php?title=Main_Page),
|
||||||
|
[Cute](http://r2.ifs.hsr.ch/cute),
|
||||||
|
[many, many more](http://en.wikipedia.org/wiki/List_of_unit_testing_frameworks#C.2B.2B).
|
||||||
|
|
||||||
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
|
So what does Catch bring to the party that differentiates it from these? Apart from a Catchy name, of course.
|
||||||
|
|
||||||
## Key Features
|
## Key Features
|
||||||
|
|
||||||
* Really easy to get started. Just download catch.hpp, #include it and you're away.
|
* Quick and Really easy to get started. Just download catch.hpp, `#include` it and you're away.
|
||||||
* No external dependencies. As long as you can compile C++98 and have a C++ standard library available.
|
* No external dependencies. As long as you can compile C++11 and have a C++ standard library available.
|
||||||
* Write test cases as, self-registering, functions or methods.
|
* Write test cases as, self-registering, functions (or methods, if you prefer).
|
||||||
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures!)
|
* Divide test cases into sections, each of which is run in isolation (eliminates the need for fixtures).
|
||||||
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
|
* Use BDD-style Given-When-Then sections as well as traditional unit test cases.
|
||||||
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
|
* Only one core assertion macro for comparisons. Standard C/C++ operators are used for the comparison - yet the full expression is decomposed and lhs and rhs values are logged.
|
||||||
|
* Tests are named using free-form strings - no more couching names in legal identifiers.
|
||||||
|
|
||||||
## Other core features
|
## Other core features
|
||||||
|
|
||||||
* Tests are named using free-form strings - no more couching names in legal identifiers.
|
|
||||||
* Tests can be tagged for easily running ad-hoc groups of tests.
|
* Tests can be tagged for easily running ad-hoc groups of tests.
|
||||||
* Failures can (optionally) break into the debugger on Windows and Mac.
|
* Failures can (optionally) break into the debugger on Windows and Mac.
|
||||||
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
|
* Output is through modular reporter objects. Basic textual and XML reporters are included. Custom reporters can easily be added.
|
||||||
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
|
* JUnit xml output is supported for integration with third-party tools, such as CI servers.
|
||||||
* A default main() function is provided (in a header), but you can supply your own for complete control (e.g. integration into your own test runner GUI).
|
* A default main() function is provided, but you can supply your own for complete control (e.g. integration into your own test runner GUI).
|
||||||
* A command line parser is provided and can still be used if you choose to provided your own main() function.
|
* A command line parser is provided and can still be used if you choose to provided your own main() function.
|
||||||
* Catch can test itself.
|
* Catch can test itself.
|
||||||
* Alternative assertion macro(s) report failures but don't abort the test case
|
* Alternative assertion macro(s) report failures but don't abort the test case
|
||||||
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
|
* Floating point tolerance comparisons are built in using an expressive Approx() syntax.
|
||||||
* Internal and friendly macros are isolated so name clashes can be managed
|
* Internal and friendly macros are isolated so name clashes can be managed
|
||||||
* Support for Matchers (early stages)
|
* Matchers
|
||||||
|
|
||||||
## Objective-C-specific features
|
|
||||||
|
|
||||||
* Automatically detects if you are using it from an Objective-C project
|
|
||||||
* Works with and without ARC with no additional configuration
|
|
||||||
* Implement test fixtures using Obj-C classes too (like OCUnit)
|
|
||||||
* Additional built in matchers that work with Obj-C types (e.g. string matchers)
|
|
||||||
|
|
||||||
## Who else is using Catch?
|
## Who else is using Catch?
|
||||||
|
|
||||||
See the list of [open source projects using Catch](opensource-users.md).
|
See the list of [open source projects using Catch](opensource-users.md#top).
|
||||||
|
|
||||||
See the [tutorial](tutorial.md) to get more of a taste of using CATCH in practice
|
See the [tutorial](tutorial.md#top) to get more of a taste of using Catch in practice
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
[Home](Readme.md)
|
[Home](Readme.md#top)
|
||||||
|
@ -19,8 +19,14 @@
|
|||||||
|
|
||||||
#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
|
#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER)
|
||||||
# define CATCH_IMPL
|
# define CATCH_IMPL
|
||||||
|
# define CATCH_CONFIG_EXTERNAL_INTERFACES
|
||||||
|
# if defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
# undef CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include "internal/catch_platform.h"
|
||||||
|
|
||||||
#ifdef CATCH_IMPL
|
#ifdef CATCH_IMPL
|
||||||
# ifndef CLARA_CONFIG_MAIN
|
# ifndef CLARA_CONFIG_MAIN
|
||||||
# define CLARA_CONFIG_MAIN_NOT_DEFINED
|
# define CLARA_CONFIG_MAIN_NOT_DEFINED
|
||||||
@ -28,18 +34,19 @@
|
|||||||
# endif
|
# endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "internal/catch_notimplemented_exception.h"
|
#include "internal/catch_tag_alias_autoregistrar.h"
|
||||||
#include "internal/catch_context.h"
|
#include "internal/catch_test_registry.h"
|
||||||
#include "internal/catch_test_registry.hpp"
|
|
||||||
#include "internal/catch_capture.hpp"
|
#include "internal/catch_capture.hpp"
|
||||||
#include "internal/catch_section.h"
|
#include "internal/catch_section.h"
|
||||||
#include "internal/catch_generators.hpp"
|
#include "internal/catch_benchmark.h"
|
||||||
#include "internal/catch_interfaces_exception.h"
|
#include "internal/catch_interfaces_exception.h"
|
||||||
#include "internal/catch_approx.hpp"
|
#include "internal/catch_approx.h"
|
||||||
#include "internal/catch_matchers_string.h"
|
|
||||||
#include "internal/catch_matchers_vector.h"
|
|
||||||
#include "internal/catch_compiler_capabilities.h"
|
#include "internal/catch_compiler_capabilities.h"
|
||||||
#include "internal/catch_interfaces_tag_alias_registry.h"
|
#include "internal/catch_string_manip.h"
|
||||||
|
|
||||||
|
#ifndef CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#include "internal/catch_capture_matchers.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
// These files are included here so the single_include script doesn't put them
|
// These files are included here so the single_include script doesn't put them
|
||||||
// in the conditionally compiled sections
|
// in the conditionally compiled sections
|
||||||
@ -50,30 +57,11 @@
|
|||||||
#include "internal/catch_objc.hpp"
|
#include "internal/catch_objc.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CATCH_IMPL
|
#ifdef CATCH_CONFIG_EXTERNAL_INTERFACES
|
||||||
|
#include "internal/catch_external_interfaces.h"
|
||||||
// !TBD: Move the leak detector code into a separate header
|
|
||||||
#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
|
|
||||||
#include <crtdbg.h>
|
|
||||||
class LeakDetector {
|
|
||||||
public:
|
|
||||||
LeakDetector() {
|
|
||||||
int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
|
||||||
flag |= _CRTDBG_LEAK_CHECK_DF;
|
|
||||||
flag |= _CRTDBG_ALLOC_MEM_DF;
|
|
||||||
_CrtSetDbgFlag(flag);
|
|
||||||
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
|
||||||
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
|
||||||
// Change this to leaking allocation's number to break there
|
|
||||||
_CrtSetBreakAlloc(-1);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
#else
|
|
||||||
class LeakDetector {};
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
LeakDetector leakDetector;
|
#ifdef CATCH_IMPL
|
||||||
|
|
||||||
#include "internal/catch_impl.hpp"
|
#include "internal/catch_impl.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -86,134 +74,105 @@ LeakDetector leakDetector;
|
|||||||
# undef CLARA_CONFIG_MAIN
|
# undef CLARA_CONFIG_MAIN
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE)
|
||||||
//////
|
//////
|
||||||
|
|
||||||
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
||||||
#ifdef CATCH_CONFIG_PREFIX_ALL
|
#ifdef CATCH_CONFIG_PREFIX_ALL
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
#define CATCH_REQUIRE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
#define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
|
#define CATCH_REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||||
#define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
|
|
||||||
#else
|
|
||||||
#define CATCH_REQUIRE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE", Catch::ResultDisposition::Normal, expr )
|
|
||||||
#define CATCH_REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define CATCH_REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
|
#define CATCH_REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", __VA_ARGS__ )
|
||||||
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
|
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
|
||||||
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
|
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
#define CATCH_REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
|
#endif// CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
|
||||||
#define CATCH_CHECK( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CATCH_CHECK( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CATCH_CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
|
#define CATCH_CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||||
#define CATCH_CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CATCH_CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CATCH_CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CATCH_CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CATCH_CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CATCH_CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CATCH_CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
|
#define CATCH_CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CATCH_CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||||
|
|
||||||
#define CATCH_CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
|
#define CATCH_CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", __VA_ARGS__ )
|
||||||
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CATCH_CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
|
||||||
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CATCH_CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
#define CATCH_CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CATCH_CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CATCH_CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
|
#define CATCH_CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
|
||||||
#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
|
||||||
#else
|
|
||||||
#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
#define CATCH_REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CATCH_REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
||||||
#endif
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
|
||||||
#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
|
#define CATCH_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
|
||||||
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
#define CATCH_WARN( msg ) INTERNAL_CATCH_MSG( "CATCH_WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
||||||
#define CATCH_SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "CATCH_INFO", msg )
|
#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) )
|
||||||
#define CATCH_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
|
|
||||||
#define CATCH_SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CATCH_CAPTURE", #msg " := " << Catch::toString(msg) )
|
|
||||||
|
|
||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
||||||
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
#define CATCH_METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
|
||||||
#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_REGISTER_TEST_CASE( Function, ... ) INTERNAL_CATCH_REGISTER_TESTCASE( Function, __VA_ARGS__ )
|
#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
|
||||||
#define CATCH_SECTION( ... ) INTERNAL_CATCH_SECTION( __VA_ARGS__ )
|
#define CATCH_FAIL( ... ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __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_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__ )
|
||||||
#define CATCH_SUCCEED( ... ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
|
||||||
#else
|
|
||||||
#define CATCH_TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
|
|
||||||
#define CATCH_TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
|
|
||||||
#define CATCH_METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
|
|
||||||
#define CATCH_REGISTER_TEST_CASE( function, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( function, name, description )
|
|
||||||
#define CATCH_SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
|
|
||||||
#define CATCH_FAIL( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
|
|
||||||
#define CATCH_FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "CATCH_FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
|
|
||||||
#define CATCH_SUCCEED( msg ) INTERNAL_CATCH_MSG( "CATCH_SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
|
|
||||||
#endif
|
|
||||||
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
|
|
||||||
|
|
||||||
#define CATCH_REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
|
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
|
||||||
#define CATCH_REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
|
|
||||||
|
|
||||||
#define CATCH_GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
|
|
||||||
|
|
||||||
// "BDD-style" convenience wrappers
|
// "BDD-style" convenience wrappers
|
||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
|
||||||
#define CATCH_SCENARIO( ... ) CATCH_TEST_CASE( "Scenario: " __VA_ARGS__ )
|
#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_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
||||||
#else
|
#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc )
|
||||||
#define CATCH_SCENARIO( name, tags ) CATCH_TEST_CASE( "Scenario: " name, tags )
|
#define CATCH_WHEN( desc ) CATCH_SECTION( std::string( " When: ") + desc )
|
||||||
#define CATCH_SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
|
#define CATCH_AND_WHEN( desc ) CATCH_SECTION( std::string( " And: ") + desc )
|
||||||
#endif
|
#define CATCH_THEN( desc ) CATCH_SECTION( std::string( " Then: ") + desc )
|
||||||
#define CATCH_GIVEN( desc ) CATCH_SECTION( std::string( "Given: ") + desc, "" )
|
#define CATCH_AND_THEN( desc ) CATCH_SECTION( std::string( " And: ") + 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, "" )
|
|
||||||
|
|
||||||
// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
|
// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
#define REQUIRE( ... ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
#define REQUIRE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE", Catch::ResultDisposition::Normal, expr )
|
#define REQUIRE_FALSE( ... ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||||
#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST_NO_TRY( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
|
|
||||||
|
|
||||||
#else
|
#define REQUIRE_THROWS( ... ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
#define REQUIRE( expr ) INTERNAL_CATCH_TEST( "REQUIRE", Catch::ResultDisposition::Normal, expr )
|
|
||||||
#define REQUIRE_FALSE( expr ) INTERNAL_CATCH_TEST( "REQUIRE_FALSE", Catch::ResultDisposition::Normal | Catch::ResultDisposition::FalseTest, expr )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define REQUIRE_THROWS( expr ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS", Catch::ResultDisposition::Normal, "", expr )
|
|
||||||
#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
|
#define REQUIRE_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "REQUIRE_THROWS_AS", exceptionType, Catch::ResultDisposition::Normal, expr )
|
||||||
#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
|
#define REQUIRE_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "REQUIRE_THROWS_WITH", Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
#define REQUIRE_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, expr )
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "REQUIRE_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::Normal, matcher, expr )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define REQUIRE_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "REQUIRE_NOTHROW", Catch::ResultDisposition::Normal, __VA_ARGS__ )
|
||||||
|
|
||||||
#define CHECK( expr ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CHECK( ... ) INTERNAL_CATCH_TEST( "CHECK", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CHECK_FALSE( expr ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, expr )
|
#define CHECK_FALSE( ... ) INTERNAL_CATCH_TEST( "CHECK_FALSE", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::FalseTest, __VA_ARGS__ )
|
||||||
#define CHECKED_IF( expr ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CHECKED_IF( ... ) INTERNAL_CATCH_IF( "CHECKED_IF", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CHECKED_ELSE( expr ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CHECKED_ELSE( ... ) INTERNAL_CATCH_ELSE( "CHECKED_ELSE", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CHECK_NOFAIL( expr ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, expr )
|
#define CHECK_NOFAIL( ... ) INTERNAL_CATCH_TEST( "CHECK_NOFAIL", Catch::ResultDisposition::ContinueOnFailure | Catch::ResultDisposition::SuppressFail, __VA_ARGS__ )
|
||||||
|
|
||||||
#define CHECK_THROWS( expr ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, "", expr )
|
#define CHECK_THROWS( ... ) INTERNAL_CATCH_THROWS( "CHECK_THROWS", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
|
#define CHECK_THROWS_AS( expr, exceptionType ) INTERNAL_CATCH_THROWS_AS( "CHECK_THROWS_AS", exceptionType, Catch::ResultDisposition::ContinueOnFailure, expr )
|
||||||
#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
#define CHECK_THROWS_WITH( expr, matcher ) INTERNAL_CATCH_THROWS_STR_MATCHES( "CHECK_THROWS_WITH", Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
#define CHECK_NOTHROW( expr ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, expr )
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) INTERNAL_CATCH_THROWS_MATCHES( "CHECK_THROWS_MATCHES", exceptionType, Catch::ResultDisposition::ContinueOnFailure, matcher, expr )
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CHECK_NOTHROW( ... ) INTERNAL_CATCH_NO_THROW( "CHECK_NOTHROW", Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
|
#define CHECK_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "CHECK_THAT", matcher, Catch::ResultDisposition::ContinueOnFailure, arg )
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
|
||||||
#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT_NO_TRY( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
|
||||||
#else
|
|
||||||
#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
#define REQUIRE_THAT( arg, matcher ) INTERNAL_CHECK_THAT( "REQUIRE_THAT", matcher, Catch::ResultDisposition::Normal, arg )
|
||||||
#endif
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
|
||||||
#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
|
#define INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
|
||||||
#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
#define WARN( msg ) INTERNAL_CATCH_MSG( "WARN", Catch::ResultWas::Warning, Catch::ResultDisposition::ContinueOnFailure, msg )
|
||||||
#define SCOPED_INFO( msg ) INTERNAL_CATCH_INFO( "INFO", msg )
|
#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << ::Catch::Detail::stringify(msg) )
|
||||||
#define CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
|
|
||||||
#define SCOPED_CAPTURE( msg ) INTERNAL_CATCH_INFO( "CAPTURE", #msg " := " << Catch::toString(msg) )
|
|
||||||
|
|
||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
|
||||||
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE( __VA_ARGS__ )
|
||||||
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, __VA_ARGS__ )
|
||||||
#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
|
#define METHOD_AS_TEST_CASE( method, ... ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, __VA_ARGS__ )
|
||||||
@ -222,43 +181,152 @@ LeakDetector leakDetector;
|
|||||||
#define FAIL( ... ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, __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 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__ )
|
#define SUCCEED( ... ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, __VA_ARGS__ )
|
||||||
#else
|
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE()
|
||||||
#define TEST_CASE( name, description ) INTERNAL_CATCH_TESTCASE( name, description )
|
|
||||||
#define TEST_CASE_METHOD( className, name, description ) INTERNAL_CATCH_TEST_CASE_METHOD( className, name, description )
|
|
||||||
#define METHOD_AS_TEST_CASE( method, name, description ) INTERNAL_CATCH_METHOD_AS_TEST_CASE( method, name, description )
|
|
||||||
#define REGISTER_TEST_CASE( method, name, description ) INTERNAL_CATCH_REGISTER_TESTCASE( method, name, description )
|
|
||||||
#define SECTION( name, description ) INTERNAL_CATCH_SECTION( name, description )
|
|
||||||
#define FAIL( msg ) INTERNAL_CATCH_MSG( "FAIL", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::Normal, msg )
|
|
||||||
#define FAIL_CHECK( msg ) INTERNAL_CATCH_MSG( "FAIL_CHECK", Catch::ResultWas::ExplicitFailure, Catch::ResultDisposition::ContinueOnFailure, msg )
|
|
||||||
#define SUCCEED( msg ) INTERNAL_CATCH_MSG( "SUCCEED", Catch::ResultWas::Ok, Catch::ResultDisposition::ContinueOnFailure, msg )
|
|
||||||
#endif
|
|
||||||
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE( "", "" )
|
|
||||||
|
|
||||||
#define REGISTER_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_REPORTER( name, reporterType )
|
|
||||||
#define REGISTER_LEGACY_REPORTER( name, reporterType ) INTERNAL_CATCH_REGISTER_LEGACY_REPORTER( name, reporterType )
|
|
||||||
|
|
||||||
#define GENERATE( expr) INTERNAL_CATCH_GENERATE( expr )
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
|
#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION( signature )
|
||||||
|
|
||||||
// "BDD-style" convenience wrappers
|
// "BDD-style" convenience wrappers
|
||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
|
||||||
#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
|
#define SCENARIO( ... ) TEST_CASE( "Scenario: " __VA_ARGS__ )
|
||||||
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " __VA_ARGS__ )
|
||||||
#else
|
|
||||||
#define SCENARIO( name, tags ) TEST_CASE( "Scenario: " name, tags )
|
#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc )
|
||||||
#define SCENARIO_METHOD( className, name, tags ) INTERNAL_CATCH_TEST_CASE_METHOD( className, "Scenario: " name, tags )
|
#define WHEN( desc ) SECTION( std::string(" When: ") + desc )
|
||||||
#endif
|
#define AND_WHEN( desc ) SECTION( std::string("And when: ") + desc )
|
||||||
#define GIVEN( desc ) SECTION( std::string(" Given: ") + desc, "" )
|
#define THEN( desc ) SECTION( std::string(" Then: ") + desc )
|
||||||
#define WHEN( desc ) SECTION( std::string(" When: ") + desc, "" )
|
#define AND_THEN( desc ) SECTION( std::string(" And: ") + 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, "" )
|
|
||||||
|
|
||||||
using Catch::Detail::Approx;
|
using Catch::Detail::Approx;
|
||||||
|
|
||||||
|
#else
|
||||||
|
//////
|
||||||
|
// If this config identifier is defined then all CATCH macros are prefixed with CATCH_
|
||||||
|
#ifdef CATCH_CONFIG_PREFIX_ALL
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE( ... ) (void)(0)
|
||||||
|
#define CATCH_REQUIRE_FALSE( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE_THROWS( ... ) (void)(0)
|
||||||
|
#define CATCH_REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define CATCH_REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif// CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_REQUIRE_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_CHECK( ... ) (void)(0)
|
||||||
|
#define CATCH_CHECK_FALSE( ... ) (void)(0)
|
||||||
|
#define CATCH_CHECKED_IF( ... ) if (__VA_ARGS__)
|
||||||
|
#define CATCH_CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
|
||||||
|
#define CATCH_CHECK_NOFAIL( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_CHECK_THROWS( ... ) (void)(0)
|
||||||
|
#define CATCH_CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define CATCH_CHECK_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CATCH_CHECK_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CATCH_CHECK_THAT( arg, matcher ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_REQUIRE_THAT( arg, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
#define CATCH_INFO( msg ) (void)(0)
|
||||||
|
#define CATCH_WARN( msg ) (void)(0)
|
||||||
|
#define CATCH_CAPTURE( msg ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define CATCH_TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define CATCH_METHOD_AS_TEST_CASE( method, ... )
|
||||||
|
#define CATCH_REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||||
|
#define CATCH_SECTION( ... )
|
||||||
|
#define CATCH_FAIL( ... ) (void)(0)
|
||||||
|
#define CATCH_FAIL_CHECK( ... ) (void)(0)
|
||||||
|
#define CATCH_SUCCEED( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CATCH_ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
|
||||||
|
// "BDD-style" convenience wrappers
|
||||||
|
#define CATCH_SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define CATCH_SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className )
|
||||||
|
#define CATCH_GIVEN( desc )
|
||||||
|
#define CATCH_WHEN( desc )
|
||||||
|
#define CATCH_AND_WHEN( desc )
|
||||||
|
#define CATCH_THEN( desc )
|
||||||
|
#define CATCH_AND_THEN( desc )
|
||||||
|
|
||||||
|
// If CATCH_CONFIG_PREFIX_ALL is not defined then the CATCH_ prefix is not required
|
||||||
|
#else
|
||||||
|
|
||||||
|
#define REQUIRE( ... ) (void)(0)
|
||||||
|
#define REQUIRE_FALSE( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define REQUIRE_THROWS( ... ) (void)(0)
|
||||||
|
#define REQUIRE_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define REQUIRE_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define REQUIRE_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define REQUIRE_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CHECK( ... ) (void)(0)
|
||||||
|
#define CHECK_FALSE( ... ) (void)(0)
|
||||||
|
#define CHECKED_IF( ... ) if (__VA_ARGS__)
|
||||||
|
#define CHECKED_ELSE( ... ) if (!(__VA_ARGS__))
|
||||||
|
#define CHECK_NOFAIL( ... ) (void)(0)
|
||||||
|
|
||||||
|
#define CHECK_THROWS( ... ) (void)(0)
|
||||||
|
#define CHECK_THROWS_AS( expr, exceptionType ) (void)(0)
|
||||||
|
#define CHECK_THROWS_WITH( expr, matcher ) (void)(0)
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THROWS_MATCHES( expr, exceptionType, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
#define CHECK_NOTHROW( ... ) (void)(0)
|
||||||
|
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE_MATCHERS)
|
||||||
|
#define CHECK_THAT( arg, matcher ) (void)(0)
|
||||||
|
|
||||||
|
#define REQUIRE_THAT( arg, matcher ) (void)(0)
|
||||||
|
#endif // CATCH_CONFIG_DISABLE_MATCHERS
|
||||||
|
|
||||||
|
#define INFO( msg ) (void)(0)
|
||||||
|
#define WARN( msg ) (void)(0)
|
||||||
|
#define CAPTURE( msg ) (void)(0)
|
||||||
|
|
||||||
|
#define TEST_CASE( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define TEST_CASE_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
#define METHOD_AS_TEST_CASE( method, ... )
|
||||||
|
#define REGISTER_TEST_CASE( Function, ... ) (void)(0)
|
||||||
|
#define SECTION( ... )
|
||||||
|
#define FAIL( ... ) (void)(0)
|
||||||
|
#define FAIL_CHECK( ... ) (void)(0)
|
||||||
|
#define SUCCEED( ... ) (void)(0)
|
||||||
|
#define ANON_TEST_CASE() INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ))
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define CATCH_TRANSLATE_EXCEPTION( signature ) INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( INTERNAL_CATCH_UNIQUE_NAME( catch_internal_ExceptionTranslator ), signature )
|
||||||
|
|
||||||
|
// "BDD-style" convenience wrappers
|
||||||
|
#define SCENARIO( ... ) INTERNAL_CATCH_TESTCASE_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ) )
|
||||||
|
#define SCENARIO_METHOD( className, ... ) INTERNAL_CATCH_TESTCASE_METHOD_NO_REGISTRATION(INTERNAL_CATCH_UNIQUE_NAME( ____C_A_T_C_H____T_E_S_T____ ), className )
|
||||||
|
|
||||||
|
#define GIVEN( desc )
|
||||||
|
#define WHEN( desc )
|
||||||
|
#define AND_WHEN( desc )
|
||||||
|
#define THEN( desc )
|
||||||
|
#define AND_THEN( desc )
|
||||||
|
|
||||||
|
using Catch::Detail::Approx;
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "internal/catch_reenable_warnings.h"
|
#include "internal/catch_reenable_warnings.h"
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_HPP_INCLUDED
|
||||||
|
1054
include/external/clara.h
vendored
1054
include/external/clara.h
vendored
File diff suppressed because it is too large
Load Diff
1232
include/external/clara.hpp
vendored
Normal file
1232
include/external/clara.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
168
include/external/tbc_text_format.h
vendored
168
include/external/tbc_text_format.h
vendored
@ -1,168 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 18/4/2013.
|
|
||||||
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
// Only use header guard if we are not using an outer namespace
|
|
||||||
#ifndef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
|
|
||||||
# ifdef TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
|
|
||||||
# ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
|
|
||||||
# define TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
|
|
||||||
# endif
|
|
||||||
# else
|
|
||||||
# define TWOBLUECUBES_TEXT_FORMAT_H_INCLUDED
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
#ifndef TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <sstream>
|
|
||||||
|
|
||||||
// Use optional outer namespace
|
|
||||||
#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
|
|
||||||
namespace CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Tbc {
|
|
||||||
|
|
||||||
#ifdef TBC_TEXT_FORMAT_CONSOLE_WIDTH
|
|
||||||
const unsigned int consoleWidth = TBC_TEXT_FORMAT_CONSOLE_WIDTH;
|
|
||||||
#else
|
|
||||||
const unsigned int consoleWidth = 80;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct TextAttributes {
|
|
||||||
TextAttributes()
|
|
||||||
: initialIndent( std::string::npos ),
|
|
||||||
indent( 0 ),
|
|
||||||
width( consoleWidth-1 )
|
|
||||||
{}
|
|
||||||
|
|
||||||
TextAttributes& setInitialIndent( std::size_t _value ) { initialIndent = _value; return *this; }
|
|
||||||
TextAttributes& setIndent( std::size_t _value ) { indent = _value; return *this; }
|
|
||||||
TextAttributes& setWidth( std::size_t _value ) { width = _value; return *this; }
|
|
||||||
|
|
||||||
std::size_t initialIndent; // indent of first line, or npos
|
|
||||||
std::size_t indent; // indent of subsequent lines, or all if initialIndent is npos
|
|
||||||
std::size_t width; // maximum width of text, including indent. Longer text will wrap
|
|
||||||
};
|
|
||||||
|
|
||||||
class Text {
|
|
||||||
public:
|
|
||||||
Text( std::string const& _str, TextAttributes const& _attr = TextAttributes() )
|
|
||||||
: attr( _attr )
|
|
||||||
{
|
|
||||||
const std::string wrappableBeforeChars = "[({<\t";
|
|
||||||
const std::string wrappableAfterChars = "])}>-,./|\\";
|
|
||||||
const std::string wrappableInsteadOfChars = " \n\r";
|
|
||||||
std::string indent = _attr.initialIndent != std::string::npos
|
|
||||||
? std::string( _attr.initialIndent, ' ' )
|
|
||||||
: std::string( _attr.indent, ' ' );
|
|
||||||
|
|
||||||
typedef std::string::const_iterator iterator;
|
|
||||||
iterator it = _str.begin();
|
|
||||||
const iterator strEnd = _str.end();
|
|
||||||
|
|
||||||
while( it != strEnd ) {
|
|
||||||
|
|
||||||
if( lines.size() >= 1000 ) {
|
|
||||||
lines.push_back( "... message truncated due to excessive size" );
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::string suffix;
|
|
||||||
std::size_t width = (std::min)( static_cast<size_t>( strEnd-it ), _attr.width-static_cast<size_t>( indent.size() ) );
|
|
||||||
iterator itEnd = it+width;
|
|
||||||
iterator itNext = _str.end();
|
|
||||||
|
|
||||||
iterator itNewLine = std::find( it, itEnd, '\n' );
|
|
||||||
if( itNewLine != itEnd )
|
|
||||||
itEnd = itNewLine;
|
|
||||||
|
|
||||||
if( itEnd != strEnd ) {
|
|
||||||
bool foundWrapPoint = false;
|
|
||||||
iterator findIt = itEnd;
|
|
||||||
do {
|
|
||||||
if( wrappableAfterChars.find( *findIt ) != std::string::npos && findIt != itEnd ) {
|
|
||||||
itEnd = findIt+1;
|
|
||||||
itNext = findIt+1;
|
|
||||||
foundWrapPoint = true;
|
|
||||||
}
|
|
||||||
else if( findIt > it && wrappableBeforeChars.find( *findIt ) != std::string::npos ) {
|
|
||||||
itEnd = findIt;
|
|
||||||
itNext = findIt;
|
|
||||||
foundWrapPoint = true;
|
|
||||||
}
|
|
||||||
else if( wrappableInsteadOfChars.find( *findIt ) != std::string::npos ) {
|
|
||||||
itNext = findIt+1;
|
|
||||||
itEnd = findIt;
|
|
||||||
foundWrapPoint = true;
|
|
||||||
}
|
|
||||||
if( findIt == it )
|
|
||||||
break;
|
|
||||||
else
|
|
||||||
--findIt;
|
|
||||||
}
|
|
||||||
while( !foundWrapPoint );
|
|
||||||
|
|
||||||
if( !foundWrapPoint ) {
|
|
||||||
// No good wrap char, so we'll break mid word and add a hyphen
|
|
||||||
--itEnd;
|
|
||||||
itNext = itEnd;
|
|
||||||
suffix = "-";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
while( itEnd > it && wrappableInsteadOfChars.find( *(itEnd-1) ) != std::string::npos )
|
|
||||||
--itEnd;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
lines.push_back( indent + std::string( it, itEnd ) + suffix );
|
|
||||||
|
|
||||||
if( indent.size() != _attr.indent )
|
|
||||||
indent = std::string( _attr.indent, ' ' );
|
|
||||||
it = itNext;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef std::vector<std::string>::const_iterator const_iterator;
|
|
||||||
|
|
||||||
const_iterator begin() const { return lines.begin(); }
|
|
||||||
const_iterator end() const { return lines.end(); }
|
|
||||||
std::string const& last() const { return lines.back(); }
|
|
||||||
std::size_t size() const { return lines.size(); }
|
|
||||||
std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
|
|
||||||
std::string toString() const {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << *this;
|
|
||||||
return oss.str();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline friend std::ostream& operator << ( std::ostream& _stream, Text const& _text ) {
|
|
||||||
for( Text::const_iterator it = _text.begin(), itEnd = _text.end();
|
|
||||||
it != itEnd; ++it ) {
|
|
||||||
if( it != _text.begin() )
|
|
||||||
_stream << "\n";
|
|
||||||
_stream << *it;
|
|
||||||
}
|
|
||||||
return _stream;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::string str;
|
|
||||||
TextAttributes attr;
|
|
||||||
std::vector<std::string> lines;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // end namespace Tbc
|
|
||||||
|
|
||||||
#ifdef CLICHE_TBC_TEXT_FORMAT_OUTER_NAMESPACE
|
|
||||||
} // end outer namespace
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_TEXT_FORMAT_H_ALREADY_INCLUDED
|
|
56
include/internal/catch_approx.cpp
Normal file
56
include/internal/catch_approx.cpp
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 19/07/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_approx.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
// Performs equivalent check of std::fabs(lhs - rhs) <= margin
|
||||||
|
// But without the subtraction to allow for INFINITY in comparison
|
||||||
|
bool marginComparison(double lhs, double rhs, double margin) {
|
||||||
|
return (lhs + margin >= rhs) && (rhs + margin >= lhs);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
|
Approx::Approx ( double value )
|
||||||
|
: m_epsilon( std::numeric_limits<float>::epsilon()*100 ),
|
||||||
|
m_margin( 0.0 ),
|
||||||
|
m_scale( 0.0 ),
|
||||||
|
m_value( value )
|
||||||
|
{}
|
||||||
|
|
||||||
|
Approx Approx::custom() {
|
||||||
|
return Approx( 0 );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string Approx::toString() const {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Approx( " << ::Catch::Detail::stringify( m_value ) << " )";
|
||||||
|
return oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Approx::equalityComparisonImpl(const double other) const {
|
||||||
|
// First try with fixed margin, then compute margin based on epsilon, scale and Approx's value
|
||||||
|
// Thanks to Richard Harris for his help refining the scaled margin value
|
||||||
|
return marginComparison(m_value, other, m_margin) || marginComparison(m_value, other, m_epsilon * (m_scale + std::fabs(m_value)));
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Detail
|
||||||
|
|
||||||
|
std::string StringMaker<Catch::Detail::Approx>::convert(Catch::Detail::Approx const& value) {
|
||||||
|
return value.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
126
include/internal/catch_approx.h
Normal file
126
include/internal/catch_approx.h
Normal file
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 28/04/2011.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_enforce.h"
|
||||||
|
#include "catch_tostring.h"
|
||||||
|
|
||||||
|
#include <type_traits>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
|
class Approx {
|
||||||
|
private:
|
||||||
|
bool equalityComparisonImpl(double other) const;
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Approx ( double value );
|
||||||
|
|
||||||
|
static Approx custom();
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
Approx operator()( T const& value ) {
|
||||||
|
Approx approx( static_cast<double>(value) );
|
||||||
|
approx.epsilon( m_epsilon );
|
||||||
|
approx.margin( m_margin );
|
||||||
|
approx.scale( m_scale );
|
||||||
|
return approx;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
explicit Approx( T const& value ): Approx(static_cast<double>(value))
|
||||||
|
{}
|
||||||
|
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator == ( const T& lhs, Approx const& rhs ) {
|
||||||
|
auto lhs_v = static_cast<double>(lhs);
|
||||||
|
return rhs.equalityComparisonImpl(lhs_v);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator == ( Approx const& lhs, const T& rhs ) {
|
||||||
|
return operator==( rhs, lhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator != ( T const& lhs, Approx const& rhs ) {
|
||||||
|
return !operator==( lhs, rhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator != ( Approx const& lhs, T const& rhs ) {
|
||||||
|
return !operator==( rhs, lhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator <= ( T const& lhs, Approx const& rhs ) {
|
||||||
|
return static_cast<double>(lhs) < rhs.m_value || lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator <= ( Approx const& lhs, T const& rhs ) {
|
||||||
|
return lhs.m_value < static_cast<double>(rhs) || lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator >= ( T const& lhs, Approx const& rhs ) {
|
||||||
|
return static_cast<double>(lhs) > rhs.m_value || lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
friend bool operator >= ( Approx const& lhs, T const& rhs ) {
|
||||||
|
return lhs.m_value > static_cast<double>(rhs) || lhs == rhs;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
Approx& epsilon( T const& newEpsilon ) {
|
||||||
|
double epsilonAsDouble = static_cast<double>(newEpsilon);
|
||||||
|
CATCH_ENFORCE(epsilonAsDouble >= 0 && epsilonAsDouble <= 1.0,
|
||||||
|
"Invalid Approx::epsilon: " << epsilonAsDouble
|
||||||
|
<< ", Approx::epsilon has to be between 0 and 1");
|
||||||
|
m_epsilon = epsilonAsDouble;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
Approx& margin( T const& newMargin ) {
|
||||||
|
double marginAsDouble = static_cast<double>(newMargin);
|
||||||
|
CATCH_ENFORCE(marginAsDouble >= 0,
|
||||||
|
"Invalid Approx::margin: " << marginAsDouble
|
||||||
|
<< ", Approx::Margin has to be non-negative.");
|
||||||
|
m_margin = marginAsDouble;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T, typename = typename std::enable_if<std::is_constructible<double, T>::value>::type>
|
||||||
|
Approx& scale( T const& newScale ) {
|
||||||
|
m_scale = static_cast<double>(newScale);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string toString() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
double m_epsilon;
|
||||||
|
double m_margin;
|
||||||
|
double m_scale;
|
||||||
|
double m_value;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct StringMaker<Catch::Detail::Approx> {
|
||||||
|
static std::string convert(Catch::Detail::Approx const& value);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_APPROX_HPP_INCLUDED
|
147
include/internal/catch_assertionhandler.cpp
Normal file
147
include/internal/catch_assertionhandler.cpp
Normal file
@ -0,0 +1,147 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_assertionhandler.h"
|
||||||
|
#include "catch_assertionresult.h"
|
||||||
|
#include "catch_interfaces_capture.h"
|
||||||
|
#include "catch_interfaces_runner.h"
|
||||||
|
#include "catch_interfaces_config.h"
|
||||||
|
#include "catch_context.h"
|
||||||
|
#include "catch_debugger.h"
|
||||||
|
#include "catch_interfaces_registry_hub.h"
|
||||||
|
#include "catch_capture_matchers.h"
|
||||||
|
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
|
||||||
|
expr.streamReconstructedExpression( os );
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
LazyExpression::LazyExpression( bool isNegated )
|
||||||
|
: m_isNegated( isNegated )
|
||||||
|
{}
|
||||||
|
|
||||||
|
LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
|
||||||
|
|
||||||
|
LazyExpression::operator bool() const {
|
||||||
|
return m_transientExpression != nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
|
||||||
|
if( lazyExpr.m_isNegated )
|
||||||
|
os << "!";
|
||||||
|
|
||||||
|
if( lazyExpr ) {
|
||||||
|
if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() )
|
||||||
|
os << "(" << *lazyExpr.m_transientExpression << ")";
|
||||||
|
else
|
||||||
|
os << *lazyExpr.m_transientExpression;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
os << "{** error - unchecked empty expression requested **}";
|
||||||
|
}
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertionHandler::AssertionHandler
|
||||||
|
( StringRef macroName,
|
||||||
|
SourceLineInfo const& lineInfo,
|
||||||
|
StringRef capturedExpression,
|
||||||
|
ResultDisposition::Flags resultDisposition )
|
||||||
|
: m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition }
|
||||||
|
{
|
||||||
|
getCurrentContext().getResultCapture()->assertionStarting( m_assertionInfo );
|
||||||
|
}
|
||||||
|
AssertionHandler::~AssertionHandler() {
|
||||||
|
if ( m_inExceptionGuard ) {
|
||||||
|
handle( ResultWas::ThrewException, "Exception translation was disabled by CATCH_CONFIG_FAST_COMPILE" );
|
||||||
|
getCurrentContext().getResultCapture()->exceptionEarlyReported();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertionHandler::handle( ITransientExpression const& expr ) {
|
||||||
|
|
||||||
|
bool negated = isFalseTest( m_assertionInfo.resultDisposition );
|
||||||
|
bool result = expr.getResult() != negated;
|
||||||
|
|
||||||
|
handle( result ? ResultWas::Ok : ResultWas::ExpressionFailed, &expr, negated );
|
||||||
|
}
|
||||||
|
void AssertionHandler::handle( ResultWas::OfType resultType ) {
|
||||||
|
handle( resultType, nullptr, false );
|
||||||
|
}
|
||||||
|
void AssertionHandler::handle( ResultWas::OfType resultType, StringRef const& message ) {
|
||||||
|
AssertionResultData data( resultType, LazyExpression( false ) );
|
||||||
|
data.message = message;
|
||||||
|
handle( data, nullptr );
|
||||||
|
}
|
||||||
|
void AssertionHandler::handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated ) {
|
||||||
|
AssertionResultData data( resultType, LazyExpression( negated ) );
|
||||||
|
handle( data, expr );
|
||||||
|
}
|
||||||
|
void AssertionHandler::handle( AssertionResultData const& resultData, ITransientExpression const* expr ) {
|
||||||
|
|
||||||
|
getResultCapture().assertionRun();
|
||||||
|
|
||||||
|
AssertionResult assertionResult{ m_assertionInfo, resultData };
|
||||||
|
assertionResult.m_resultData.lazyExpression.m_transientExpression = expr;
|
||||||
|
|
||||||
|
getResultCapture().assertionEnded( assertionResult );
|
||||||
|
|
||||||
|
if( !assertionResult.isOk() ) {
|
||||||
|
m_shouldDebugBreak = getCurrentContext().getConfig()->shouldDebugBreak();
|
||||||
|
m_shouldThrow =
|
||||||
|
getCurrentContext().getRunner()->aborting() ||
|
||||||
|
(m_assertionInfo.resultDisposition & ResultDisposition::Normal);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto AssertionHandler::allowThrows() const -> bool {
|
||||||
|
return getCurrentContext().getConfig()->allowThrows();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto AssertionHandler::shouldDebugBreak() const -> bool {
|
||||||
|
return m_shouldDebugBreak;
|
||||||
|
}
|
||||||
|
void AssertionHandler::reactWithDebugBreak() const {
|
||||||
|
if (m_shouldDebugBreak) {
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
// To inspect the state during test, you need to go one level up the callstack
|
||||||
|
// To go back to the test and change execution, jump over the reactWithoutDebugBreak() call
|
||||||
|
///////////////////////////////////////////////////////////////////
|
||||||
|
CATCH_BREAK_INTO_DEBUGGER();
|
||||||
|
}
|
||||||
|
reactWithoutDebugBreak();
|
||||||
|
}
|
||||||
|
void AssertionHandler::reactWithoutDebugBreak() const {
|
||||||
|
if( m_shouldThrow )
|
||||||
|
throw Catch::TestFailureException();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertionHandler::useActiveException() {
|
||||||
|
handle( ResultWas::ThrewException, Catch::translateActiveException() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void AssertionHandler::setExceptionGuard() {
|
||||||
|
assert( m_inExceptionGuard == false );
|
||||||
|
m_inExceptionGuard = true;
|
||||||
|
}
|
||||||
|
void AssertionHandler::unsetExceptionGuard() {
|
||||||
|
assert( m_inExceptionGuard == true );
|
||||||
|
m_inExceptionGuard = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the overload that takes a string and infers the Equals matcher from it
|
||||||
|
// The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
|
||||||
|
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) {
|
||||||
|
handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Catch
|
73
include/internal/catch_assertionhandler.h
Normal file
73
include/internal/catch_assertionhandler.h
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_decomposer.h"
|
||||||
|
#include "catch_assertioninfo.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct TestFailureException{};
|
||||||
|
struct AssertionResultData;
|
||||||
|
|
||||||
|
class LazyExpression {
|
||||||
|
friend class AssertionHandler;
|
||||||
|
friend struct AssertionStats;
|
||||||
|
|
||||||
|
ITransientExpression const* m_transientExpression = nullptr;
|
||||||
|
bool m_isNegated;
|
||||||
|
public:
|
||||||
|
LazyExpression( bool isNegated );
|
||||||
|
LazyExpression( LazyExpression const& other );
|
||||||
|
LazyExpression& operator = ( LazyExpression const& ) = delete;
|
||||||
|
|
||||||
|
explicit operator bool() const;
|
||||||
|
|
||||||
|
friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
|
||||||
|
};
|
||||||
|
|
||||||
|
class AssertionHandler {
|
||||||
|
AssertionInfo m_assertionInfo;
|
||||||
|
bool m_shouldDebugBreak = false;
|
||||||
|
bool m_shouldThrow = false;
|
||||||
|
bool m_inExceptionGuard = false;
|
||||||
|
|
||||||
|
public:
|
||||||
|
AssertionHandler
|
||||||
|
( StringRef macroName,
|
||||||
|
SourceLineInfo const& lineInfo,
|
||||||
|
StringRef capturedExpression,
|
||||||
|
ResultDisposition::Flags resultDisposition );
|
||||||
|
~AssertionHandler();
|
||||||
|
|
||||||
|
void handle( ITransientExpression const& expr );
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void handle( ExprLhs<T> const& expr ) {
|
||||||
|
handle( expr.makeUnaryExpr() );
|
||||||
|
}
|
||||||
|
void handle( ResultWas::OfType resultType );
|
||||||
|
void handle( ResultWas::OfType resultType, StringRef const& message );
|
||||||
|
void handle( ResultWas::OfType resultType, ITransientExpression const* expr, bool negated );
|
||||||
|
void handle( AssertionResultData const& resultData, ITransientExpression const* expr );
|
||||||
|
|
||||||
|
auto shouldDebugBreak() const -> bool;
|
||||||
|
auto allowThrows() const -> bool;
|
||||||
|
void reactWithDebugBreak() const;
|
||||||
|
void reactWithoutDebugBreak() const;
|
||||||
|
void useActiveException();
|
||||||
|
void setExceptionGuard();
|
||||||
|
void unsetExceptionGuard();
|
||||||
|
};
|
||||||
|
|
||||||
|
void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString );
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
|
31
include/internal/catch_assertioninfo.h
Normal file
31
include/internal/catch_assertioninfo.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_ASSERTIONINFO_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_ASSERTIONINFO_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_result_type.h"
|
||||||
|
#include "catch_common.h"
|
||||||
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct AssertionInfo
|
||||||
|
{
|
||||||
|
StringRef macroName;
|
||||||
|
SourceLineInfo lineInfo;
|
||||||
|
StringRef capturedExpression;
|
||||||
|
ResultDisposition::Flags resultDisposition;
|
||||||
|
|
||||||
|
// We want to delete this constructor but a compiler bug in 4.8 means
|
||||||
|
// the struct is then treated as non-aggregate
|
||||||
|
//AssertionInfo() = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_ASSERTIONINFO_H_INCLUDED
|
99
include/internal/catch_assertionresult.cpp
Normal file
99
include/internal/catch_assertionresult.cpp
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 8/8/12
|
||||||
|
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_assertionresult.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
|
||||||
|
lazyExpression(_lazyExpression),
|
||||||
|
resultType(_resultType) {}
|
||||||
|
|
||||||
|
std::string AssertionResultData::reconstructExpression() const {
|
||||||
|
|
||||||
|
if( reconstructedExpression.empty() ) {
|
||||||
|
if( lazyExpression ) {
|
||||||
|
// !TBD Use stringstream for now, but rework above to pass stream in
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << lazyExpression;
|
||||||
|
reconstructedExpression = oss.str();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return reconstructedExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertionResult::AssertionResult( AssertionInfo const& info, AssertionResultData const& data )
|
||||||
|
: m_info( info ),
|
||||||
|
m_resultData( data )
|
||||||
|
{}
|
||||||
|
|
||||||
|
// Result was a success
|
||||||
|
bool AssertionResult::succeeded() const {
|
||||||
|
return Catch::isOk( m_resultData.resultType );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Result was a success, or failure is suppressed
|
||||||
|
bool AssertionResult::isOk() const {
|
||||||
|
return Catch::isOk( m_resultData.resultType ) || shouldSuppressFailure( m_info.resultDisposition );
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultWas::OfType AssertionResult::getResultType() const {
|
||||||
|
return m_resultData.resultType;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssertionResult::hasExpression() const {
|
||||||
|
return m_info.capturedExpression[0] != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssertionResult::hasMessage() const {
|
||||||
|
return !m_resultData.message.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AssertionResult::getExpression() const {
|
||||||
|
if( isFalseTest( m_info.resultDisposition ) )
|
||||||
|
return "!(" + std::string(m_info.capturedExpression) + ")";
|
||||||
|
else
|
||||||
|
return m_info.capturedExpression;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AssertionResult::getExpressionInMacro() const {
|
||||||
|
std::string expr;
|
||||||
|
if( m_info.macroName[0] == 0 )
|
||||||
|
expr = m_info.capturedExpression;
|
||||||
|
else {
|
||||||
|
expr.reserve( m_info.macroName.size() + m_info.capturedExpression.size() + 4 );
|
||||||
|
expr += m_info.macroName;
|
||||||
|
expr += "( ";
|
||||||
|
expr += m_info.capturedExpression;
|
||||||
|
expr += " )";
|
||||||
|
}
|
||||||
|
return expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AssertionResult::hasExpandedExpression() const {
|
||||||
|
return hasExpression() && getExpandedExpression() != getExpression();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AssertionResult::getExpandedExpression() const {
|
||||||
|
std::string expr = m_resultData.reconstructExpression();
|
||||||
|
return expr.empty()
|
||||||
|
? getExpression()
|
||||||
|
: expr;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AssertionResult::getMessage() const {
|
||||||
|
return m_resultData.message;
|
||||||
|
}
|
||||||
|
SourceLineInfo AssertionResult::getSourceInfo() const {
|
||||||
|
return m_info.lineInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string AssertionResult::getTestMacroName() const {
|
||||||
|
return m_info.macroName;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
@ -9,100 +9,32 @@
|
|||||||
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_ASSERTIONRESULT_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include "catch_assertioninfo.h"
|
||||||
#include "catch_result_type.h"
|
#include "catch_result_type.h"
|
||||||
|
#include "catch_common.h"
|
||||||
|
#include "catch_stringref.h"
|
||||||
|
#include "catch_assertionhandler.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison;
|
|
||||||
|
|
||||||
struct DecomposedExpression
|
|
||||||
{
|
|
||||||
virtual ~DecomposedExpression() {}
|
|
||||||
virtual bool isBinaryExpression() const {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
virtual void reconstructExpression( std::string& dest ) const = 0;
|
|
||||||
|
|
||||||
// Only simple binary comparisons can be decomposed.
|
|
||||||
// If more complex check is required then wrap sub-expressions in parentheses.
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator + ( T const& );
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator - ( T const& );
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator * ( T const& );
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator / ( T const& );
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator % ( T const& );
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator && ( T const& );
|
|
||||||
template<typename T> STATIC_ASSERT_Expression_Too_Complex_Please_Rewrite_As_Binary_Comparison& operator || ( T const& );
|
|
||||||
|
|
||||||
private:
|
|
||||||
DecomposedExpression& operator = (DecomposedExpression const&);
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AssertionInfo
|
|
||||||
{
|
|
||||||
AssertionInfo();
|
|
||||||
AssertionInfo( char const * _macroName,
|
|
||||||
SourceLineInfo const& _lineInfo,
|
|
||||||
char const * _capturedExpression,
|
|
||||||
ResultDisposition::Flags _resultDisposition,
|
|
||||||
char const * _secondArg = "");
|
|
||||||
|
|
||||||
char const * macroName;
|
|
||||||
SourceLineInfo lineInfo;
|
|
||||||
char const * capturedExpression;
|
|
||||||
ResultDisposition::Flags resultDisposition;
|
|
||||||
char const * secondArg;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct AssertionResultData
|
struct AssertionResultData
|
||||||
{
|
{
|
||||||
AssertionResultData() : decomposedExpression( CATCH_NULL )
|
AssertionResultData() = delete;
|
||||||
, resultType( ResultWas::Unknown )
|
|
||||||
, negated( false )
|
|
||||||
, parenthesized( false ) {}
|
|
||||||
|
|
||||||
void negate( bool parenthesize ) {
|
AssertionResultData( ResultWas::OfType _resultType, LazyExpression const& _lazyExpression );
|
||||||
negated = !negated;
|
|
||||||
parenthesized = parenthesize;
|
|
||||||
if( resultType == ResultWas::Ok )
|
|
||||||
resultType = ResultWas::ExpressionFailed;
|
|
||||||
else if( resultType == ResultWas::ExpressionFailed )
|
|
||||||
resultType = ResultWas::Ok;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string const& reconstructExpression() const {
|
|
||||||
if( decomposedExpression != CATCH_NULL ) {
|
|
||||||
decomposedExpression->reconstructExpression( reconstructedExpression );
|
|
||||||
if( parenthesized ) {
|
|
||||||
reconstructedExpression.insert( 0, 1, '(' );
|
|
||||||
reconstructedExpression.append( 1, ')' );
|
|
||||||
}
|
|
||||||
if( negated ) {
|
|
||||||
reconstructedExpression.insert( 0, 1, '!' );
|
|
||||||
}
|
|
||||||
decomposedExpression = CATCH_NULL;
|
|
||||||
}
|
|
||||||
return reconstructedExpression;
|
|
||||||
}
|
|
||||||
|
|
||||||
mutable DecomposedExpression const* decomposedExpression;
|
|
||||||
mutable std::string reconstructedExpression;
|
|
||||||
std::string message;
|
std::string message;
|
||||||
|
mutable std::string reconstructedExpression;
|
||||||
|
LazyExpression lazyExpression;
|
||||||
ResultWas::OfType resultType;
|
ResultWas::OfType resultType;
|
||||||
bool negated;
|
|
||||||
bool parenthesized;
|
std::string reconstructExpression() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
class AssertionResult {
|
class AssertionResult {
|
||||||
public:
|
public:
|
||||||
AssertionResult();
|
AssertionResult() = delete;
|
||||||
AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
|
AssertionResult( AssertionInfo const& info, AssertionResultData const& data );
|
||||||
~AssertionResult();
|
|
||||||
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
AssertionResult( AssertionResult const& ) = default;
|
|
||||||
AssertionResult( AssertionResult && ) = default;
|
|
||||||
AssertionResult& operator = ( AssertionResult const& ) = default;
|
|
||||||
AssertionResult& operator = ( AssertionResult && ) = default;
|
|
||||||
# endif
|
|
||||||
|
|
||||||
bool isOk() const;
|
bool isOk() const;
|
||||||
bool succeeded() const;
|
bool succeeded() const;
|
||||||
@ -116,10 +48,8 @@ namespace Catch {
|
|||||||
std::string getMessage() const;
|
std::string getMessage() const;
|
||||||
SourceLineInfo getSourceInfo() const;
|
SourceLineInfo getSourceInfo() const;
|
||||||
std::string getTestMacroName() const;
|
std::string getTestMacroName() const;
|
||||||
void discardDecomposedExpression() const;
|
|
||||||
void expandDecomposedExpression() const;
|
|
||||||
|
|
||||||
protected:
|
//protected:
|
||||||
AssertionInfo m_info;
|
AssertionInfo m_info;
|
||||||
AssertionResultData m_resultData;
|
AssertionResultData m_resultData;
|
||||||
};
|
};
|
||||||
|
36
include/internal/catch_benchmark.cpp
Normal file
36
include/internal/catch_benchmark.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 04/07/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_benchmark.h"
|
||||||
|
#include "catch_capture.hpp"
|
||||||
|
#include "catch_interfaces_reporter.h"
|
||||||
|
#include "catch_context.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
auto BenchmarkLooper::getResolution() -> uint64_t {
|
||||||
|
return getEstimatedClockResolution() * getCurrentContext().getConfig()->benchmarkResolutionMultiple();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BenchmarkLooper::reportStart() {
|
||||||
|
getResultCapture().benchmarkStarting( { m_name } );
|
||||||
|
}
|
||||||
|
auto BenchmarkLooper::needsMoreIterations() -> bool {
|
||||||
|
auto elapsed = m_timer.getElapsedNanoseconds();
|
||||||
|
|
||||||
|
// Exponentially increasing iterations until we're confident in our timer resolution
|
||||||
|
if( elapsed < m_resolution ) {
|
||||||
|
m_iterationsToRun *= 10;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
getResultCapture().benchmarkEnded( { { m_name }, m_count, elapsed } );
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
57
include/internal/catch_benchmark.h
Normal file
57
include/internal/catch_benchmark.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 04/07/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_BENCHMARK_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_BENCHMARK_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_stringref.h"
|
||||||
|
#include "catch_timer.h"
|
||||||
|
|
||||||
|
#include <cstdint>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
class BenchmarkLooper {
|
||||||
|
|
||||||
|
std::string m_name;
|
||||||
|
std::size_t m_count = 0;
|
||||||
|
std::size_t m_iterationsToRun = 1;
|
||||||
|
uint64_t m_resolution;
|
||||||
|
Timer m_timer;
|
||||||
|
|
||||||
|
static auto getResolution() -> uint64_t;
|
||||||
|
public:
|
||||||
|
// Keep most of this inline as it's on the code path that is being timed
|
||||||
|
BenchmarkLooper( StringRef name )
|
||||||
|
: m_name( name ),
|
||||||
|
m_resolution( getResolution() )
|
||||||
|
{
|
||||||
|
reportStart();
|
||||||
|
m_timer.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
explicit operator bool() {
|
||||||
|
if( m_count < m_iterationsToRun )
|
||||||
|
return true;
|
||||||
|
return needsMoreIterations();
|
||||||
|
}
|
||||||
|
|
||||||
|
void increment() {
|
||||||
|
++m_count;
|
||||||
|
}
|
||||||
|
|
||||||
|
void reportStart();
|
||||||
|
auto needsMoreIterations() -> bool;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#define BENCHMARK( name ) \
|
||||||
|
for( Catch::BenchmarkLooper looper( name ); looper; looper.increment() )
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_BENCHMARK_H_INCLUDED
|
@ -8,20 +8,17 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_result_builder.h"
|
#include "catch_assertionhandler.h"
|
||||||
#include "catch_message.h"
|
#include "catch_message.h"
|
||||||
#include "catch_interfaces_capture.h"
|
#include "catch_interfaces_capture.h"
|
||||||
#include "catch_debugger.h"
|
#include "catch_debugger.h"
|
||||||
#include "catch_common.h"
|
|
||||||
#include "catch_tostring.h"
|
|
||||||
#include "catch_interfaces_runner.h"
|
|
||||||
#include "catch_compiler_capabilities.h"
|
|
||||||
|
|
||||||
|
#if !defined(CATCH_CONFIG_DISABLE)
|
||||||
|
|
||||||
#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
|
#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
|
||||||
# define CATCH_INTERNAL_STRINGIFY(expr) #expr
|
#define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
|
||||||
#else
|
#else
|
||||||
# define CATCH_INTERNAL_STRINGIFY(expr) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
|
#define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
#if defined(CATCH_CONFIG_FAST_COMPILE)
|
||||||
@ -29,158 +26,138 @@
|
|||||||
// We can speedup compilation significantly by breaking into debugger lower in
|
// We can speedup compilation significantly by breaking into debugger lower in
|
||||||
// the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
|
// the callstack, because then we don't have to expand CATCH_BREAK_INTO_DEBUGGER
|
||||||
// macro in each assertion
|
// macro in each assertion
|
||||||
#define INTERNAL_CATCH_REACT( resultBuilder ) \
|
#define INTERNAL_CATCH_REACT( handler ) \
|
||||||
resultBuilder.react();
|
handler.reactWithDebugBreak();
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// Another way to speed-up compilation is to omit local try-catch for REQUIRE*
|
// Another way to speed-up compilation is to omit local try-catch for REQUIRE*
|
||||||
// macros.
|
// macros.
|
||||||
// This can potentially cause false negative, if the test code catches
|
// This can potentially cause false negative, if the test code catches
|
||||||
// the exception before it propagates back up to the runner.
|
// the exception before it propagates back up to the runner.
|
||||||
#define INTERNAL_CATCH_TEST_NO_TRY( macroName, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_TRY( capturer ) capturer.setExceptionGuard();
|
||||||
do { \
|
#define INTERNAL_CATCH_CATCH( capturer ) capturer.unsetExceptionGuard();
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
|
|
||||||
__catchResult.setExceptionGuard(); \
|
|
||||||
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
|
||||||
( __catchResult <= expr ).endExpression(); \
|
|
||||||
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
|
||||||
__catchResult.unsetExceptionGuard(); \
|
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
||||||
} while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
|
|
||||||
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
|
|
||||||
|
|
||||||
#define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \
|
#else // CATCH_CONFIG_FAST_COMPILE
|
||||||
do { \
|
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
|
||||||
__catchResult.setExceptionGuard(); \
|
|
||||||
__catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
|
|
||||||
__catchResult.unsetExceptionGuard(); \
|
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
||||||
} while( Catch::alwaysFalse() )
|
|
||||||
|
|
||||||
#else
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
// In the event of a failure works out if the debugger needs to be invoked
|
// In the event of a failure works out if the debugger needs to be invoked
|
||||||
// and/or an exception thrown and takes appropriate action.
|
// and/or an exception thrown and takes appropriate action.
|
||||||
// This needs to be done as a macro so the debugger will stop in the user
|
// This needs to be done as a macro so the debugger will stop in the user
|
||||||
// source code rather than in Catch library code
|
// source code rather than in Catch library code
|
||||||
#define INTERNAL_CATCH_REACT( resultBuilder ) \
|
#define INTERNAL_CATCH_REACT( handler ) \
|
||||||
if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
|
if( handler.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
|
||||||
resultBuilder.react();
|
handler.reactWithoutDebugBreak();
|
||||||
|
|
||||||
|
#define INTERNAL_CATCH_TRY( capturer ) try
|
||||||
|
#define INTERNAL_CATCH_CATCH( capturer ) catch(...) { capturer.useActiveException(); }
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
|
||||||
try { \
|
INTERNAL_CATCH_TRY( catchAssertionHandler ) { \
|
||||||
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
||||||
( __catchResult <= expr ).endExpression(); \
|
catchAssertionHandler.handle( Catch::Decomposer() <= __VA_ARGS__ ); \
|
||||||
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
||||||
} \
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
||||||
catch( ... ) { \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
__catchResult.useActiveException( resultDisposition ); \
|
} while( Catch::isTrue( false && static_cast<bool>( !!(__VA_ARGS__) ) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
|
||||||
} \
|
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
||||||
} while( Catch::isTrue( false && static_cast<bool>( !!(expr) ) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
|
|
||||||
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
|
// The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_IF( macroName, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
|
||||||
INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
|
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
||||||
if( Catch::getResultCapture().lastAssertionPassed() )
|
if( Catch::getResultCapture().lastAssertionPassed() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
|
||||||
INTERNAL_CATCH_TEST( macroName, resultDisposition, expr ); \
|
INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
|
||||||
if( !Catch::getResultCapture().lastAssertionPassed() )
|
if( !Catch::getResultCapture().lastAssertionPassed() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(expr); \
|
static_cast<void>(__VA_ARGS__); \
|
||||||
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
__catchResult.useActiveException( resultDisposition ); \
|
catchAssertionHandler.useActiveException(); \
|
||||||
} \
|
} \
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, matcher, expr ) \
|
#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr), resultDisposition, CATCH_INTERNAL_STRINGIFY(matcher) ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
|
||||||
if( __catchResult.allowThrows() ) \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(expr); \
|
static_cast<void>(__VA_ARGS__); \
|
||||||
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
|
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
__catchResult.captureExpectedException( matcher ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
|
#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
|
||||||
if( __catchResult.allowThrows() ) \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
try { \
|
try { \
|
||||||
static_cast<void>(expr); \
|
static_cast<void>(expr); \
|
||||||
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
|
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
||||||
} \
|
} \
|
||||||
catch( exceptionType ) { \
|
catch( exceptionType const& ) { \
|
||||||
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
} \
|
} \
|
||||||
catch( ... ) { \
|
catch( ... ) { \
|
||||||
__catchResult.useActiveException( resultDisposition ); \
|
catchAssertionHandler.useActiveException(); \
|
||||||
} \
|
} \
|
||||||
else \
|
else \
|
||||||
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
||||||
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
|
do { \
|
||||||
do { \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
catchAssertionHandler.handle( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
|
||||||
__catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
__catchResult.captureResult( messageType ); \
|
} while( Catch::alwaysFalse() )
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
||||||
} while( Catch::alwaysFalse() )
|
|
||||||
#else
|
|
||||||
#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, log ) \
|
|
||||||
do { \
|
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
|
||||||
__catchResult << log + ::Catch::StreamEndStop(); \
|
|
||||||
__catchResult.captureResult( messageType ); \
|
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
||||||
} while( Catch::alwaysFalse() )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CATCH_INFO( macroName, log ) \
|
#define INTERNAL_CATCH_INFO( macroName, log ) \
|
||||||
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
|
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
|
// Although this is matcher-based, it can be used with just a string
|
||||||
|
#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
|
||||||
do { \
|
do { \
|
||||||
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
||||||
try { \
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
__catchResult.captureMatch( arg, matcher, CATCH_INTERNAL_STRINGIFY(matcher) ); \
|
try { \
|
||||||
} catch( ... ) { \
|
static_cast<void>(__VA_ARGS__); \
|
||||||
__catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
|
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
||||||
} \
|
} \
|
||||||
INTERNAL_CATCH_REACT( __catchResult ) \
|
catch( ... ) { \
|
||||||
|
handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
} while( Catch::alwaysFalse() )
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
|
#endif // CATCH_CONFIG_DISABLE
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
||||||
|
24
include/internal/catch_capture_matchers.cpp
Normal file
24
include/internal/catch_capture_matchers.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 9/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include "catch_capture_matchers.h"
|
||||||
|
#include "catch_interfaces_registry_hub.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
|
||||||
|
|
||||||
|
// This is the general overload that takes a any string matcher
|
||||||
|
// There is another overload, in catch_assertinhandler.h/.cpp, that only takes a string and infers
|
||||||
|
// the Equals matcher (so the header does not mention matchers)
|
||||||
|
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) {
|
||||||
|
std::string exceptionMessage = Catch::translateActiveException();
|
||||||
|
MatchExpr<std::string, StringMatcher const&> expr( exceptionMessage, matcher, matcherString );
|
||||||
|
handler.handle( expr );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Catch
|
88
include/internal/catch_capture_matchers.h
Normal file
88
include/internal/catch_capture_matchers.h
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 9/8/2017
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_capture.hpp"
|
||||||
|
#include "catch_matchers.h"
|
||||||
|
#include "catch_matchers_string.h"
|
||||||
|
#include "catch_matchers_vector.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
template<typename ArgT, typename MatcherT>
|
||||||
|
class MatchExpr : public ITransientExpression {
|
||||||
|
ArgT const& m_arg;
|
||||||
|
MatcherT m_matcher;
|
||||||
|
StringRef m_matcherString;
|
||||||
|
bool m_result;
|
||||||
|
public:
|
||||||
|
MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString )
|
||||||
|
: m_arg( arg ),
|
||||||
|
m_matcher( matcher ),
|
||||||
|
m_matcherString( matcherString ),
|
||||||
|
m_result( matcher.match( arg ) )
|
||||||
|
{}
|
||||||
|
|
||||||
|
auto isBinaryExpression() const -> bool override { return true; }
|
||||||
|
auto getResult() const -> bool override { return m_result; }
|
||||||
|
|
||||||
|
void streamReconstructedExpression( std::ostream &os ) const override {
|
||||||
|
auto matcherAsString = m_matcher.toString();
|
||||||
|
os << Catch::Detail::stringify( m_arg ) << ' ';
|
||||||
|
if( matcherAsString == Detail::unprintableString )
|
||||||
|
os << m_matcherString;
|
||||||
|
else
|
||||||
|
os << matcherAsString;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
|
||||||
|
|
||||||
|
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString );
|
||||||
|
|
||||||
|
template<typename ArgT, typename MatcherT>
|
||||||
|
auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr<ArgT, MatcherT> {
|
||||||
|
return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
|
||||||
|
do { \
|
||||||
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
||||||
|
INTERNAL_CATCH_TRY( catchAssertionHandler ) { \
|
||||||
|
catchAssertionHandler.handle( Catch::makeMatchExpr( arg, matcher, #matcher ) ); \
|
||||||
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
||||||
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
|
||||||
|
do { \
|
||||||
|
Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
||||||
|
if( catchAssertionHandler.allowThrows() ) \
|
||||||
|
try { \
|
||||||
|
static_cast<void>(__VA_ARGS__ ); \
|
||||||
|
catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \
|
||||||
|
} \
|
||||||
|
catch( exceptionType const& ex ) { \
|
||||||
|
catchAssertionHandler.handle( Catch::makeMatchExpr( ex, matcher, #matcher ) ); \
|
||||||
|
} \
|
||||||
|
catch( ... ) { \
|
||||||
|
catchAssertionHandler.useActiveException(); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
catchAssertionHandler.handle( Catch::ResultWas::Ok ); \
|
||||||
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
||||||
|
} while( Catch::alwaysFalse() )
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|
@ -11,21 +11,27 @@
|
|||||||
|
|
||||||
// Use Catch's value for console width (store Clara's off to the side, if present)
|
// Use Catch's value for console width (store Clara's off to the side, if present)
|
||||||
#ifdef CLARA_CONFIG_CONSOLE_WIDTH
|
#ifdef CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CLARA_CONFIG_CONSOLE_WIDTH
|
#define CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
||||||
#undef CLARA_CONFIG_CONSOLE_WIDTH
|
#undef CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH
|
||||||
#endif
|
#endif
|
||||||
#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH
|
#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_CONFIG_CONSOLE_WIDTH-1
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic push
|
||||||
|
#pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
|
#pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||||
|
#pragma clang diagnostic ignored "-Wshadow"
|
||||||
|
#endif
|
||||||
|
|
||||||
// Declare Clara inside the Catch namespace
|
#include "../external/clara.hpp"
|
||||||
#define STITCH_CLARA_OPEN_NAMESPACE namespace Catch {
|
|
||||||
#include "../external/clara.h"
|
|
||||||
#undef STITCH_CLARA_OPEN_NAMESPACE
|
|
||||||
|
|
||||||
|
#ifdef __clang__
|
||||||
|
#pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
||||||
// Restore Clara's value for console width, if present
|
// Restore Clara's value for console width, if present
|
||||||
#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
#ifdef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
#define CLARA_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
#define CATCH_CLARA_TEXTFLOW_CONFIG_CONSOLE_WIDTH CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
#undef CATCH_TEMP_CLARA_CONFIG_CONSOLE_WIDTH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
184
include/internal/catch_commandline.cpp
Normal file
184
include/internal/catch_commandline.cpp
Normal file
@ -0,0 +1,184 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 02/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_commandline.h"
|
||||||
|
|
||||||
|
#include "catch_string_manip.h"
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
#include <ctime>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
clara::Parser makeCommandLineParser( ConfigData& config ) {
|
||||||
|
|
||||||
|
using namespace clara;
|
||||||
|
|
||||||
|
auto const setWarning = [&]( std::string const& warning ) {
|
||||||
|
if( warning != "NoAssertions" )
|
||||||
|
return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
|
||||||
|
config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
|
||||||
|
std::ifstream f( filename.c_str() );
|
||||||
|
if( !f.is_open() )
|
||||||
|
return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
|
||||||
|
|
||||||
|
std::string line;
|
||||||
|
while( std::getline( f, line ) ) {
|
||||||
|
line = trim(line);
|
||||||
|
if( !line.empty() && !startsWith( line, '#' ) ) {
|
||||||
|
if( !startsWith( line, '"' ) )
|
||||||
|
line = '"' + line + '"';
|
||||||
|
config.testsOrTags.push_back( line + ',' );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
auto const setTestOrder = [&]( std::string const& order ) {
|
||||||
|
if( startsWith( "declared", order ) )
|
||||||
|
config.runOrder = RunTests::InDeclarationOrder;
|
||||||
|
else if( startsWith( "lexical", order ) )
|
||||||
|
config.runOrder = RunTests::InLexicographicalOrder;
|
||||||
|
else if( startsWith( "random", order ) )
|
||||||
|
config.runOrder = RunTests::InRandomOrder;
|
||||||
|
else
|
||||||
|
return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
auto const setRngSeed = [&]( std::string const& seed ) {
|
||||||
|
if( seed != "time" )
|
||||||
|
return clara::detail::convertInto( seed, config.rngSeed );
|
||||||
|
config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
auto const setColourUsage = [&]( std::string const& useColour ) {
|
||||||
|
auto mode = toLower( useColour );
|
||||||
|
|
||||||
|
if( mode == "yes" )
|
||||||
|
config.useColour = UseColour::Yes;
|
||||||
|
else if( mode == "no" )
|
||||||
|
config.useColour = UseColour::No;
|
||||||
|
else if( mode == "auto" )
|
||||||
|
config.useColour = UseColour::Auto;
|
||||||
|
else
|
||||||
|
return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
auto const setWaitForKeypress = [&]( std::string const& keypress ) {
|
||||||
|
auto keypressLc = toLower( keypress );
|
||||||
|
if( keypressLc == "start" )
|
||||||
|
config.waitForKeypress = WaitForKeypress::BeforeStart;
|
||||||
|
else if( keypressLc == "exit" )
|
||||||
|
config.waitForKeypress = WaitForKeypress::BeforeExit;
|
||||||
|
else if( keypressLc == "both" )
|
||||||
|
config.waitForKeypress = WaitForKeypress::BeforeStartAndExit;
|
||||||
|
else
|
||||||
|
return ParserResult::runtimeError( "keypress argument must be one of: start, exit or both. '" + keypress + "' not recognised" );
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
auto const setVerbosity = [&]( std::string const& verbosity ) {
|
||||||
|
auto lcVerbosity = toLower( verbosity );
|
||||||
|
if( lcVerbosity == "quiet" )
|
||||||
|
config.verbosity = Verbosity::Quiet;
|
||||||
|
else if( lcVerbosity == "normal" )
|
||||||
|
config.verbosity = Verbosity::Normal;
|
||||||
|
else if( lcVerbosity == "high" )
|
||||||
|
config.verbosity = Verbosity::High;
|
||||||
|
else
|
||||||
|
return ParserResult::runtimeError( "Unrecognised verbosity, '" + verbosity + "'" );
|
||||||
|
return ParserResult::ok( ParseResultType::Matched );
|
||||||
|
};
|
||||||
|
|
||||||
|
auto cli
|
||||||
|
= ExeName( config.processName )
|
||||||
|
| Help( config.showHelp )
|
||||||
|
| Opt( config.listTests )
|
||||||
|
["-l"]["--list-tests"]
|
||||||
|
( "list all/matching test cases" )
|
||||||
|
| Opt( config.listTags )
|
||||||
|
["-t"]["--list-tags"]
|
||||||
|
( "list all/matching tags" )
|
||||||
|
| Opt( config.showSuccessfulTests )
|
||||||
|
["-s"]["--success"]
|
||||||
|
( "include successful tests in output" )
|
||||||
|
| Opt( config.shouldDebugBreak )
|
||||||
|
["-b"]["--break"]
|
||||||
|
( "break into debugger on failure" )
|
||||||
|
| Opt( config.noThrow )
|
||||||
|
["-e"]["--nothrow"]
|
||||||
|
( "skip exception tests" )
|
||||||
|
| Opt( config.showInvisibles )
|
||||||
|
["-i"]["--invisibles"]
|
||||||
|
( "show invisibles (tabs, newlines)" )
|
||||||
|
| Opt( config.outputFilename, "filename" )
|
||||||
|
["-o"]["--out"]
|
||||||
|
( "output filename" )
|
||||||
|
| Opt( config.reporterNames, "name" )
|
||||||
|
["-r"]["--reporter"]
|
||||||
|
( "reporter to use (defaults to console)" )
|
||||||
|
| Opt( config.name, "name" )
|
||||||
|
["-n"]["--name"]
|
||||||
|
( "suite name" )
|
||||||
|
| Opt( [&]( bool ){ config.abortAfter = 1; } )
|
||||||
|
["-a"]["--abort"]
|
||||||
|
( "abort at first failure" )
|
||||||
|
| Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" )
|
||||||
|
["-x"]["--abortx"]
|
||||||
|
( "abort after x failures" )
|
||||||
|
| Opt( setWarning, "warning name" )
|
||||||
|
["-w"]["--warn"]
|
||||||
|
( "enable warnings" )
|
||||||
|
| Opt( [&]( bool flag ) { config.showDurations = flag ? ShowDurations::Always : ShowDurations::Never; }, "yes|no" )
|
||||||
|
["-d"]["--durations"]
|
||||||
|
( "show test durations" )
|
||||||
|
| Opt( loadTestNamesFromFile, "filename" )
|
||||||
|
["-f"]["--input-file"]
|
||||||
|
( "load test names to run from a file" )
|
||||||
|
| Opt( config.filenamesAsTags )
|
||||||
|
["-#"]["--filenames-as-tags"]
|
||||||
|
( "adds a tag for the filename" )
|
||||||
|
| Opt( config.sectionsToRun, "section name" )
|
||||||
|
["-c"]["--section"]
|
||||||
|
( "specify section to run" )
|
||||||
|
| Opt( setVerbosity, "quiet|normal|high" )
|
||||||
|
["-v"]["--verbosity"]
|
||||||
|
( "set output verbosity" )
|
||||||
|
| Opt( config.listTestNamesOnly )
|
||||||
|
["--list-test-names-only"]
|
||||||
|
( "list all/matching test cases names only" )
|
||||||
|
| Opt( config.listReporters )
|
||||||
|
["--list-reporters"]
|
||||||
|
( "list all reporters" )
|
||||||
|
| Opt( setTestOrder, "decl|lex|rand" )
|
||||||
|
["--order"]
|
||||||
|
( "test case order (defaults to decl)" )
|
||||||
|
| Opt( setRngSeed, "'time'|number" )
|
||||||
|
["--rng-seed"]
|
||||||
|
( "set a specific seed for random numbers" )
|
||||||
|
| Opt( setColourUsage, "yes|no" )
|
||||||
|
["--use-colour"]
|
||||||
|
( "should output be colourised" )
|
||||||
|
| Opt( config.libIdentify )
|
||||||
|
["--libidentify"]
|
||||||
|
( "report name and version according to libidentify standard" )
|
||||||
|
| Opt( setWaitForKeypress, "start|exit|both" )
|
||||||
|
["--wait-for-keypress"]
|
||||||
|
( "waits for a keypress before exiting" )
|
||||||
|
| Opt( config.benchmarkResolutionMultiple, "multiplier" )
|
||||||
|
["--benchmark-resolution-multiple"]
|
||||||
|
( "multiple of clock resolution to run benchmarks" )
|
||||||
|
|
||||||
|
| Arg( config.testsOrTags, "test name|pattern|tags" )
|
||||||
|
( "which test or tests to use" );
|
||||||
|
|
||||||
|
return cli;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
20
include/internal/catch_commandline.h
Normal file
20
include/internal/catch_commandline.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 02/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_config.hpp"
|
||||||
|
#include "catch_clara.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
clara::Parser makeCommandLineParser( ConfigData& config );
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_COMMANDLINE_HPP_INCLUDED
|
52
include/internal/catch_common.cpp
Normal file
52
include/internal/catch_common.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 27/11/2013.
|
||||||
|
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_common.h"
|
||||||
|
#include "catch_context.h"
|
||||||
|
#include "catch_interfaces_config.h"
|
||||||
|
|
||||||
|
#include <cstring>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
SourceLineInfo::SourceLineInfo( char const* _file, std::size_t _line ) noexcept
|
||||||
|
: file( _file ),
|
||||||
|
line( _line )
|
||||||
|
{}
|
||||||
|
bool SourceLineInfo::empty() const noexcept {
|
||||||
|
return file[0] == '\0';
|
||||||
|
}
|
||||||
|
bool SourceLineInfo::operator == ( SourceLineInfo const& other ) const noexcept {
|
||||||
|
return line == other.line && (file == other.file || std::strcmp(file, other.file) == 0);
|
||||||
|
}
|
||||||
|
bool SourceLineInfo::operator < ( SourceLineInfo const& other ) const noexcept {
|
||||||
|
return line < other.line || ( line == other.line && (std::strcmp(file, other.file) < 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ) {
|
||||||
|
#ifndef __GNUG__
|
||||||
|
os << info.file << '(' << info.line << ')';
|
||||||
|
#else
|
||||||
|
os << info.file << ':' << info.line;
|
||||||
|
#endif
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isTrue( bool value ){ return value; }
|
||||||
|
bool alwaysTrue() { return true; }
|
||||||
|
bool alwaysFalse() { return false; }
|
||||||
|
|
||||||
|
std::string StreamEndStop::operator+() const {
|
||||||
|
return std::string();
|
||||||
|
}
|
||||||
|
|
||||||
|
NonCopyable::NonCopyable() = default;
|
||||||
|
NonCopyable::~NonCopyable() = default;
|
||||||
|
|
||||||
|
}
|
@ -18,95 +18,41 @@
|
|||||||
# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
|
# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define INTERNAL_CATCH_STRINGIFY2( expr ) #expr
|
#include <iosfwd>
|
||||||
#define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr )
|
#include <string>
|
||||||
|
#include <cstdint>
|
||||||
#include <sstream>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct IConfig;
|
|
||||||
|
|
||||||
struct CaseSensitive { enum Choice {
|
struct CaseSensitive { enum Choice {
|
||||||
Yes,
|
Yes,
|
||||||
No
|
No
|
||||||
}; };
|
}; };
|
||||||
|
|
||||||
class NonCopyable {
|
class NonCopyable {
|
||||||
#ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
NonCopyable( NonCopyable const& ) = delete;
|
NonCopyable( NonCopyable const& ) = delete;
|
||||||
NonCopyable( NonCopyable && ) = delete;
|
NonCopyable( NonCopyable && ) = delete;
|
||||||
NonCopyable& operator = ( NonCopyable const& ) = delete;
|
NonCopyable& operator = ( NonCopyable const& ) = delete;
|
||||||
NonCopyable& operator = ( NonCopyable && ) = delete;
|
NonCopyable& operator = ( NonCopyable && ) = delete;
|
||||||
#else
|
|
||||||
NonCopyable( NonCopyable const& info );
|
|
||||||
NonCopyable& operator = ( NonCopyable const& );
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
NonCopyable() {}
|
NonCopyable();
|
||||||
virtual ~NonCopyable();
|
virtual ~NonCopyable();
|
||||||
};
|
};
|
||||||
|
|
||||||
class SafeBool {
|
|
||||||
public:
|
|
||||||
typedef void (SafeBool::*type)() const;
|
|
||||||
|
|
||||||
static type makeSafe( bool value ) {
|
|
||||||
return value ? &SafeBool::trueValue : 0;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
void trueValue() const {}
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename ContainerT>
|
|
||||||
void deleteAll( ContainerT& container ) {
|
|
||||||
typename ContainerT::const_iterator it = container.begin();
|
|
||||||
typename ContainerT::const_iterator itEnd = container.end();
|
|
||||||
for(; it != itEnd; ++it )
|
|
||||||
delete *it;
|
|
||||||
}
|
|
||||||
template<typename AssociativeContainerT>
|
|
||||||
void deleteAllValues( AssociativeContainerT& container ) {
|
|
||||||
typename AssociativeContainerT::const_iterator it = container.begin();
|
|
||||||
typename AssociativeContainerT::const_iterator itEnd = container.end();
|
|
||||||
for(; it != itEnd; ++it )
|
|
||||||
delete it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool startsWith( std::string const& s, std::string const& prefix );
|
|
||||||
bool startsWith( std::string const& s, char prefix );
|
|
||||||
bool endsWith( std::string const& s, std::string const& suffix );
|
|
||||||
bool endsWith( std::string const& s, char suffix );
|
|
||||||
bool contains( std::string const& s, std::string const& infix );
|
|
||||||
void toLowerInPlace( std::string& s );
|
|
||||||
std::string toLower( std::string const& s );
|
|
||||||
std::string trim( std::string const& str );
|
|
||||||
bool replaceInPlace( std::string& str, std::string const& replaceThis, std::string const& withThis );
|
|
||||||
|
|
||||||
struct pluralise {
|
|
||||||
pluralise( std::size_t count, std::string const& label );
|
|
||||||
|
|
||||||
friend std::ostream& operator << ( std::ostream& os, pluralise const& pluraliser );
|
|
||||||
|
|
||||||
std::size_t m_count;
|
|
||||||
std::string m_label;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SourceLineInfo {
|
struct SourceLineInfo {
|
||||||
|
|
||||||
SourceLineInfo();
|
SourceLineInfo() = delete;
|
||||||
SourceLineInfo( char const* _file, std::size_t _line );
|
SourceLineInfo( char const* _file, std::size_t _line ) noexcept;
|
||||||
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
SourceLineInfo(SourceLineInfo const& other) = default;
|
SourceLineInfo( SourceLineInfo const& other ) = default;
|
||||||
SourceLineInfo( SourceLineInfo && ) = default;
|
SourceLineInfo( SourceLineInfo && ) = default;
|
||||||
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
|
SourceLineInfo& operator = ( SourceLineInfo const& ) = default;
|
||||||
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
|
SourceLineInfo& operator = ( SourceLineInfo && ) = default;
|
||||||
# endif
|
|
||||||
bool empty() const;
|
bool empty() const noexcept;
|
||||||
bool operator == ( SourceLineInfo const& other ) const;
|
bool operator == ( SourceLineInfo const& other ) const noexcept;
|
||||||
bool operator < ( SourceLineInfo const& other ) const;
|
bool operator < ( SourceLineInfo const& other ) const noexcept;
|
||||||
|
|
||||||
char const* file;
|
char const* file;
|
||||||
std::size_t line;
|
std::size_t line;
|
||||||
@ -115,23 +61,16 @@ namespace Catch {
|
|||||||
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
|
std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info );
|
||||||
|
|
||||||
// This is just here to avoid compiler warnings with macro constants and boolean literals
|
// This is just here to avoid compiler warnings with macro constants and boolean literals
|
||||||
inline bool isTrue( bool value ){ return value; }
|
bool isTrue( bool value );
|
||||||
inline bool alwaysTrue() { return true; }
|
bool alwaysTrue();
|
||||||
inline bool alwaysFalse() { return false; }
|
bool alwaysFalse();
|
||||||
|
|
||||||
void throwLogicError( std::string const& message, SourceLineInfo const& locationInfo );
|
|
||||||
|
|
||||||
void seedRng( IConfig const& config );
|
|
||||||
unsigned int rngSeed();
|
|
||||||
|
|
||||||
// Use this in variadic streaming macros to allow
|
// Use this in variadic streaming macros to allow
|
||||||
// >> +StreamEndStop
|
// >> +StreamEndStop
|
||||||
// as well as
|
// as well as
|
||||||
// >> stuff +StreamEndStop
|
// >> stuff +StreamEndStop
|
||||||
struct StreamEndStop {
|
struct StreamEndStop {
|
||||||
std::string operator+() {
|
std::string operator+() const;
|
||||||
return std::string();
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
template<typename T>
|
template<typename T>
|
||||||
T const& operator + ( T const& value, StreamEndStop ) {
|
T const& operator + ( T const& value, StreamEndStop ) {
|
||||||
@ -139,8 +78,8 @@ namespace Catch {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define CATCH_INTERNAL_LINEINFO ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
|
#define CATCH_INTERNAL_LINEINFO \
|
||||||
#define CATCH_INTERNAL_ERROR( msg ) ::Catch::throwLogicError( msg, CATCH_INTERNAL_LINEINFO );
|
::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) )
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_COMMON_H_INCLUDED
|
||||||
|
|
||||||
|
@ -8,23 +8,9 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
||||||
|
|
||||||
// Detect a number of compiler features - mostly C++11/14 conformance - by compiler
|
// Detect a number of compiler features - by compiler
|
||||||
// The following features are defined:
|
// The following features are defined:
|
||||||
//
|
//
|
||||||
// CATCH_CONFIG_CPP11_NULLPTR : is nullptr supported?
|
|
||||||
// CATCH_CONFIG_CPP11_NOEXCEPT : is noexcept supported?
|
|
||||||
// CATCH_CONFIG_CPP11_GENERATED_METHODS : The delete and default keywords for compiler generated methods
|
|
||||||
// CATCH_CONFIG_CPP11_IS_ENUM : std::is_enum is supported?
|
|
||||||
// CATCH_CONFIG_CPP11_TUPLE : std::tuple is supported
|
|
||||||
// CATCH_CONFIG_CPP11_LONG_LONG : is long long supported?
|
|
||||||
// CATCH_CONFIG_CPP11_OVERRIDE : is override supported?
|
|
||||||
// CATCH_CONFIG_CPP11_UNIQUE_PTR : is unique_ptr supported (otherwise use auto_ptr)
|
|
||||||
// CATCH_CONFIG_CPP11_SHUFFLE : is std::shuffle supported?
|
|
||||||
// CATCH_CONFIG_CPP11_TYPE_TRAITS : are type_traits and enable_if supported?
|
|
||||||
|
|
||||||
// CATCH_CONFIG_CPP11_OR_GREATER : Is C++11 supported?
|
|
||||||
|
|
||||||
// CATCH_CONFIG_VARIADIC_MACROS : are variadic macros supported?
|
|
||||||
// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
|
// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported?
|
||||||
// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
|
// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported?
|
||||||
// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
|
// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported?
|
||||||
@ -34,18 +20,13 @@
|
|||||||
// ****************
|
// ****************
|
||||||
|
|
||||||
// In general each macro has a _NO_<feature name> form
|
// In general each macro has a _NO_<feature name> form
|
||||||
// (e.g. CATCH_CONFIG_CPP11_NO_NULLPTR) which disables the feature.
|
// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature.
|
||||||
// Many features, at point of detection, define an _INTERNAL_ macro, so they
|
// Many features, at point of detection, define an _INTERNAL_ macro, so they
|
||||||
// can be combined, en-mass, with the _NO_ forms later.
|
// can be combined, en-mass, with the _NO_ forms later.
|
||||||
|
|
||||||
// All the C++11 features can be disabled with CATCH_CONFIG_NO_CPP11
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
||||||
# if __cplusplus >= 201103L
|
|
||||||
# define CATCH_CPP11_OR_GREATER
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if __cplusplus >= 201402L
|
# if __cplusplus >= 201402L
|
||||||
# define CATCH_CPP14_OR_GREATER
|
# define CATCH_CPP14_OR_GREATER
|
||||||
# endif
|
# endif
|
||||||
@ -54,19 +35,11 @@
|
|||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
|
||||||
# if __has_feature(cxx_nullptr)
|
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if __has_feature(cxx_noexcept)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if defined(CATCH_CPP11_OR_GREATER)
|
|
||||||
# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS \
|
|
||||||
_Pragma( "clang diagnostic push" ) \
|
_Pragma( "clang diagnostic push" ) \
|
||||||
_Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" )
|
_Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \
|
||||||
# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS \
|
_Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"")
|
||||||
|
# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS \
|
||||||
_Pragma( "clang diagnostic pop" )
|
_Pragma( "clang diagnostic pop" )
|
||||||
|
|
||||||
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
||||||
@ -74,7 +47,6 @@
|
|||||||
_Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
|
_Pragma( "clang diagnostic ignored \"-Wparentheses\"" )
|
||||||
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
|
||||||
_Pragma( "clang diagnostic pop" )
|
_Pragma( "clang diagnostic pop" )
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif // __clang__
|
#endif // __clang__
|
||||||
|
|
||||||
@ -104,174 +76,34 @@
|
|||||||
|
|
||||||
#endif // __CYGWIN__
|
#endif // __CYGWIN__
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Borland
|
|
||||||
#ifdef __BORLANDC__
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __BORLANDC__
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// EDG
|
|
||||||
#ifdef __EDG_VERSION__
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __EDG_VERSION__
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Digital Mars
|
|
||||||
#ifdef __DMC__
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __DMC__
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// GCC
|
|
||||||
#ifdef __GNUC__
|
|
||||||
|
|
||||||
# if __GNUC__ == 4 && __GNUC_MINOR__ >= 6 && defined(__GXX_EXPERIMENTAL_CXX0X__)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
|
|
||||||
# endif
|
|
||||||
|
|
||||||
|
|
||||||
// - otherwise more recent versions define __cplusplus >= 201103L
|
|
||||||
// and will get picked up below
|
|
||||||
|
|
||||||
|
|
||||||
#endif // __GNUC__
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Visual C++
|
// Visual C++
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
|
|
||||||
#define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
|
// Universal Windows platform does not support SEH
|
||||||
|
// Or console colours (or console at all...)
|
||||||
#if (_MSC_VER >= 1600)
|
# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP)
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
|
# define CATCH_CONFIG_COLOUR_NONE
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
|
# else
|
||||||
#endif
|
# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH
|
||||||
|
# endif
|
||||||
#if (_MSC_VER >= 1900 ) // (VC++ 13 (VS2015))
|
|
||||||
#define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
|
|
||||||
#define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
#define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
|
|
||||||
#define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // _MSC_VER
|
#endif // _MSC_VER
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// Use variadic macros if the compiler supports them
|
// Use of __COUNTER__ is suppressed during code analysis in
|
||||||
#if ( defined _MSC_VER && _MSC_VER > 1400 && !defined __EDGE__) || \
|
// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly
|
||||||
( defined __WAVE__ && __WAVE_HAS_VARIADICS ) || \
|
// handled by it.
|
||||||
( defined __GNUC__ && __GNUC__ >= 3 ) || \
|
// Otherwise all supported compilers support COUNTER macro,
|
||||||
( !defined __cplusplus && __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L )
|
// but user still might want to turn it off
|
||||||
|
#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L )
|
||||||
#define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Use __COUNTER__ if the compiler supports it
|
|
||||||
#if ( defined _MSC_VER && _MSC_VER >= 1300 ) || \
|
|
||||||
( defined __GNUC__ && ( __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 3 )) ) || \
|
|
||||||
( defined __clang__ && __clang_major__ >= 3 )
|
|
||||||
|
|
||||||
// Use of __COUNTER__ is suppressed during code analysis in CLion/AppCode 2017.2.x and former,
|
|
||||||
// because __COUNTER__ is not properly handled by it.
|
|
||||||
// This does not affect compilation
|
|
||||||
#if ( !defined __JETBRAINS_IDE__ || __JETBRAINS_IDE__ >= 20170300L )
|
|
||||||
#define CATCH_INTERNAL_CONFIG_COUNTER
|
#define CATCH_INTERNAL_CONFIG_COUNTER
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// C++ language feature support
|
|
||||||
|
|
||||||
// catch all support for C++11
|
|
||||||
#if defined(CATCH_CPP11_OR_GREATER)
|
|
||||||
|
|
||||||
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_NULLPTR
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef CATCH_INTERNAL_CONFIG_CPP11_TUPLE
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_TUPLE
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# ifndef CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
|
|
||||||
# define CATCH_INTERNAL_CONFIG_VARIADIC_MACROS
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG
|
|
||||||
# endif
|
|
||||||
|
|
||||||
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE
|
|
||||||
# endif
|
|
||||||
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR
|
|
||||||
# endif
|
|
||||||
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE
|
|
||||||
# endif
|
|
||||||
# if !defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS)
|
|
||||||
# define CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS
|
|
||||||
# endif
|
|
||||||
|
|
||||||
#endif // __cplusplus >= 201103L
|
|
||||||
|
|
||||||
// Now set the actual defines based on the above + anything the user has configured
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NO_NULLPTR) && !defined(CATCH_CONFIG_CPP11_NULLPTR) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_NULLPTR
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NO_NOEXCEPT) && !defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_NOEXCEPT
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_NO_GENERATED_METHODS) && !defined(CATCH_CONFIG_CPP11_GENERATED_METHODS) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_NO_IS_ENUM) && !defined(CATCH_CONFIG_CPP11_IS_ENUM) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_IS_ENUM
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_CPP11_NO_TUPLE) && !defined(CATCH_CONFIG_CPP11_TUPLE) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_TUPLE
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_VARIADIC_MACROS) && !defined(CATCH_CONFIG_NO_VARIADIC_MACROS) && !defined(CATCH_CONFIG_VARIADIC_MACROS)
|
|
||||||
# define CATCH_CONFIG_VARIADIC_MACROS
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_NO_LONG_LONG) && !defined(CATCH_CONFIG_CPP11_LONG_LONG) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_LONG_LONG
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_NO_OVERRIDE) && !defined(CATCH_CONFIG_CPP11_OVERRIDE) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_OVERRIDE
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_NO_UNIQUE_PTR) && !defined(CATCH_CONFIG_CPP11_UNIQUE_PTR) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_UNIQUE_PTR
|
|
||||||
#endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
|
#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER)
|
||||||
# define CATCH_CONFIG_COUNTER
|
# define CATCH_CONFIG_COUNTER
|
||||||
#endif
|
#endif
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_NO_SHUFFLE) && !defined(CATCH_CONFIG_CPP11_SHUFFLE) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_SHUFFLE
|
|
||||||
#endif
|
|
||||||
# if defined(CATCH_INTERNAL_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_NO_TYPE_TRAITS) && !defined(CATCH_CONFIG_CPP11_TYPE_TRAITS) && !defined(CATCH_CONFIG_NO_CPP11)
|
|
||||||
# define CATCH_CONFIG_CPP11_TYPE_TRAITS
|
|
||||||
# endif
|
|
||||||
#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
|
#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH)
|
||||||
# define CATCH_CONFIG_WINDOWS_SEH
|
# define CATCH_CONFIG_WINDOWS_SEH
|
||||||
#endif
|
#endif
|
||||||
@ -284,40 +116,11 @@
|
|||||||
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
|
# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS
|
||||||
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
|
# define CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
#if !defined(CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS)
|
#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS)
|
||||||
# define CATCH_INTERNAL_SUPPRESS_ETD_WARNINGS
|
# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS
|
||||||
# define CATCH_INTERNAL_UNSUPPRESS_ETD_WARNINGS
|
# define CATCH_INTERNAL_UNSUPPRESS_GLOBALS_WARNINGS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// noexcept support:
|
|
||||||
#if defined(CATCH_CONFIG_CPP11_NOEXCEPT) && !defined(CATCH_NOEXCEPT)
|
|
||||||
# define CATCH_NOEXCEPT noexcept
|
|
||||||
# define CATCH_NOEXCEPT_IS(x) noexcept(x)
|
|
||||||
#else
|
|
||||||
# define CATCH_NOEXCEPT throw()
|
|
||||||
# define CATCH_NOEXCEPT_IS(x)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// nullptr support
|
|
||||||
#ifdef CATCH_CONFIG_CPP11_NULLPTR
|
|
||||||
# define CATCH_NULL nullptr
|
|
||||||
#else
|
|
||||||
# define CATCH_NULL NULL
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// override support
|
|
||||||
#ifdef CATCH_CONFIG_CPP11_OVERRIDE
|
|
||||||
# define CATCH_OVERRIDE override
|
|
||||||
#else
|
|
||||||
# define CATCH_OVERRIDE
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// unique_ptr support
|
|
||||||
#ifdef CATCH_CONFIG_CPP11_UNIQUE_PTR
|
|
||||||
# define CATCH_AUTO_PTR( T ) std::unique_ptr<T>
|
|
||||||
#else
|
|
||||||
# define CATCH_AUTO_PTR( T ) std::auto_ptr<T>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_COMPILER_CAPABILITIES_HPP_INCLUDED
|
||||||
|
|
||||||
|
73
include/internal/catch_config.cpp
Normal file
73
include/internal/catch_config.cpp
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 19/07/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_config.hpp"
|
||||||
|
#include "catch_enforce.h"
|
||||||
|
#include "catch_stream.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
Config::Config( ConfigData const& data )
|
||||||
|
: m_data( data ),
|
||||||
|
m_stream( openStream() )
|
||||||
|
{
|
||||||
|
if( !data.testsOrTags.empty() ) {
|
||||||
|
TestSpecParser parser( ITagAliasRegistry::get() );
|
||||||
|
for( auto const& testOrTags : data.testsOrTags )
|
||||||
|
parser.parse( testOrTags );
|
||||||
|
m_testSpec = parser.testSpec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string const& Config::getFilename() const {
|
||||||
|
return m_data.outputFilename ;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Config::listTests() const { return m_data.listTests; }
|
||||||
|
bool Config::listTestNamesOnly() const { return m_data.listTestNamesOnly; }
|
||||||
|
bool Config::listTags() const { return m_data.listTags; }
|
||||||
|
bool Config::listReporters() const { return m_data.listReporters; }
|
||||||
|
|
||||||
|
std::string Config::getProcessName() const { return m_data.processName; }
|
||||||
|
|
||||||
|
std::vector<std::string> const& Config::getReporterNames() const { return m_data.reporterNames; }
|
||||||
|
std::vector<std::string> const& Config::getSectionsToRun() const { return m_data.sectionsToRun; }
|
||||||
|
|
||||||
|
TestSpec const& Config::testSpec() const { return m_testSpec; }
|
||||||
|
|
||||||
|
bool Config::showHelp() const { return m_data.showHelp; }
|
||||||
|
|
||||||
|
// IConfig interface
|
||||||
|
bool Config::allowThrows() const { return !m_data.noThrow; }
|
||||||
|
std::ostream& Config::stream() const { return m_stream->stream(); }
|
||||||
|
std::string Config::name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
||||||
|
bool Config::includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
||||||
|
bool Config::warnAboutMissingAssertions() const { return m_data.warnings & WarnAbout::NoAssertions; }
|
||||||
|
ShowDurations::OrNot Config::showDurations() const { return m_data.showDurations; }
|
||||||
|
RunTests::InWhatOrder Config::runOrder() const { return m_data.runOrder; }
|
||||||
|
unsigned int Config::rngSeed() const { return m_data.rngSeed; }
|
||||||
|
int Config::benchmarkResolutionMultiple() const { return m_data.benchmarkResolutionMultiple; }
|
||||||
|
UseColour::YesOrNo Config::useColour() const { return m_data.useColour; }
|
||||||
|
bool Config::shouldDebugBreak() const { return m_data.shouldDebugBreak; }
|
||||||
|
int Config::abortAfter() const { return m_data.abortAfter; }
|
||||||
|
bool Config::showInvisibles() const { return m_data.showInvisibles; }
|
||||||
|
Verbosity Config::verbosity() const { return m_data.verbosity; }
|
||||||
|
|
||||||
|
IStream const* Config::openStream() {
|
||||||
|
if( m_data.outputFilename.empty() )
|
||||||
|
return new CoutStream();
|
||||||
|
else if( m_data.outputFilename[0] == '%' ) {
|
||||||
|
if( m_data.outputFilename == "%debug" )
|
||||||
|
return new DebugOutStream();
|
||||||
|
else
|
||||||
|
CATCH_ERROR( "Unrecognised stream: '" << m_data.outputFilename << "'" );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return new FileStream( m_data.outputFilename );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
@ -8,15 +8,15 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_CONFIG_HPP_INCLUDED
|
||||||
|
|
||||||
#include "catch_test_spec_parser.hpp"
|
#include "catch_test_spec_parser.h"
|
||||||
#include "catch_context.h"
|
|
||||||
#include "catch_interfaces_config.h"
|
#include "catch_interfaces_config.h"
|
||||||
|
|
||||||
|
// Libstdc++ doesn't like incomplete classes for unique_ptr
|
||||||
#include "catch_stream.h"
|
#include "catch_stream.h"
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <stdexcept>
|
|
||||||
|
|
||||||
#ifndef CATCH_CONFIG_CONSOLE_WIDTH
|
#ifndef CATCH_CONFIG_CONSOLE_WIDTH
|
||||||
#define CATCH_CONFIG_CONSOLE_WIDTH 80
|
#define CATCH_CONFIG_CONSOLE_WIDTH 80
|
||||||
@ -24,54 +24,32 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
struct IStream;
|
||||||
|
|
||||||
struct ConfigData {
|
struct ConfigData {
|
||||||
|
bool listTests = false;
|
||||||
|
bool listTags = false;
|
||||||
|
bool listReporters = false;
|
||||||
|
bool listTestNamesOnly = false;
|
||||||
|
|
||||||
ConfigData()
|
bool showSuccessfulTests = false;
|
||||||
: listTests( false ),
|
bool shouldDebugBreak = false;
|
||||||
listTags( false ),
|
bool noThrow = false;
|
||||||
listReporters( false ),
|
bool showHelp = false;
|
||||||
listTestNamesOnly( false ),
|
bool showInvisibles = false;
|
||||||
listExtraInfo( false ),
|
bool filenamesAsTags = false;
|
||||||
showSuccessfulTests( false ),
|
bool libIdentify = false;
|
||||||
shouldDebugBreak( false ),
|
|
||||||
noThrow( false ),
|
|
||||||
showHelp( false ),
|
|
||||||
showInvisibles( false ),
|
|
||||||
filenamesAsTags( false ),
|
|
||||||
libIdentify( false ),
|
|
||||||
abortAfter( -1 ),
|
|
||||||
rngSeed( 0 ),
|
|
||||||
verbosity( Verbosity::Normal ),
|
|
||||||
warnings( WarnAbout::Nothing ),
|
|
||||||
showDurations( ShowDurations::DefaultForReporter ),
|
|
||||||
runOrder( RunTests::InDeclarationOrder ),
|
|
||||||
useColour( UseColour::Auto ),
|
|
||||||
waitForKeypress( WaitForKeypress::Never )
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool listTests;
|
int abortAfter = -1;
|
||||||
bool listTags;
|
unsigned int rngSeed = 0;
|
||||||
bool listReporters;
|
int benchmarkResolutionMultiple = 100;
|
||||||
bool listTestNamesOnly;
|
|
||||||
bool listExtraInfo;
|
|
||||||
|
|
||||||
bool showSuccessfulTests;
|
Verbosity verbosity = Verbosity::Normal;
|
||||||
bool shouldDebugBreak;
|
WarnAbout::What warnings = WarnAbout::Nothing;
|
||||||
bool noThrow;
|
ShowDurations::OrNot showDurations = ShowDurations::DefaultForReporter;
|
||||||
bool showHelp;
|
RunTests::InWhatOrder runOrder = RunTests::InDeclarationOrder;
|
||||||
bool showInvisibles;
|
UseColour::YesOrNo useColour = UseColour::Auto;
|
||||||
bool filenamesAsTags;
|
WaitForKeypress::When waitForKeypress = WaitForKeypress::Never;
|
||||||
bool libIdentify;
|
|
||||||
|
|
||||||
int abortAfter;
|
|
||||||
unsigned int rngSeed;
|
|
||||||
|
|
||||||
Verbosity::Level verbosity;
|
|
||||||
WarnAbout::What warnings;
|
|
||||||
ShowDurations::OrNot showDurations;
|
|
||||||
RunTests::InWhatOrder runOrder;
|
|
||||||
UseColour::YesOrNo useColour;
|
|
||||||
WaitForKeypress::When waitForKeypress;
|
|
||||||
|
|
||||||
std::string outputFilename;
|
std::string outputFilename;
|
||||||
std::string name;
|
std::string name;
|
||||||
@ -83,80 +61,51 @@ namespace Catch {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Config : public SharedImpl<IConfig> {
|
class Config : public IConfig {
|
||||||
private:
|
|
||||||
Config( Config const& other );
|
|
||||||
Config& operator = ( Config const& other );
|
|
||||||
virtual void dummy();
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
Config()
|
Config() = default;
|
||||||
{}
|
Config( ConfigData const& data );
|
||||||
|
virtual ~Config() = default;
|
||||||
|
|
||||||
Config( ConfigData const& data )
|
std::string const& getFilename() const;
|
||||||
: m_data( data ),
|
|
||||||
m_stream( openStream() )
|
|
||||||
{
|
|
||||||
if( !data.testsOrTags.empty() ) {
|
|
||||||
TestSpecParser parser( ITagAliasRegistry::get() );
|
|
||||||
for( std::size_t i = 0; i < data.testsOrTags.size(); ++i )
|
|
||||||
parser.parse( data.testsOrTags[i] );
|
|
||||||
m_testSpec = parser.testSpec();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual ~Config() {}
|
bool listTests() const;
|
||||||
|
bool listTestNamesOnly() const;
|
||||||
|
bool listTags() const;
|
||||||
|
bool listReporters() const;
|
||||||
|
|
||||||
std::string const& getFilename() const {
|
std::string getProcessName() const;
|
||||||
return m_data.outputFilename ;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool listTests() const { return m_data.listTests; }
|
std::vector<std::string> const& getReporterNames() const;
|
||||||
bool listTestNamesOnly() const { return m_data.listTestNamesOnly; }
|
std::vector<std::string> const& getSectionsToRun() const override;
|
||||||
bool listTags() const { return m_data.listTags; }
|
|
||||||
bool listReporters() const { return m_data.listReporters; }
|
|
||||||
bool listExtraInfo() const { return m_data.listExtraInfo; }
|
|
||||||
|
|
||||||
std::string getProcessName() const { return m_data.processName; }
|
virtual TestSpec const& testSpec() const override;
|
||||||
|
|
||||||
std::vector<std::string> const& getReporterNames() const { return m_data.reporterNames; }
|
bool showHelp() const;
|
||||||
std::vector<std::string> const& getSectionsToRun() const CATCH_OVERRIDE { return m_data.sectionsToRun; }
|
|
||||||
|
|
||||||
virtual TestSpec const& testSpec() const CATCH_OVERRIDE { return m_testSpec; }
|
|
||||||
|
|
||||||
bool showHelp() const { return m_data.showHelp; }
|
|
||||||
|
|
||||||
// IConfig interface
|
// IConfig interface
|
||||||
virtual bool allowThrows() const CATCH_OVERRIDE { return !m_data.noThrow; }
|
bool allowThrows() const override;
|
||||||
virtual std::ostream& stream() const CATCH_OVERRIDE { return m_stream->stream(); }
|
std::ostream& stream() const override;
|
||||||
virtual std::string name() const CATCH_OVERRIDE { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
std::string name() const override;
|
||||||
virtual bool includeSuccessfulResults() const CATCH_OVERRIDE { return m_data.showSuccessfulTests; }
|
bool includeSuccessfulResults() const override;
|
||||||
virtual bool warnAboutMissingAssertions() const CATCH_OVERRIDE { return m_data.warnings & WarnAbout::NoAssertions; }
|
bool warnAboutMissingAssertions() const override;
|
||||||
virtual ShowDurations::OrNot showDurations() const CATCH_OVERRIDE { return m_data.showDurations; }
|
ShowDurations::OrNot showDurations() const override;
|
||||||
virtual RunTests::InWhatOrder runOrder() const CATCH_OVERRIDE { return m_data.runOrder; }
|
RunTests::InWhatOrder runOrder() const override;
|
||||||
virtual unsigned int rngSeed() const CATCH_OVERRIDE { return m_data.rngSeed; }
|
unsigned int rngSeed() const override;
|
||||||
virtual UseColour::YesOrNo useColour() const CATCH_OVERRIDE { return m_data.useColour; }
|
int benchmarkResolutionMultiple() const override;
|
||||||
virtual bool shouldDebugBreak() const CATCH_OVERRIDE { return m_data.shouldDebugBreak; }
|
UseColour::YesOrNo useColour() const override;
|
||||||
virtual int abortAfter() const CATCH_OVERRIDE { return m_data.abortAfter; }
|
bool shouldDebugBreak() const override;
|
||||||
virtual bool showInvisibles() const CATCH_OVERRIDE { return m_data.showInvisibles; }
|
int abortAfter() const override;
|
||||||
|
bool showInvisibles() const override;
|
||||||
|
Verbosity verbosity() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
IStream const* openStream() {
|
IStream const* openStream();
|
||||||
if( m_data.outputFilename.empty() )
|
|
||||||
return new CoutStream();
|
|
||||||
else if( m_data.outputFilename[0] == '%' ) {
|
|
||||||
if( m_data.outputFilename == "%debug" )
|
|
||||||
return new DebugOutStream();
|
|
||||||
else
|
|
||||||
throw std::domain_error( "Unrecognised stream: " + m_data.outputFilename );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return new FileStream( m_data.outputFilename );
|
|
||||||
}
|
|
||||||
ConfigData m_data;
|
ConfigData m_data;
|
||||||
|
|
||||||
CATCH_AUTO_PTR( IStream const ) m_stream;
|
std::unique_ptr<IStream const> m_stream;
|
||||||
TestSpec m_testSpec;
|
TestSpec m_testSpec;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -5,17 +5,29 @@
|
|||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*/
|
*/
|
||||||
#ifndef TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_console_colour.hpp"
|
|
||||||
#include "catch_errno_guard.hpp"
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic push
|
||||||
|
# pragma clang diagnostic ignored "-Wexit-time-destructors"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#include "catch_console_colour.h"
|
||||||
|
#include "catch_enforce.h"
|
||||||
|
#include "catch_errno_guard.h"
|
||||||
|
#include "catch_interfaces_config.h"
|
||||||
|
#include "catch_stream.h"
|
||||||
|
#include "catch_context.h"
|
||||||
|
#include "catch_platform.h"
|
||||||
|
#include "catch_debugger.h"
|
||||||
|
#include "catch_windows_h_proxy.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
struct IColourImpl {
|
struct IColourImpl {
|
||||||
virtual ~IColourImpl() {}
|
virtual ~IColourImpl() = default;
|
||||||
virtual void use( Colour::Code _colourCode ) = 0;
|
virtual void use( Colour::Code _colourCode ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -42,8 +54,6 @@ namespace Catch {
|
|||||||
|
|
||||||
#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
|
#if defined ( CATCH_CONFIG_COLOUR_WINDOWS ) /////////////////////////////////////////
|
||||||
|
|
||||||
#include "catch_windows_h_proxy.h"
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
@ -57,7 +67,7 @@ namespace {
|
|||||||
originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
|
originalBackgroundAttributes = csbiInfo.wAttributes & ~( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void use( Colour::Code _colourCode ) {
|
virtual void use( Colour::Code _colourCode ) override {
|
||||||
switch( _colourCode ) {
|
switch( _colourCode ) {
|
||||||
case Colour::None: return setTextAttribute( originalForegroundAttributes );
|
case Colour::None: return setTextAttribute( originalForegroundAttributes );
|
||||||
case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
|
case Colour::White: return setTextAttribute( FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
|
||||||
@ -73,7 +83,7 @@ namespace {
|
|||||||
case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
|
case Colour::BrightGreen: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN );
|
||||||
case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
|
case Colour::BrightWhite: return setTextAttribute( FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_RED | FOREGROUND_BLUE );
|
||||||
|
|
||||||
case Colour::Bright: throw std::logic_error( "not a colour" );
|
case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,14 +99,12 @@ namespace {
|
|||||||
IColourImpl* platformColourInstance() {
|
IColourImpl* platformColourInstance() {
|
||||||
static Win32ColourImpl s_instance;
|
static Win32ColourImpl s_instance;
|
||||||
|
|
||||||
Ptr<IConfig const> config = getCurrentContext().getConfig();
|
IConfigPtr config = getCurrentContext().getConfig();
|
||||||
UseColour::YesOrNo colourMode = config
|
UseColour::YesOrNo colourMode = config
|
||||||
? config->useColour()
|
? config->useColour()
|
||||||
: UseColour::Auto;
|
: UseColour::Auto;
|
||||||
if( colourMode == UseColour::Auto )
|
if( colourMode == UseColour::Auto )
|
||||||
colourMode = !isDebuggerActive()
|
colourMode = UseColour::Yes;
|
||||||
? UseColour::Yes
|
|
||||||
: UseColour::No;
|
|
||||||
return colourMode == UseColour::Yes
|
return colourMode == UseColour::Yes
|
||||||
? &s_instance
|
? &s_instance
|
||||||
: NoColourImpl::instance();
|
: NoColourImpl::instance();
|
||||||
@ -118,7 +126,7 @@ namespace {
|
|||||||
// https://github.com/philsquared/Catch/pull/131
|
// https://github.com/philsquared/Catch/pull/131
|
||||||
class PosixColourImpl : public IColourImpl {
|
class PosixColourImpl : public IColourImpl {
|
||||||
public:
|
public:
|
||||||
virtual void use( Colour::Code _colourCode ) {
|
virtual void use( Colour::Code _colourCode ) override {
|
||||||
switch( _colourCode ) {
|
switch( _colourCode ) {
|
||||||
case Colour::None:
|
case Colour::None:
|
||||||
case Colour::White: return setColour( "[0m" );
|
case Colour::White: return setColour( "[0m" );
|
||||||
@ -134,7 +142,7 @@ namespace {
|
|||||||
case Colour::BrightGreen: return setColour( "[1;32m" );
|
case Colour::BrightGreen: return setColour( "[1;32m" );
|
||||||
case Colour::BrightWhite: return setColour( "[1;37m" );
|
case Colour::BrightWhite: return setColour( "[1;37m" );
|
||||||
|
|
||||||
case Colour::Bright: throw std::logic_error( "not a colour" );
|
case Colour::Bright: CATCH_INTERNAL_ERROR( "not a colour" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static IColourImpl* instance() {
|
static IColourImpl* instance() {
|
||||||
@ -148,14 +156,21 @@ namespace {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
bool useColourOnPlatform() {
|
||||||
|
return
|
||||||
|
#ifdef CATCH_PLATFORM_MAC
|
||||||
|
!isDebuggerActive() &&
|
||||||
|
#endif
|
||||||
|
isatty(STDOUT_FILENO);
|
||||||
|
}
|
||||||
IColourImpl* platformColourInstance() {
|
IColourImpl* platformColourInstance() {
|
||||||
ErrnoGuard guard;
|
ErrnoGuard guard;
|
||||||
Ptr<IConfig const> config = getCurrentContext().getConfig();
|
IConfigPtr config = getCurrentContext().getConfig();
|
||||||
UseColour::YesOrNo colourMode = config
|
UseColour::YesOrNo colourMode = config
|
||||||
? config->useColour()
|
? config->useColour()
|
||||||
: UseColour::Auto;
|
: UseColour::Auto;
|
||||||
if( colourMode == UseColour::Auto )
|
if( colourMode == UseColour::Auto )
|
||||||
colourMode = (!isDebuggerActive() && isatty(STDOUT_FILENO) )
|
colourMode = useColourOnPlatform()
|
||||||
? UseColour::Yes
|
? UseColour::Yes
|
||||||
: UseColour::No;
|
: UseColour::No;
|
||||||
return colourMode == UseColour::Yes
|
return colourMode == UseColour::Yes
|
||||||
@ -178,8 +193,17 @@ namespace Catch {
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
Colour::Colour( Code _colourCode ) : m_moved( false ) { use( _colourCode ); }
|
Colour::Colour( Code _colourCode ) { use( _colourCode ); }
|
||||||
Colour::Colour( Colour const& _other ) : m_moved( false ) { const_cast<Colour&>( _other ).m_moved = true; }
|
Colour::Colour( Colour&& rhs ) noexcept {
|
||||||
|
m_moved = rhs.m_moved;
|
||||||
|
rhs.m_moved = true;
|
||||||
|
}
|
||||||
|
Colour& Colour::operator=( Colour&& rhs ) noexcept {
|
||||||
|
m_moved = rhs.m_moved;
|
||||||
|
rhs.m_moved = true;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
Colour::~Colour(){ if( !m_moved ) use( None ); }
|
Colour::~Colour(){ if( !m_moved ) use( None ); }
|
||||||
|
|
||||||
void Colour::use( Code _colourCode ) {
|
void Colour::use( Code _colourCode ) {
|
||||||
@ -187,6 +211,13 @@ namespace Catch {
|
|||||||
impl->use( _colourCode );
|
impl->use( _colourCode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::ostream& operator << ( std::ostream& os, Colour const& ) {
|
||||||
|
return os;
|
||||||
|
}
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CONSOLE_COLOUR_IMPL_HPP_INCLUDED
|
#if defined(__clang__)
|
||||||
|
# pragma clang diagnostic pop
|
||||||
|
#endif
|
||||||
|
|
@ -50,17 +50,18 @@ namespace Catch {
|
|||||||
|
|
||||||
// Use constructed object for RAII guard
|
// Use constructed object for RAII guard
|
||||||
Colour( Code _colourCode );
|
Colour( Code _colourCode );
|
||||||
Colour( Colour const& other );
|
Colour( Colour&& other ) noexcept;
|
||||||
|
Colour& operator=( Colour&& other ) noexcept;
|
||||||
~Colour();
|
~Colour();
|
||||||
|
|
||||||
// Use static method for one-shot changes
|
// Use static method for one-shot changes
|
||||||
static void use( Code _colourCode );
|
static void use( Code _colourCode );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_moved;
|
bool m_moved = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator << ( std::ostream& os, Colour const& ) { return os; }
|
std::ostream& operator << ( std::ostream& os, Colour const& );
|
||||||
|
|
||||||
} // end namespace Catch
|
} // end namespace Catch
|
||||||
|
|
67
include/internal/catch_context.cpp
Normal file
67
include/internal/catch_context.cpp
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 31/12/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#include "catch_context.h"
|
||||||
|
#include "catch_common.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
class Context : public IMutableContext, NonCopyable {
|
||||||
|
|
||||||
|
public: // IContext
|
||||||
|
virtual IResultCapture* getResultCapture() override {
|
||||||
|
return m_resultCapture;
|
||||||
|
}
|
||||||
|
virtual IRunner* getRunner() override {
|
||||||
|
return m_runner;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual IConfigPtr getConfig() const override {
|
||||||
|
return m_config;
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual ~Context() override;
|
||||||
|
|
||||||
|
public: // IMutableContext
|
||||||
|
virtual void setResultCapture( IResultCapture* resultCapture ) override {
|
||||||
|
m_resultCapture = resultCapture;
|
||||||
|
}
|
||||||
|
virtual void setRunner( IRunner* runner ) override {
|
||||||
|
m_runner = runner;
|
||||||
|
}
|
||||||
|
virtual void setConfig( IConfigPtr const& config ) override {
|
||||||
|
m_config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
friend IMutableContext& getCurrentMutableContext();
|
||||||
|
|
||||||
|
private:
|
||||||
|
IConfigPtr m_config;
|
||||||
|
IRunner* m_runner = nullptr;
|
||||||
|
IResultCapture* m_resultCapture = nullptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
Context* currentContext = nullptr;
|
||||||
|
}
|
||||||
|
IMutableContext& getCurrentMutableContext() {
|
||||||
|
if( !currentContext )
|
||||||
|
currentContext = new Context();
|
||||||
|
return *currentContext;
|
||||||
|
}
|
||||||
|
IContext& getCurrentContext() {
|
||||||
|
return getCurrentMutableContext();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cleanUpContext() {
|
||||||
|
delete currentContext;
|
||||||
|
currentContext = nullptr;
|
||||||
|
}
|
||||||
|
IContext::~IContext() = default;
|
||||||
|
IMutableContext::~IMutableContext() = default;
|
||||||
|
Context::~Context() = default;
|
||||||
|
}
|
@ -8,28 +8,23 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_interfaces_generators.h"
|
#include <memory>
|
||||||
#include "catch_ptr.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class TestCase;
|
|
||||||
class Stream;
|
|
||||||
struct IResultCapture;
|
struct IResultCapture;
|
||||||
struct IRunner;
|
struct IRunner;
|
||||||
struct IGeneratorsForTest;
|
|
||||||
struct IConfig;
|
struct IConfig;
|
||||||
|
|
||||||
|
using IConfigPtr = std::shared_ptr<IConfig const>;
|
||||||
|
|
||||||
struct IContext
|
struct IContext
|
||||||
{
|
{
|
||||||
virtual ~IContext();
|
virtual ~IContext();
|
||||||
|
|
||||||
virtual IResultCapture* getResultCapture() = 0;
|
virtual IResultCapture* getResultCapture() = 0;
|
||||||
virtual IRunner* getRunner() = 0;
|
virtual IRunner* getRunner() = 0;
|
||||||
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) = 0;
|
virtual IConfigPtr getConfig() const = 0;
|
||||||
virtual bool advanceGeneratorsForCurrentTest() = 0;
|
|
||||||
virtual Ptr<IConfig const> getConfig() const = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IMutableContext : IContext
|
struct IMutableContext : IContext
|
||||||
@ -37,14 +32,12 @@ namespace Catch {
|
|||||||
virtual ~IMutableContext();
|
virtual ~IMutableContext();
|
||||||
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
|
virtual void setResultCapture( IResultCapture* resultCapture ) = 0;
|
||||||
virtual void setRunner( IRunner* runner ) = 0;
|
virtual void setRunner( IRunner* runner ) = 0;
|
||||||
virtual void setConfig( Ptr<IConfig const> const& config ) = 0;
|
virtual void setConfig( IConfigPtr const& config ) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
IContext& getCurrentContext();
|
IContext& getCurrentContext();
|
||||||
IMutableContext& getCurrentMutableContext();
|
IMutableContext& getCurrentMutableContext();
|
||||||
void cleanUpContext();
|
void cleanUpContext();
|
||||||
Stream createStream( std::string const& streamName );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_CONTEXT_H_INCLUDED
|
||||||
|
@ -1,110 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 31/12/2010.
|
|
||||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_run_context.hpp"
|
|
||||||
|
|
||||||
#include "catch_context.h"
|
|
||||||
#include "catch_stream.hpp"
|
|
||||||
#include "catch_common.h"
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
class Context : public IMutableContext {
|
|
||||||
|
|
||||||
Context() : m_config( CATCH_NULL ), m_runner( CATCH_NULL ), m_resultCapture( CATCH_NULL ) {}
|
|
||||||
Context( Context const& );
|
|
||||||
void operator=( Context const& );
|
|
||||||
|
|
||||||
public:
|
|
||||||
virtual ~Context() {
|
|
||||||
deleteAllValues( m_generatorsByTestName );
|
|
||||||
}
|
|
||||||
|
|
||||||
public: // IContext
|
|
||||||
virtual IResultCapture* getResultCapture() {
|
|
||||||
return m_resultCapture;
|
|
||||||
}
|
|
||||||
virtual IRunner* getRunner() {
|
|
||||||
return m_runner;
|
|
||||||
}
|
|
||||||
virtual size_t getGeneratorIndex( std::string const& fileInfo, size_t totalSize ) {
|
|
||||||
return getGeneratorsForCurrentTest()
|
|
||||||
.getGeneratorInfo( fileInfo, totalSize )
|
|
||||||
.getCurrentIndex();
|
|
||||||
}
|
|
||||||
virtual bool advanceGeneratorsForCurrentTest() {
|
|
||||||
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
|
||||||
return generators && generators->moveNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual Ptr<IConfig const> getConfig() const {
|
|
||||||
return m_config;
|
|
||||||
}
|
|
||||||
|
|
||||||
public: // IMutableContext
|
|
||||||
virtual void setResultCapture( IResultCapture* resultCapture ) {
|
|
||||||
m_resultCapture = resultCapture;
|
|
||||||
}
|
|
||||||
virtual void setRunner( IRunner* runner ) {
|
|
||||||
m_runner = runner;
|
|
||||||
}
|
|
||||||
virtual void setConfig( Ptr<IConfig const> const& config ) {
|
|
||||||
m_config = config;
|
|
||||||
}
|
|
||||||
|
|
||||||
friend IMutableContext& getCurrentMutableContext();
|
|
||||||
|
|
||||||
private:
|
|
||||||
IGeneratorsForTest* findGeneratorsForCurrentTest() {
|
|
||||||
std::string testName = getResultCapture()->getCurrentTestName();
|
|
||||||
|
|
||||||
std::map<std::string, IGeneratorsForTest*>::const_iterator it =
|
|
||||||
m_generatorsByTestName.find( testName );
|
|
||||||
return it != m_generatorsByTestName.end()
|
|
||||||
? it->second
|
|
||||||
: CATCH_NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
IGeneratorsForTest& getGeneratorsForCurrentTest() {
|
|
||||||
IGeneratorsForTest* generators = findGeneratorsForCurrentTest();
|
|
||||||
if( !generators ) {
|
|
||||||
std::string testName = getResultCapture()->getCurrentTestName();
|
|
||||||
generators = createGeneratorsForTest();
|
|
||||||
m_generatorsByTestName.insert( std::make_pair( testName, generators ) );
|
|
||||||
}
|
|
||||||
return *generators;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ptr<IConfig const> m_config;
|
|
||||||
IRunner* m_runner;
|
|
||||||
IResultCapture* m_resultCapture;
|
|
||||||
std::map<std::string, IGeneratorsForTest*> m_generatorsByTestName;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace {
|
|
||||||
Context* currentContext = CATCH_NULL;
|
|
||||||
}
|
|
||||||
IMutableContext& getCurrentMutableContext() {
|
|
||||||
if( !currentContext )
|
|
||||||
currentContext = new Context();
|
|
||||||
return *currentContext;
|
|
||||||
}
|
|
||||||
IContext& getCurrentContext() {
|
|
||||||
return getCurrentMutableContext();
|
|
||||||
}
|
|
||||||
|
|
||||||
void cleanUpContext() {
|
|
||||||
delete currentContext;
|
|
||||||
currentContext = CATCH_NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_CONTEXT_IMPL_HPP_INCLUDED
|
|
29
include/internal/catch_debug_console.cpp
Normal file
29
include/internal/catch_debug_console.cpp
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 29/08/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_debug_console.h"
|
||||||
|
#include "catch_stream.h"
|
||||||
|
#include "catch_platform.h"
|
||||||
|
|
||||||
|
#ifdef CATCH_PLATFORM_WINDOWS
|
||||||
|
|
||||||
|
#include "catch_windows_h_proxy.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
void writeToDebugConsole( std::string const& text ) {
|
||||||
|
::OutputDebugStringA( text.c_str() );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
namespace Catch {
|
||||||
|
void writeToDebugConsole( std::string const& text ) {
|
||||||
|
// !TBD: Need a version for Mac/ XCode and other IDEs
|
||||||
|
Catch::cout() << text;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif // Platform
|
17
include/internal/catch_debug_console.h
Normal file
17
include/internal/catch_debug_console.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 29/08/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_DEBUG_CONSOLE_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_DEBUG_CONSOLE_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
void writeToDebugConsole( std::string const& text );
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_DEBUG_CONSOLE_H_INCLUDED
|
@ -6,11 +6,11 @@
|
|||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_debugger.h"
|
#include "catch_debugger.h"
|
||||||
#include "catch_errno_guard.hpp"
|
#include "catch_errno_guard.h"
|
||||||
|
#include "catch_stream.h"
|
||||||
|
#include "catch_platform.h"
|
||||||
|
|
||||||
#ifdef CATCH_PLATFORM_MAC
|
#ifdef CATCH_PLATFORM_MAC
|
||||||
|
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/sysctl.h>
|
#include <sys/sysctl.h>
|
||||||
|
|
||||||
namespace Catch{
|
namespace Catch {
|
||||||
|
|
||||||
// The following function is taken directly from the following technical note:
|
// The following function is taken directly from the following technical note:
|
||||||
// http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
|
// http://developer.apple.com/library/mac/#qa/qa2004/qa1361.html
|
||||||
@ -31,7 +31,7 @@
|
|||||||
|
|
||||||
int mib[4];
|
int mib[4];
|
||||||
struct kinfo_proc info;
|
struct kinfo_proc info;
|
||||||
size_t size;
|
std::size_t size;
|
||||||
|
|
||||||
// Initialize the flags so that, if sysctl fails for some bizarre
|
// Initialize the flags so that, if sysctl fails for some bizarre
|
||||||
// reason, we get a predictable result.
|
// reason, we get a predictable result.
|
||||||
@ -49,7 +49,7 @@
|
|||||||
// Call sysctl.
|
// Call sysctl.
|
||||||
|
|
||||||
size = sizeof(info);
|
size = sizeof(info);
|
||||||
if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, CATCH_NULL, 0) != 0 ) {
|
if( sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) != 0 ) {
|
||||||
Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
|
Catch::cerr() << "\n** Call to sysctl failed - unable to determine if debugger is active **\n" << std::endl;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -106,26 +106,6 @@
|
|||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
inline bool isDebuggerActive() { return false; }
|
bool isDebuggerActive() { return false; }
|
||||||
}
|
}
|
||||||
#endif // Platform
|
#endif // Platform
|
||||||
|
|
||||||
#ifdef CATCH_PLATFORM_WINDOWS
|
|
||||||
|
|
||||||
#include "catch_windows_h_proxy.h"
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
void writeToDebugConsole( std::string const& text ) {
|
|
||||||
::OutputDebugStringA( text.c_str() );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
namespace Catch {
|
|
||||||
void writeToDebugConsole( std::string const& text ) {
|
|
||||||
// !TBD: Need a version for Mac/ XCode and other IDEs
|
|
||||||
Catch::cout() << text;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif // Platform
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_DEBUGGER_HPP_INCLUDED
|
|
@ -11,25 +11,13 @@
|
|||||||
|
|
||||||
#include "catch_platform.h"
|
#include "catch_platform.h"
|
||||||
|
|
||||||
#include <string>
|
namespace Catch {
|
||||||
|
|
||||||
namespace Catch{
|
|
||||||
|
|
||||||
bool isDebuggerActive();
|
bool isDebuggerActive();
|
||||||
void writeToDebugConsole( std::string const& text );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CATCH_PLATFORM_MAC
|
#ifdef CATCH_PLATFORM_MAC
|
||||||
|
|
||||||
// The following code snippet based on:
|
#define CATCH_TRAP() __asm__("int $3\n" : : ) /* NOLINT */
|
||||||
// http://cocoawithlove.com/2008/03/break-into-debugger.html
|
|
||||||
#if defined(__ppc64__) || defined(__ppc__)
|
|
||||||
#define CATCH_TRAP() \
|
|
||||||
__asm__("li r0, 20\nsc\nnop\nli r0, 37\nli r4, 2\nsc\nnop\n" \
|
|
||||||
: : : "memory","r0","r3","r4" ) /* NOLINT */
|
|
||||||
#else
|
|
||||||
#define CATCH_TRAP() __asm__("int $3\n" : : /* NOLINT */ )
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#elif defined(CATCH_PLATFORM_LINUX)
|
#elif defined(CATCH_PLATFORM_LINUX)
|
||||||
// If we can use inline assembler, do it because this allows us to break
|
// If we can use inline assembler, do it because this allows us to break
|
||||||
|
24
include/internal/catch_decomposer.cpp
Normal file
24
include/internal/catch_decomposer.cpp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil Nash on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_decomposer.h"
|
||||||
|
#include "catch_config.hpp"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
ITransientExpression::~ITransientExpression() = default;
|
||||||
|
|
||||||
|
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs ) {
|
||||||
|
if( lhs.size() + rhs.size() < 40 &&
|
||||||
|
lhs.find('\n') == std::string::npos &&
|
||||||
|
rhs.find('\n') == std::string::npos )
|
||||||
|
os << lhs << " " << op << " " << rhs;
|
||||||
|
else
|
||||||
|
os << lhs << "\n" << op << "\n" << rhs;
|
||||||
|
}
|
||||||
|
}
|
169
include/internal/catch_decomposer.h
Normal file
169
include/internal/catch_decomposer.h
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil Nash on 8/8/2017.
|
||||||
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_DECOMPOSER_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_DECOMPOSER_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_tostring.h"
|
||||||
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(push)
|
||||||
|
#pragma warning(disable:4389) // '==' : signed/unsigned mismatch
|
||||||
|
#pragma warning(disable:4018) // more "signed/unsigned mismatch"
|
||||||
|
#pragma warning(disable:4312) // Converting int to T* using reinterpret_cast (issue on x64 platform)
|
||||||
|
#pragma warning(disable:4180) // qualifier applied to function type has no meaning
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct ITransientExpression {
|
||||||
|
virtual auto isBinaryExpression() const -> bool = 0;
|
||||||
|
virtual auto getResult() const -> bool = 0;
|
||||||
|
virtual void streamReconstructedExpression( std::ostream &os ) const = 0;
|
||||||
|
|
||||||
|
// We don't actually need a virtual destructore, but many static analysers
|
||||||
|
// complain if it's not here :-(
|
||||||
|
virtual ~ITransientExpression();
|
||||||
|
};
|
||||||
|
|
||||||
|
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );
|
||||||
|
|
||||||
|
template<typename LhsT, typename RhsT>
|
||||||
|
class BinaryExpr : public ITransientExpression {
|
||||||
|
bool m_result;
|
||||||
|
LhsT m_lhs;
|
||||||
|
StringRef m_op;
|
||||||
|
RhsT m_rhs;
|
||||||
|
|
||||||
|
auto isBinaryExpression() const -> bool override { return true; }
|
||||||
|
auto getResult() const -> bool override { return m_result; }
|
||||||
|
|
||||||
|
void streamReconstructedExpression( std::ostream &os ) const override {
|
||||||
|
formatReconstructedExpression
|
||||||
|
( os, Catch::Detail::stringify( m_lhs ), m_op, Catch::Detail::stringify( m_rhs ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
BinaryExpr( bool comparisonResult, LhsT lhs, StringRef op, RhsT rhs )
|
||||||
|
: m_result( comparisonResult ),
|
||||||
|
m_lhs( lhs ),
|
||||||
|
m_op( op ),
|
||||||
|
m_rhs( rhs )
|
||||||
|
{}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename LhsT>
|
||||||
|
class UnaryExpr : public ITransientExpression {
|
||||||
|
LhsT m_lhs;
|
||||||
|
|
||||||
|
auto isBinaryExpression() const -> bool override { return false; }
|
||||||
|
auto getResult() const -> bool override { return m_lhs ? true : false; }
|
||||||
|
|
||||||
|
void streamReconstructedExpression( std::ostream &os ) const override {
|
||||||
|
os << Catch::Detail::stringify( m_lhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
UnaryExpr( LhsT lhs ) : m_lhs( lhs ) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Specialised comparison functions to handle equality comparisons between ints and pointers (NULL deduces as an int)
|
||||||
|
template<typename LhsT, typename RhsT>
|
||||||
|
auto compareEqual( LhsT const& lhs, RhsT const& rhs ) -> bool { return lhs == rhs; };
|
||||||
|
template<typename T>
|
||||||
|
auto compareEqual( T* const& lhs, int rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
|
||||||
|
template<typename T>
|
||||||
|
auto compareEqual( T* const& lhs, long rhs ) -> bool { return lhs == reinterpret_cast<void const*>( rhs ); }
|
||||||
|
template<typename T>
|
||||||
|
auto compareEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
|
||||||
|
template<typename T>
|
||||||
|
auto compareEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) == rhs; }
|
||||||
|
|
||||||
|
template<typename LhsT, typename RhsT>
|
||||||
|
auto compareNotEqual( LhsT const& lhs, RhsT&& rhs ) -> bool { return lhs != rhs; };
|
||||||
|
template<typename T>
|
||||||
|
auto compareNotEqual( T* const& lhs, int rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
|
||||||
|
template<typename T>
|
||||||
|
auto compareNotEqual( T* const& lhs, long rhs ) -> bool { return lhs != reinterpret_cast<void const*>( rhs ); }
|
||||||
|
template<typename T>
|
||||||
|
auto compareNotEqual( int lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
|
||||||
|
template<typename T>
|
||||||
|
auto compareNotEqual( long lhs, T* const& rhs ) -> bool { return reinterpret_cast<void const*>( lhs ) != rhs; }
|
||||||
|
|
||||||
|
|
||||||
|
template<typename LhsT>
|
||||||
|
class ExprLhs {
|
||||||
|
LhsT m_lhs;
|
||||||
|
public:
|
||||||
|
ExprLhs( LhsT lhs ) : m_lhs( lhs ) {}
|
||||||
|
|
||||||
|
template<typename RhsT>
|
||||||
|
auto operator == ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
|
||||||
|
return BinaryExpr<LhsT, RhsT const&>( compareEqual( m_lhs, rhs ), m_lhs, "==", rhs );
|
||||||
|
}
|
||||||
|
auto operator == ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
|
||||||
|
return BinaryExpr<LhsT, bool>( m_lhs == rhs, m_lhs, "==", rhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RhsT>
|
||||||
|
auto operator != ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
|
||||||
|
return BinaryExpr<LhsT, RhsT const&>( compareNotEqual( m_lhs, rhs ), m_lhs, "!=", rhs );
|
||||||
|
}
|
||||||
|
auto operator != ( bool rhs ) -> BinaryExpr<LhsT, bool> const {
|
||||||
|
return BinaryExpr<LhsT, bool>( m_lhs != rhs, m_lhs, "!=", rhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename RhsT>
|
||||||
|
auto operator > ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
|
||||||
|
return BinaryExpr<LhsT, RhsT const&>( m_lhs > rhs, m_lhs, ">", rhs );
|
||||||
|
}
|
||||||
|
template<typename RhsT>
|
||||||
|
auto operator < ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
|
||||||
|
return BinaryExpr<LhsT, RhsT const&>( m_lhs < rhs, m_lhs, "<", rhs );
|
||||||
|
}
|
||||||
|
template<typename RhsT>
|
||||||
|
auto operator >= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
|
||||||
|
return BinaryExpr<LhsT, RhsT const&>( m_lhs >= rhs, m_lhs, ">=", rhs );
|
||||||
|
}
|
||||||
|
template<typename RhsT>
|
||||||
|
auto operator <= ( RhsT const& rhs ) -> BinaryExpr<LhsT, RhsT const&> const {
|
||||||
|
return BinaryExpr<LhsT, RhsT const&>( m_lhs <= rhs, m_lhs, "<=", rhs );
|
||||||
|
}
|
||||||
|
|
||||||
|
auto makeUnaryExpr() const -> UnaryExpr<LhsT> {
|
||||||
|
return UnaryExpr<LhsT>( m_lhs );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void handleExpression( ITransientExpression const& expr );
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
void handleExpression( ExprLhs<T> const& expr ) {
|
||||||
|
handleExpression( expr.makeUnaryExpr() );
|
||||||
|
}
|
||||||
|
|
||||||
|
struct Decomposer {
|
||||||
|
template<typename T>
|
||||||
|
auto operator <= ( T const& lhs ) -> ExprLhs<T const&> {
|
||||||
|
return ExprLhs<T const&>( lhs );
|
||||||
|
}
|
||||||
|
auto operator <=( bool value ) -> ExprLhs<bool> {
|
||||||
|
return ExprLhs<bool>( value );
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#ifdef _MSC_VER
|
||||||
|
#pragma warning(pop)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_DECOMPOSER_H_INCLUDED
|
@ -8,6 +8,8 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_DEFAULT_MAIN_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_session.h"
|
||||||
|
|
||||||
#ifndef __OBJC__
|
#ifndef __OBJC__
|
||||||
|
|
||||||
#if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
|
#if defined(WIN32) && defined(_UNICODE) && !defined(DO_NOT_USE_WMAIN)
|
||||||
@ -18,8 +20,7 @@ extern "C" int wmain (int argc, wchar_t * argv[], wchar_t * []) {
|
|||||||
int main (int argc, char * argv[]) {
|
int main (int argc, char * argv[]) {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int result = Catch::Session().run( argc, argv );
|
return Catch::Session().run( argc, argv );
|
||||||
return ( result < 0xff ? result : 0xff );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else // __OBJC__
|
#else // __OBJC__
|
||||||
@ -31,13 +32,13 @@ int main (int argc, char * const argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
Catch::registerTestMethods();
|
Catch::registerTestMethods();
|
||||||
int result = Catch::Session().run( argc, (char* const*)argv );
|
int result = Catch::Session().run( argc, (char**)argv );
|
||||||
|
|
||||||
#if !CATCH_ARC_ENABLED
|
#if !CATCH_ARC_ENABLED
|
||||||
[pool drain];
|
[pool drain];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return ( result < 0xff ? result : 0xff );
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // __OBJC__
|
#endif // __OBJC__
|
||||||
|
24
include/internal/catch_enforce.h
Normal file
24
include/internal/catch_enforce.h
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 01/08/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_common.h"
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
#define CATCH_PREPARE_EXCEPTION( type, msg ) \
|
||||||
|
type( static_cast<std::ostringstream&&>( std::ostringstream() << msg ).str() )
|
||||||
|
#define CATCH_INTERNAL_ERROR( msg ) \
|
||||||
|
throw CATCH_PREPARE_EXCEPTION( std::logic_error, CATCH_INTERNAL_LINEINFO << ": Internal Catch error: " << msg);
|
||||||
|
#define CATCH_ERROR( msg ) \
|
||||||
|
throw CATCH_PREPARE_EXCEPTION( std::domain_error, msg )
|
||||||
|
#define CATCH_ENFORCE( condition, msg ) \
|
||||||
|
do{ if( !(condition) ) CATCH_ERROR( msg ); } while(false)
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_ENFORCE_H_INCLUDED
|
15
include/internal/catch_errno_guard.cpp
Normal file
15
include/internal/catch_errno_guard.cpp
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 06/03/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_errno_guard.h"
|
||||||
|
|
||||||
|
#include <cerrno>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
ErrnoGuard::ErrnoGuard():m_oldErrno(errno){}
|
||||||
|
ErrnoGuard::~ErrnoGuard() { errno = m_oldErrno; }
|
||||||
|
}
|
@ -4,22 +4,19 @@
|
|||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*/
|
*/
|
||||||
#ifndef TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_ERRNO_GUARD_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_ERRNO_GUARD_H_INCLUDED
|
||||||
|
|
||||||
#include <cerrno>
|
|
||||||
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class ErrnoGuard {
|
class ErrnoGuard {
|
||||||
public:
|
public:
|
||||||
ErrnoGuard():m_oldErrno(errno){}
|
ErrnoGuard();
|
||||||
~ErrnoGuard() { errno = m_oldErrno; }
|
~ErrnoGuard();
|
||||||
private:
|
private:
|
||||||
int m_oldErrno;
|
int m_oldErrno;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_ERRNO_GUARD_HPP_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_ERRNO_GUARD_H_INCLUDED
|
62
include/internal/catch_exception_translator_registry.cpp
Normal file
62
include/internal/catch_exception_translator_registry.cpp
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 20/04/2011.
|
||||||
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_assertionhandler.h"
|
||||||
|
#include "catch_exception_translator_registry.h"
|
||||||
|
|
||||||
|
#ifdef __OBJC__
|
||||||
|
#import "Foundation/Foundation.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
ExceptionTranslatorRegistry::~ExceptionTranslatorRegistry() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExceptionTranslatorRegistry::registerTranslator( const IExceptionTranslator* translator ) {
|
||||||
|
m_translators.push_back( std::unique_ptr<const IExceptionTranslator>( translator ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ExceptionTranslatorRegistry::translateActiveException() const {
|
||||||
|
try {
|
||||||
|
#ifdef __OBJC__
|
||||||
|
// In Objective-C try objective-c exceptions first
|
||||||
|
@try {
|
||||||
|
return tryTranslators();
|
||||||
|
}
|
||||||
|
@catch (NSException *exception) {
|
||||||
|
return Catch::Detail::stringify( [exception description] );
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
return tryTranslators();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
catch( TestFailureException& ) {
|
||||||
|
std::rethrow_exception(std::current_exception());
|
||||||
|
}
|
||||||
|
catch( std::exception& ex ) {
|
||||||
|
return ex.what();
|
||||||
|
}
|
||||||
|
catch( std::string& msg ) {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
catch( const char* msg ) {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
catch(...) {
|
||||||
|
return "Unknown exception";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ExceptionTranslatorRegistry::tryTranslators() const {
|
||||||
|
if( m_translators.empty() )
|
||||||
|
std::rethrow_exception(std::current_exception());
|
||||||
|
else
|
||||||
|
return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
|
||||||
|
}
|
||||||
|
}
|
30
include/internal/catch_exception_translator_registry.h
Normal file
30
include/internal/catch_exception_translator_registry.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 20/04/2011.
|
||||||
|
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_interfaces_exception.h"
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
|
||||||
|
public:
|
||||||
|
~ExceptionTranslatorRegistry();
|
||||||
|
virtual void registerTranslator( const IExceptionTranslator* translator );
|
||||||
|
virtual std::string translateActiveException() const override;
|
||||||
|
std::string tryTranslators() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<std::unique_ptr<IExceptionTranslator const>> m_translators;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
|
@ -1,73 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 20/04/2011.
|
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_interfaces_exception.h"
|
|
||||||
#include "catch_tostring.h"
|
|
||||||
|
|
||||||
#ifdef __OBJC__
|
|
||||||
#import "Foundation/Foundation.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
class ExceptionTranslatorRegistry : public IExceptionTranslatorRegistry {
|
|
||||||
public:
|
|
||||||
~ExceptionTranslatorRegistry() {
|
|
||||||
deleteAll( m_translators );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual void registerTranslator( const IExceptionTranslator* translator ) {
|
|
||||||
m_translators.push_back( translator );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::string translateActiveException() const {
|
|
||||||
try {
|
|
||||||
#ifdef __OBJC__
|
|
||||||
// In Objective-C try objective-c exceptions first
|
|
||||||
@try {
|
|
||||||
return tryTranslators();
|
|
||||||
}
|
|
||||||
@catch (NSException *exception) {
|
|
||||||
return Catch::toString( [exception description] );
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
return tryTranslators();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
catch( TestFailureException& ) {
|
|
||||||
throw;
|
|
||||||
}
|
|
||||||
catch( std::exception& ex ) {
|
|
||||||
return ex.what();
|
|
||||||
}
|
|
||||||
catch( std::string& msg ) {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
catch( const char* msg ) {
|
|
||||||
return msg;
|
|
||||||
}
|
|
||||||
catch(...) {
|
|
||||||
return "Unknown exception";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string tryTranslators() const {
|
|
||||||
if( m_translators.empty() )
|
|
||||||
throw;
|
|
||||||
else
|
|
||||||
return m_translators[0]->translate( m_translators.begin()+1, m_translators.end() );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<const IExceptionTranslator*> m_translators;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_EXCEPTION_TRANSLATOR_REGISTRY_HPP_INCLUDED
|
|
14
include/internal/catch_external_interfaces.h
Normal file
14
include/internal/catch_external_interfaces.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 17/08/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_EXTERNAL_INTERFACES_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_EXTERNAL_INTERFACES_H_INCLUDED
|
||||||
|
|
||||||
|
#include "../reporters/catch_reporter_bases.hpp"
|
||||||
|
#include "catch_console_colour.h"
|
||||||
|
#include "catch_reporter_registrars.hpp"
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_EXTERNAL_INTERFACES_H_INCLUDED
|
176
include/internal/catch_fatal_condition.cpp
Normal file
176
include/internal/catch_fatal_condition.cpp
Normal file
@ -0,0 +1,176 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 21/08/2014
|
||||||
|
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_fatal_condition.h"
|
||||||
|
|
||||||
|
#include "catch_context.h"
|
||||||
|
#include "catch_interfaces_capture.h"
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
// Report the error condition
|
||||||
|
void reportFatal( char const * const message ) {
|
||||||
|
Catch::getCurrentContext().getResultCapture()->handleFatalErrorCondition( message );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
||||||
|
|
||||||
|
# if !defined ( CATCH_CONFIG_WINDOWS_SEH )
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
void FatalConditionHandler::reset() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
# else // CATCH_CONFIG_WINDOWS_SEH is defined
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
struct SignalDefs { DWORD id; const char* name; };
|
||||||
|
|
||||||
|
// There is no 1-1 mapping between signals and windows exceptions.
|
||||||
|
// Windows can easily distinguish between SO and SigSegV,
|
||||||
|
// but SigInt, SigTerm, etc are handled differently.
|
||||||
|
static SignalDefs signalDefs[] = {
|
||||||
|
{ EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" },
|
||||||
|
{ EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" },
|
||||||
|
{ EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" },
|
||||||
|
{ EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" },
|
||||||
|
};
|
||||||
|
|
||||||
|
LONG CALLBACK FatalConditionHandler::handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
|
||||||
|
for (auto const& def : signalDefs) {
|
||||||
|
if (ExceptionInfo->ExceptionRecord->ExceptionCode == def.id) {
|
||||||
|
reportFatal(def.name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If its not an exception we care about, pass it along.
|
||||||
|
// This stops us from eating debugger breaks etc.
|
||||||
|
return EXCEPTION_CONTINUE_SEARCH;
|
||||||
|
}
|
||||||
|
|
||||||
|
FatalConditionHandler::FatalConditionHandler() {
|
||||||
|
isSet = true;
|
||||||
|
// 32k seems enough for Catch to handle stack overflow,
|
||||||
|
// but the value was found experimentally, so there is no strong guarantee
|
||||||
|
guaranteeSize = 32 * 1024;
|
||||||
|
exceptionHandlerHandle = nullptr;
|
||||||
|
// Register as first handler in current chain
|
||||||
|
exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
|
||||||
|
// Pass in guarantee size to be filled
|
||||||
|
SetThreadStackGuarantee(&guaranteeSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FatalConditionHandler::reset() {
|
||||||
|
if (isSet) {
|
||||||
|
// Unregister handler and restore the old guarantee
|
||||||
|
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
||||||
|
SetThreadStackGuarantee(&guaranteeSize);
|
||||||
|
exceptionHandlerHandle = nullptr;
|
||||||
|
isSet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FatalConditionHandler::~FatalConditionHandler() {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FatalConditionHandler::isSet = false;
|
||||||
|
ULONG FatalConditionHandler::guaranteeSize = 0;
|
||||||
|
PVOID FatalConditionHandler::exceptionHandlerHandle = nullptr;
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
# endif // CATCH_CONFIG_WINDOWS_SEH
|
||||||
|
|
||||||
|
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
||||||
|
|
||||||
|
# if !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
void FatalConditionHandler::reset() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# else // CATCH_CONFIG_POSIX_SIGNALS is defined
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct SignalDefs {
|
||||||
|
int id;
|
||||||
|
const char* name;
|
||||||
|
};
|
||||||
|
static SignalDefs signalDefs[] = {
|
||||||
|
{ SIGINT, "SIGINT - Terminal interrupt signal" },
|
||||||
|
{ SIGILL, "SIGILL - Illegal instruction signal" },
|
||||||
|
{ SIGFPE, "SIGFPE - Floating point error signal" },
|
||||||
|
{ SIGSEGV, "SIGSEGV - Segmentation violation signal" },
|
||||||
|
{ SIGTERM, "SIGTERM - Termination request signal" },
|
||||||
|
{ SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
void FatalConditionHandler::handleSignal( int sig ) {
|
||||||
|
char const * name = "<unknown signal>";
|
||||||
|
for (auto const& def : signalDefs) {
|
||||||
|
if (sig == def.id) {
|
||||||
|
name = def.name;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
reset();
|
||||||
|
reportFatal(name);
|
||||||
|
raise( sig );
|
||||||
|
}
|
||||||
|
|
||||||
|
FatalConditionHandler::FatalConditionHandler() {
|
||||||
|
isSet = true;
|
||||||
|
stack_t sigStack;
|
||||||
|
sigStack.ss_sp = altStackMem;
|
||||||
|
sigStack.ss_size = SIGSTKSZ;
|
||||||
|
sigStack.ss_flags = 0;
|
||||||
|
sigaltstack(&sigStack, &oldSigStack);
|
||||||
|
struct sigaction sa = { };
|
||||||
|
|
||||||
|
sa.sa_handler = handleSignal;
|
||||||
|
sa.sa_flags = SA_ONSTACK;
|
||||||
|
for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
|
||||||
|
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
FatalConditionHandler::~FatalConditionHandler() {
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FatalConditionHandler::reset() {
|
||||||
|
if( isSet ) {
|
||||||
|
// Set signals back to previous values -- hopefully nobody overwrote them in the meantime
|
||||||
|
for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
|
||||||
|
sigaction(signalDefs[i].id, &oldSigActions[i], nullptr);
|
||||||
|
}
|
||||||
|
// Return the old stack
|
||||||
|
sigaltstack(&oldSigStack, nullptr);
|
||||||
|
isSet = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool FatalConditionHandler::isSet = false;
|
||||||
|
struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
|
||||||
|
stack_t FatalConditionHandler::oldSigStack = {};
|
||||||
|
char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
# endif // CATCH_CONFIG_POSIX_SIGNALS
|
||||||
|
|
||||||
|
#endif // not Windows
|
86
include/internal/catch_fatal_condition.h
Normal file
86
include/internal/catch_fatal_condition.h
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 21/08/2014
|
||||||
|
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include "catch_platform.h"
|
||||||
|
#include "catch_compiler_capabilities.h"
|
||||||
|
|
||||||
|
|
||||||
|
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
||||||
|
#include "catch_windows_h_proxy.h"
|
||||||
|
|
||||||
|
# if !defined ( CATCH_CONFIG_WINDOWS_SEH )
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
struct FatalConditionHandler {
|
||||||
|
void reset();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
# else // CATCH_CONFIG_WINDOWS_SEH is defined
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct FatalConditionHandler {
|
||||||
|
|
||||||
|
static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo);
|
||||||
|
FatalConditionHandler();
|
||||||
|
static void reset();
|
||||||
|
~FatalConditionHandler();
|
||||||
|
|
||||||
|
private:
|
||||||
|
static bool isSet;
|
||||||
|
static ULONG guaranteeSize;
|
||||||
|
static PVOID exceptionHandlerHandle;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
# endif // CATCH_CONFIG_WINDOWS_SEH
|
||||||
|
|
||||||
|
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
||||||
|
|
||||||
|
# if !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
struct FatalConditionHandler {
|
||||||
|
void reset();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
# else // CATCH_CONFIG_POSIX_SIGNALS is defined
|
||||||
|
|
||||||
|
#include <signal.h>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct FatalConditionHandler {
|
||||||
|
|
||||||
|
static bool isSet;
|
||||||
|
static struct sigaction oldSigActions[];// [sizeof(signalDefs) / sizeof(SignalDefs)];
|
||||||
|
static stack_t oldSigStack;
|
||||||
|
static char altStackMem[];
|
||||||
|
|
||||||
|
static void handleSignal( int sig );
|
||||||
|
|
||||||
|
FatalConditionHandler();
|
||||||
|
~FatalConditionHandler();
|
||||||
|
static void reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Catch
|
||||||
|
|
||||||
|
# endif // CATCH_CONFIG_POSIX_SIGNALS
|
||||||
|
|
||||||
|
#endif // not Windows
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
@ -1,200 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 21/08/2014
|
|
||||||
* Copyright 2014 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
|
||||||
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
// Report the error condition
|
|
||||||
inline void reportFatal( std::string const& message ) {
|
|
||||||
IContext& context = Catch::getCurrentContext();
|
|
||||||
IResultCapture* resultCapture = context.getResultCapture();
|
|
||||||
resultCapture->handleFatalErrorCondition( message );
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Catch
|
|
||||||
|
|
||||||
#if defined ( CATCH_PLATFORM_WINDOWS ) /////////////////////////////////////////
|
|
||||||
#include "catch_windows_h_proxy.h"
|
|
||||||
|
|
||||||
# if !defined ( CATCH_CONFIG_WINDOWS_SEH )
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
struct FatalConditionHandler {
|
|
||||||
void reset() {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
# else // CATCH_CONFIG_WINDOWS_SEH is defined
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
struct SignalDefs { DWORD id; const char* name; };
|
|
||||||
extern SignalDefs signalDefs[];
|
|
||||||
// There is no 1-1 mapping between signals and windows exceptions.
|
|
||||||
// Windows can easily distinguish between SO and SigSegV,
|
|
||||||
// but SigInt, SigTerm, etc are handled differently.
|
|
||||||
SignalDefs signalDefs[] = {
|
|
||||||
{ EXCEPTION_ILLEGAL_INSTRUCTION, "SIGILL - Illegal instruction signal" },
|
|
||||||
{ EXCEPTION_STACK_OVERFLOW, "SIGSEGV - Stack overflow" },
|
|
||||||
{ EXCEPTION_ACCESS_VIOLATION, "SIGSEGV - Segmentation violation signal" },
|
|
||||||
{ EXCEPTION_INT_DIVIDE_BY_ZERO, "Divide by zero error" },
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FatalConditionHandler {
|
|
||||||
|
|
||||||
static LONG CALLBACK handleVectoredException(PEXCEPTION_POINTERS ExceptionInfo) {
|
|
||||||
for (int i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
|
|
||||||
if (ExceptionInfo->ExceptionRecord->ExceptionCode == signalDefs[i].id) {
|
|
||||||
reportFatal(signalDefs[i].name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// If its not an exception we care about, pass it along.
|
|
||||||
// This stops us from eating debugger breaks etc.
|
|
||||||
return EXCEPTION_CONTINUE_SEARCH;
|
|
||||||
}
|
|
||||||
|
|
||||||
FatalConditionHandler() {
|
|
||||||
isSet = true;
|
|
||||||
// 32k seems enough for Catch to handle stack overflow,
|
|
||||||
// but the value was found experimentally, so there is no strong guarantee
|
|
||||||
guaranteeSize = 32 * 1024;
|
|
||||||
exceptionHandlerHandle = CATCH_NULL;
|
|
||||||
// Register as first handler in current chain
|
|
||||||
exceptionHandlerHandle = AddVectoredExceptionHandler(1, handleVectoredException);
|
|
||||||
// Pass in guarantee size to be filled
|
|
||||||
SetThreadStackGuarantee(&guaranteeSize);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void reset() {
|
|
||||||
if (isSet) {
|
|
||||||
// Unregister handler and restore the old guarantee
|
|
||||||
RemoveVectoredExceptionHandler(exceptionHandlerHandle);
|
|
||||||
SetThreadStackGuarantee(&guaranteeSize);
|
|
||||||
exceptionHandlerHandle = CATCH_NULL;
|
|
||||||
isSet = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~FatalConditionHandler() {
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
static bool isSet;
|
|
||||||
static ULONG guaranteeSize;
|
|
||||||
static PVOID exceptionHandlerHandle;
|
|
||||||
};
|
|
||||||
|
|
||||||
bool FatalConditionHandler::isSet = false;
|
|
||||||
ULONG FatalConditionHandler::guaranteeSize = 0;
|
|
||||||
PVOID FatalConditionHandler::exceptionHandlerHandle = CATCH_NULL;
|
|
||||||
|
|
||||||
} // namespace Catch
|
|
||||||
|
|
||||||
# endif // CATCH_CONFIG_WINDOWS_SEH
|
|
||||||
|
|
||||||
#else // Not Windows - assumed to be POSIX compatible //////////////////////////
|
|
||||||
|
|
||||||
# if !defined(CATCH_CONFIG_POSIX_SIGNALS)
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
struct FatalConditionHandler {
|
|
||||||
void reset() {}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
# else // CATCH_CONFIG_POSIX_SIGNALS is defined
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
struct SignalDefs {
|
|
||||||
int id;
|
|
||||||
const char* name;
|
|
||||||
};
|
|
||||||
extern SignalDefs signalDefs[];
|
|
||||||
SignalDefs signalDefs[] = {
|
|
||||||
{ SIGINT, "SIGINT - Terminal interrupt signal" },
|
|
||||||
{ SIGILL, "SIGILL - Illegal instruction signal" },
|
|
||||||
{ SIGFPE, "SIGFPE - Floating point error signal" },
|
|
||||||
{ SIGSEGV, "SIGSEGV - Segmentation violation signal" },
|
|
||||||
{ SIGTERM, "SIGTERM - Termination request signal" },
|
|
||||||
{ SIGABRT, "SIGABRT - Abort (abnormal termination) signal" }
|
|
||||||
};
|
|
||||||
|
|
||||||
struct FatalConditionHandler {
|
|
||||||
|
|
||||||
static bool isSet;
|
|
||||||
static struct sigaction oldSigActions [sizeof(signalDefs)/sizeof(SignalDefs)];
|
|
||||||
static stack_t oldSigStack;
|
|
||||||
static char altStackMem[SIGSTKSZ];
|
|
||||||
|
|
||||||
static void handleSignal( int sig ) {
|
|
||||||
std::string name = "<unknown signal>";
|
|
||||||
for (std::size_t i = 0; i < sizeof(signalDefs) / sizeof(SignalDefs); ++i) {
|
|
||||||
SignalDefs &def = signalDefs[i];
|
|
||||||
if (sig == def.id) {
|
|
||||||
name = def.name;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
reset();
|
|
||||||
reportFatal(name);
|
|
||||||
raise( sig );
|
|
||||||
}
|
|
||||||
|
|
||||||
FatalConditionHandler() {
|
|
||||||
isSet = true;
|
|
||||||
stack_t sigStack;
|
|
||||||
sigStack.ss_sp = altStackMem;
|
|
||||||
sigStack.ss_size = SIGSTKSZ;
|
|
||||||
sigStack.ss_flags = 0;
|
|
||||||
sigaltstack(&sigStack, &oldSigStack);
|
|
||||||
struct sigaction sa = { 0 };
|
|
||||||
|
|
||||||
sa.sa_handler = handleSignal;
|
|
||||||
sa.sa_flags = SA_ONSTACK;
|
|
||||||
for (std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i) {
|
|
||||||
sigaction(signalDefs[i].id, &sa, &oldSigActions[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
~FatalConditionHandler() {
|
|
||||||
reset();
|
|
||||||
}
|
|
||||||
static void reset() {
|
|
||||||
if( isSet ) {
|
|
||||||
// Set signals back to previous values -- hopefully nobody overwrote them in the meantime
|
|
||||||
for( std::size_t i = 0; i < sizeof(signalDefs)/sizeof(SignalDefs); ++i ) {
|
|
||||||
sigaction(signalDefs[i].id, &oldSigActions[i], CATCH_NULL);
|
|
||||||
}
|
|
||||||
// Return the old stack
|
|
||||||
sigaltstack(&oldSigStack, CATCH_NULL);
|
|
||||||
isSet = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
bool FatalConditionHandler::isSet = false;
|
|
||||||
struct sigaction FatalConditionHandler::oldSigActions[sizeof(signalDefs)/sizeof(SignalDefs)] = {};
|
|
||||||
stack_t FatalConditionHandler::oldSigStack = {};
|
|
||||||
char FatalConditionHandler::altStackMem[SIGSTKSZ] = {};
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace Catch
|
|
||||||
|
|
||||||
# endif // CATCH_CONFIG_POSIX_SIGNALS
|
|
||||||
|
|
||||||
#endif // not Windows
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_FATAL_CONDITION_H_INCLUDED
|
|
@ -1,189 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 27/01/2011.
|
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_context.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <stdlib.h>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
struct IGenerator {
|
|
||||||
virtual ~IGenerator() {}
|
|
||||||
virtual T getValue( std::size_t index ) const = 0;
|
|
||||||
virtual std::size_t size () const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class BetweenGenerator : public IGenerator<T> {
|
|
||||||
public:
|
|
||||||
BetweenGenerator( T from, T to ) : m_from( from ), m_to( to ){}
|
|
||||||
|
|
||||||
virtual T getValue( std::size_t index ) const {
|
|
||||||
return m_from+static_cast<int>( index );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::size_t size() const {
|
|
||||||
return static_cast<std::size_t>( 1+m_to-m_from );
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
T m_from;
|
|
||||||
T m_to;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class ValuesGenerator : public IGenerator<T> {
|
|
||||||
public:
|
|
||||||
ValuesGenerator(){}
|
|
||||||
|
|
||||||
void add( T value ) {
|
|
||||||
m_values.push_back( value );
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual T getValue( std::size_t index ) const {
|
|
||||||
return m_values[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual std::size_t size() const {
|
|
||||||
return m_values.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::vector<T> m_values;
|
|
||||||
};
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
class CompositeGenerator {
|
|
||||||
public:
|
|
||||||
CompositeGenerator() : m_totalSize( 0 ) {}
|
|
||||||
|
|
||||||
// *** Move semantics, similar to auto_ptr ***
|
|
||||||
CompositeGenerator( CompositeGenerator& other )
|
|
||||||
: m_fileInfo( other.m_fileInfo ),
|
|
||||||
m_totalSize( 0 )
|
|
||||||
{
|
|
||||||
move( other );
|
|
||||||
}
|
|
||||||
|
|
||||||
CompositeGenerator& setFileInfo( const char* fileInfo ) {
|
|
||||||
m_fileInfo = fileInfo;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
~CompositeGenerator() {
|
|
||||||
deleteAll( m_composed );
|
|
||||||
}
|
|
||||||
|
|
||||||
operator T () const {
|
|
||||||
size_t overallIndex = getCurrentContext().getGeneratorIndex( m_fileInfo, m_totalSize );
|
|
||||||
|
|
||||||
typename std::vector<const IGenerator<T>*>::const_iterator it = m_composed.begin();
|
|
||||||
typename std::vector<const IGenerator<T>*>::const_iterator itEnd = m_composed.end();
|
|
||||||
for( size_t index = 0; it != itEnd; ++it )
|
|
||||||
{
|
|
||||||
const IGenerator<T>* generator = *it;
|
|
||||||
if( overallIndex >= index && overallIndex < index + generator->size() )
|
|
||||||
{
|
|
||||||
return generator->getValue( overallIndex-index );
|
|
||||||
}
|
|
||||||
index += generator->size();
|
|
||||||
}
|
|
||||||
CATCH_INTERNAL_ERROR( "Indexed past end of generated range" );
|
|
||||||
return T(); // Suppress spurious "not all control paths return a value" warning in Visual Studio - if you know how to fix this please do so
|
|
||||||
}
|
|
||||||
|
|
||||||
void add( const IGenerator<T>* generator ) {
|
|
||||||
m_totalSize += generator->size();
|
|
||||||
m_composed.push_back( generator );
|
|
||||||
}
|
|
||||||
|
|
||||||
CompositeGenerator& then( CompositeGenerator& other ) {
|
|
||||||
move( other );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
CompositeGenerator& then( T value ) {
|
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
|
||||||
valuesGen->add( value );
|
|
||||||
add( valuesGen );
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void move( CompositeGenerator& other ) {
|
|
||||||
m_composed.insert( m_composed.end(), other.m_composed.begin(), other.m_composed.end() );
|
|
||||||
m_totalSize += other.m_totalSize;
|
|
||||||
other.m_composed.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<const IGenerator<T>*> m_composed;
|
|
||||||
std::string m_fileInfo;
|
|
||||||
size_t m_totalSize;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Generators
|
|
||||||
{
|
|
||||||
template<typename T>
|
|
||||||
CompositeGenerator<T> between( T from, T to ) {
|
|
||||||
CompositeGenerator<T> generators;
|
|
||||||
generators.add( new BetweenGenerator<T>( from, to ) );
|
|
||||||
return generators;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
CompositeGenerator<T> values( T val1, T val2 ) {
|
|
||||||
CompositeGenerator<T> generators;
|
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
|
||||||
valuesGen->add( val1 );
|
|
||||||
valuesGen->add( val2 );
|
|
||||||
generators.add( valuesGen );
|
|
||||||
return generators;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
CompositeGenerator<T> values( T val1, T val2, T val3 ){
|
|
||||||
CompositeGenerator<T> generators;
|
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
|
||||||
valuesGen->add( val1 );
|
|
||||||
valuesGen->add( val2 );
|
|
||||||
valuesGen->add( val3 );
|
|
||||||
generators.add( valuesGen );
|
|
||||||
return generators;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename T>
|
|
||||||
CompositeGenerator<T> values( T val1, T val2, T val3, T val4 ) {
|
|
||||||
CompositeGenerator<T> generators;
|
|
||||||
ValuesGenerator<T>* valuesGen = new ValuesGenerator<T>();
|
|
||||||
valuesGen->add( val1 );
|
|
||||||
valuesGen->add( val2 );
|
|
||||||
valuesGen->add( val3 );
|
|
||||||
valuesGen->add( val4 );
|
|
||||||
generators.add( valuesGen );
|
|
||||||
return generators;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace Generators
|
|
||||||
|
|
||||||
using namespace Generators;
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#define INTERNAL_CATCH_LINESTR2( line ) #line
|
|
||||||
#define INTERNAL_CATCH_LINESTR( line ) INTERNAL_CATCH_LINESTR2( line )
|
|
||||||
|
|
||||||
#define INTERNAL_CATCH_GENERATE( expr ) expr.setFileInfo( __FILE__ "(" INTERNAL_CATCH_LINESTR( __LINE__ ) ")" )
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_GENERATORS_HPP_INCLUDED
|
|
@ -1,86 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 28/01/2011.
|
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_interfaces_generators.h"
|
|
||||||
|
|
||||||
#include "catch_common.h"
|
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include <string>
|
|
||||||
#include <map>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
struct GeneratorInfo : IGeneratorInfo {
|
|
||||||
|
|
||||||
GeneratorInfo( std::size_t size )
|
|
||||||
: m_size( size ),
|
|
||||||
m_currentIndex( 0 )
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool moveNext() {
|
|
||||||
if( ++m_currentIndex == m_size ) {
|
|
||||||
m_currentIndex = 0;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t getCurrentIndex() const {
|
|
||||||
return m_currentIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t m_size;
|
|
||||||
std::size_t m_currentIndex;
|
|
||||||
};
|
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
class GeneratorsForTest : public IGeneratorsForTest {
|
|
||||||
|
|
||||||
public:
|
|
||||||
~GeneratorsForTest() {
|
|
||||||
deleteAll( m_generatorsInOrder );
|
|
||||||
}
|
|
||||||
|
|
||||||
IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) {
|
|
||||||
std::map<std::string, IGeneratorInfo*>::const_iterator it = m_generatorsByName.find( fileInfo );
|
|
||||||
if( it == m_generatorsByName.end() ) {
|
|
||||||
IGeneratorInfo* info = new GeneratorInfo( size );
|
|
||||||
m_generatorsByName.insert( std::make_pair( fileInfo, info ) );
|
|
||||||
m_generatorsInOrder.push_back( info );
|
|
||||||
return *info;
|
|
||||||
}
|
|
||||||
return *it->second;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool moveNext() {
|
|
||||||
std::vector<IGeneratorInfo*>::const_iterator it = m_generatorsInOrder.begin();
|
|
||||||
std::vector<IGeneratorInfo*>::const_iterator itEnd = m_generatorsInOrder.end();
|
|
||||||
for(; it != itEnd; ++it ) {
|
|
||||||
if( (*it)->moveNext() )
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::map<std::string, IGeneratorInfo*> m_generatorsByName;
|
|
||||||
std::vector<IGeneratorInfo*> m_generatorsInOrder;
|
|
||||||
};
|
|
||||||
|
|
||||||
IGeneratorsForTest* createGeneratorsForTest()
|
|
||||||
{
|
|
||||||
return new GeneratorsForTest();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_GENERATORS_IMPL_HPP_INCLUDED
|
|
@ -8,99 +8,22 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
|
#define TWOBLUECUBES_CATCH_IMPL_HPP_INCLUDED
|
||||||
|
|
||||||
// Collect all the implementation files together here
|
|
||||||
// These are the equivalent of what would usually be cpp files
|
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
#pragma clang diagnostic push
|
#pragma clang diagnostic push
|
||||||
#pragma clang diagnostic ignored "-Wweak-vtables"
|
#pragma clang diagnostic ignored "-Wweak-vtables"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../catch_session.hpp"
|
// Keep these here for external reporters
|
||||||
#include "catch_registry_hub.hpp"
|
#include "catch_test_spec.h"
|
||||||
#include "catch_notimplemented_exception.hpp"
|
#include "catch_test_case_tracker.h"
|
||||||
#include "catch_context_impl.hpp"
|
|
||||||
#include "catch_console_colour_impl.hpp"
|
|
||||||
#include "catch_generators_impl.hpp"
|
|
||||||
#include "catch_assertionresult.hpp"
|
|
||||||
#include "catch_test_case_info.hpp"
|
|
||||||
#include "catch_test_spec.hpp"
|
|
||||||
#include "catch_version.hpp"
|
|
||||||
#include "catch_message.hpp"
|
|
||||||
#include "catch_legacy_reporter_adapter.hpp"
|
|
||||||
#include "catch_timer.hpp"
|
|
||||||
#include "catch_common.hpp"
|
|
||||||
#include "catch_section.hpp"
|
|
||||||
#include "catch_debugger.hpp"
|
|
||||||
#include "catch_tostring.hpp"
|
|
||||||
#include "catch_result_builder.hpp"
|
|
||||||
#include "catch_tag_alias_registry.hpp"
|
|
||||||
#include "catch_test_case_tracker.hpp"
|
|
||||||
#include "catch_matchers_string.hpp"
|
|
||||||
|
|
||||||
#include "../reporters/catch_reporter_multi.hpp"
|
#include "catch_leak_detector.h"
|
||||||
#include "../reporters/catch_reporter_xml.hpp"
|
|
||||||
#include "../reporters/catch_reporter_junit.hpp"
|
// Cpp files will be included in the single-header file here
|
||||||
#include "../reporters/catch_reporter_console.hpp"
|
// ~*~* CATCH_CPP_STITCH_PLACE *~*~
|
||||||
#include "../reporters/catch_reporter_compact.hpp"
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
// These are all here to avoid warnings about not having any out of line
|
LeakDetector leakDetector;
|
||||||
// virtual methods
|
|
||||||
NonCopyable::~NonCopyable() {}
|
|
||||||
IShared::~IShared() {}
|
|
||||||
IStream::~IStream() CATCH_NOEXCEPT {}
|
|
||||||
FileStream::~FileStream() CATCH_NOEXCEPT {}
|
|
||||||
CoutStream::~CoutStream() CATCH_NOEXCEPT {}
|
|
||||||
DebugOutStream::~DebugOutStream() CATCH_NOEXCEPT {}
|
|
||||||
StreamBufBase::~StreamBufBase() CATCH_NOEXCEPT {}
|
|
||||||
IContext::~IContext() {}
|
|
||||||
IResultCapture::~IResultCapture() {}
|
|
||||||
ITestCase::~ITestCase() {}
|
|
||||||
ITestCaseRegistry::~ITestCaseRegistry() {}
|
|
||||||
IRegistryHub::~IRegistryHub() {}
|
|
||||||
IMutableRegistryHub::~IMutableRegistryHub() {}
|
|
||||||
IExceptionTranslator::~IExceptionTranslator() {}
|
|
||||||
IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() {}
|
|
||||||
IReporter::~IReporter() {}
|
|
||||||
IReporterFactory::~IReporterFactory() {}
|
|
||||||
IReporterRegistry::~IReporterRegistry() {}
|
|
||||||
IStreamingReporter::~IStreamingReporter() {}
|
|
||||||
AssertionStats::~AssertionStats() {}
|
|
||||||
SectionStats::~SectionStats() {}
|
|
||||||
TestCaseStats::~TestCaseStats() {}
|
|
||||||
TestGroupStats::~TestGroupStats() {}
|
|
||||||
TestRunStats::~TestRunStats() {}
|
|
||||||
CumulativeReporterBase::SectionNode::~SectionNode() {}
|
|
||||||
CumulativeReporterBase::~CumulativeReporterBase() {}
|
|
||||||
|
|
||||||
StreamingReporterBase::~StreamingReporterBase() {}
|
|
||||||
ConsoleReporter::~ConsoleReporter() {}
|
|
||||||
CompactReporter::~CompactReporter() {}
|
|
||||||
IRunner::~IRunner() {}
|
|
||||||
IMutableContext::~IMutableContext() {}
|
|
||||||
IConfig::~IConfig() {}
|
|
||||||
XmlReporter::~XmlReporter() {}
|
|
||||||
JunitReporter::~JunitReporter() {}
|
|
||||||
TestRegistry::~TestRegistry() {}
|
|
||||||
FreeFunctionTestCase::~FreeFunctionTestCase() {}
|
|
||||||
IGeneratorInfo::~IGeneratorInfo() {}
|
|
||||||
IGeneratorsForTest::~IGeneratorsForTest() {}
|
|
||||||
WildcardPattern::~WildcardPattern() {}
|
|
||||||
TestSpec::Pattern::~Pattern() {}
|
|
||||||
TestSpec::NamePattern::~NamePattern() {}
|
|
||||||
TestSpec::TagPattern::~TagPattern() {}
|
|
||||||
TestSpec::ExcludedPattern::~ExcludedPattern() {}
|
|
||||||
Matchers::Impl::MatcherUntypedBase::~MatcherUntypedBase() {}
|
|
||||||
|
|
||||||
void Config::dummy() {}
|
|
||||||
|
|
||||||
namespace TestCaseTracking {
|
|
||||||
ITracker::~ITracker() {}
|
|
||||||
TrackerBase::~TrackerBase() {}
|
|
||||||
SectionTracker::~SectionTracker() {}
|
|
||||||
IndexTracker::~IndexTracker() {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __clang__
|
#ifdef __clang__
|
||||||
|
5
include/internal/catch_interfaces_capture.cpp
Normal file
5
include/internal/catch_interfaces_capture.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "catch_interfaces_capture.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
IResultCapture::~IResultCapture() = default;
|
||||||
|
}
|
@ -9,29 +9,34 @@
|
|||||||
#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_CAPTURE_H_INCLUDED
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "catch_result_type.h"
|
|
||||||
#include "catch_common.h"
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class TestCase;
|
|
||||||
class AssertionResult;
|
class AssertionResult;
|
||||||
struct AssertionInfo;
|
struct AssertionInfo;
|
||||||
struct SectionInfo;
|
struct SectionInfo;
|
||||||
struct SectionEndInfo;
|
struct SectionEndInfo;
|
||||||
struct MessageInfo;
|
struct MessageInfo;
|
||||||
class ScopedMessageBuilder;
|
|
||||||
struct Counts;
|
struct Counts;
|
||||||
|
struct BenchmarkInfo;
|
||||||
|
struct BenchmarkStats;
|
||||||
|
|
||||||
struct IResultCapture {
|
struct IResultCapture {
|
||||||
|
|
||||||
virtual ~IResultCapture();
|
virtual ~IResultCapture();
|
||||||
|
|
||||||
|
virtual void assertionStarting( AssertionInfo const& info ) = 0;
|
||||||
virtual void assertionEnded( AssertionResult const& result ) = 0;
|
virtual void assertionEnded( AssertionResult const& result ) = 0;
|
||||||
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
virtual bool sectionStarted( SectionInfo const& sectionInfo,
|
||||||
Counts& assertions ) = 0;
|
Counts& assertions ) = 0;
|
||||||
virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
|
virtual void sectionEnded( SectionEndInfo const& endInfo ) = 0;
|
||||||
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
|
virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) = 0;
|
||||||
|
|
||||||
|
virtual void benchmarkStarting( BenchmarkInfo const& info ) = 0;
|
||||||
|
virtual void benchmarkEnded( BenchmarkStats const& stats ) = 0;
|
||||||
|
|
||||||
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
|
virtual void pushScopedMessage( MessageInfo const& message ) = 0;
|
||||||
virtual void popScopedMessage( MessageInfo const& message ) = 0;
|
virtual void popScopedMessage( MessageInfo const& message ) = 0;
|
||||||
|
|
||||||
@ -40,7 +45,7 @@ namespace Catch {
|
|||||||
|
|
||||||
virtual void exceptionEarlyReported() = 0;
|
virtual void exceptionEarlyReported() = 0;
|
||||||
|
|
||||||
virtual void handleFatalErrorCondition( std::string const& message ) = 0;
|
virtual void handleFatalErrorCondition( StringRef message ) = 0;
|
||||||
|
|
||||||
virtual bool lastAssertionPassed() = 0;
|
virtual bool lastAssertionPassed() = 0;
|
||||||
virtual void assertionPassed() = 0;
|
virtual void assertionPassed() = 0;
|
||||||
|
5
include/internal/catch_interfaces_config.cpp
Normal file
5
include/internal/catch_interfaces_config.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "internal/catch_interfaces_config.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
IConfig::~IConfig() = default;
|
||||||
|
}
|
@ -8,19 +8,20 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_common.h"
|
||||||
|
|
||||||
#include <iosfwd>
|
#include <iosfwd>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
#include "catch_ptr.hpp"
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
struct Verbosity { enum Level {
|
enum class Verbosity {
|
||||||
NoOutput = 0,
|
Quiet = 0,
|
||||||
Quiet,
|
Normal,
|
||||||
Normal
|
High
|
||||||
}; };
|
};
|
||||||
|
|
||||||
struct WarnAbout { enum What {
|
struct WarnAbout { enum What {
|
||||||
Nothing = 0x00,
|
Nothing = 0x00,
|
||||||
@ -51,7 +52,7 @@ namespace Catch {
|
|||||||
|
|
||||||
class TestSpec;
|
class TestSpec;
|
||||||
|
|
||||||
struct IConfig : IShared {
|
struct IConfig : NonCopyable {
|
||||||
|
|
||||||
virtual ~IConfig();
|
virtual ~IConfig();
|
||||||
|
|
||||||
@ -67,10 +68,13 @@ namespace Catch {
|
|||||||
virtual TestSpec const& testSpec() const = 0;
|
virtual TestSpec const& testSpec() const = 0;
|
||||||
virtual RunTests::InWhatOrder runOrder() const = 0;
|
virtual RunTests::InWhatOrder runOrder() const = 0;
|
||||||
virtual unsigned int rngSeed() const = 0;
|
virtual unsigned int rngSeed() const = 0;
|
||||||
|
virtual int benchmarkResolutionMultiple() const = 0;
|
||||||
virtual UseColour::YesOrNo useColour() const = 0;
|
virtual UseColour::YesOrNo useColour() const = 0;
|
||||||
virtual std::vector<std::string> const& getSectionsToRun() const = 0;
|
virtual std::vector<std::string> const& getSectionsToRun() const = 0;
|
||||||
|
virtual Verbosity verbosity() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using IConfigPtr = std::shared_ptr<IConfig const>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_CONFIG_H_INCLUDED
|
||||||
|
6
include/internal/catch_interfaces_exception.cpp
Normal file
6
include/internal/catch_interfaces_exception.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "internal/catch_interfaces_exception.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
IExceptionTranslator::~IExceptionTranslator() = default;
|
||||||
|
IExceptionTranslatorRegistry::~IExceptionTranslatorRegistry() = default;
|
||||||
|
}
|
@ -8,17 +8,22 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_EXCEPTION_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_interfaces_registry_hub.h"
|
||||||
|
|
||||||
|
#if defined(CATCH_CONFIG_DISABLE)
|
||||||
|
#define INTERNAL_CATCH_TRANSLATE_EXCEPTION_NO_REG( translatorName, signature) \
|
||||||
|
static std::string translatorName( signature )
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <exception>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "catch_interfaces_registry_hub.h"
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
using exceptionTranslateFunction = std::string(*)();
|
||||||
typedef std::string(*exceptionTranslateFunction)();
|
|
||||||
|
|
||||||
struct IExceptionTranslator;
|
struct IExceptionTranslator;
|
||||||
typedef std::vector<const IExceptionTranslator*> ExceptionTranslators;
|
using ExceptionTranslators = std::vector<std::unique_ptr<IExceptionTranslator const>>;
|
||||||
|
|
||||||
struct IExceptionTranslator {
|
struct IExceptionTranslator {
|
||||||
virtual ~IExceptionTranslator();
|
virtual ~IExceptionTranslator();
|
||||||
@ -40,10 +45,10 @@ namespace Catch {
|
|||||||
: m_translateFunction( translateFunction )
|
: m_translateFunction( translateFunction )
|
||||||
{}
|
{}
|
||||||
|
|
||||||
virtual std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const CATCH_OVERRIDE {
|
std::string translate( ExceptionTranslators::const_iterator it, ExceptionTranslators::const_iterator itEnd ) const override {
|
||||||
try {
|
try {
|
||||||
if( it == itEnd )
|
if( it == itEnd )
|
||||||
throw;
|
std::rethrow_exception(std::current_exception());
|
||||||
else
|
else
|
||||||
return (*it)->translate( it+1, itEnd );
|
return (*it)->translate( it+1, itEnd );
|
||||||
}
|
}
|
||||||
|
@ -1,32 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 7/8/2012.
|
|
||||||
* Copyright 2011 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
|
|
||||||
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
struct IGeneratorInfo {
|
|
||||||
virtual ~IGeneratorInfo();
|
|
||||||
virtual bool moveNext() = 0;
|
|
||||||
virtual std::size_t getCurrentIndex() const = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct IGeneratorsForTest {
|
|
||||||
virtual ~IGeneratorsForTest();
|
|
||||||
|
|
||||||
virtual IGeneratorInfo& getGeneratorInfo( std::string const& fileInfo, std::size_t size ) = 0;
|
|
||||||
virtual bool moveNext() = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
IGeneratorsForTest* createGeneratorsForTest();
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_GENERATORS_H_INCLUDED
|
|
6
include/internal/catch_interfaces_registry_hub.cpp
Normal file
6
include/internal/catch_interfaces_registry_hub.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "internal/catch_interfaces_registry_hub.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
IRegistryHub::~IRegistryHub() = default;
|
||||||
|
IMutableRegistryHub::~IMutableRegistryHub() = default;
|
||||||
|
}
|
@ -8,9 +8,10 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_REGISTRY_HUB_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_ptr.hpp"
|
#include "catch_common.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
@ -21,6 +22,9 @@ namespace Catch {
|
|||||||
struct IReporterRegistry;
|
struct IReporterRegistry;
|
||||||
struct IReporterFactory;
|
struct IReporterFactory;
|
||||||
struct ITagAliasRegistry;
|
struct ITagAliasRegistry;
|
||||||
|
class StartupExceptionRegistry;
|
||||||
|
|
||||||
|
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
|
||||||
|
|
||||||
struct IRegistryHub {
|
struct IRegistryHub {
|
||||||
virtual ~IRegistryHub();
|
virtual ~IRegistryHub();
|
||||||
@ -30,15 +34,19 @@ namespace Catch {
|
|||||||
virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
|
virtual ITagAliasRegistry const& getTagAliasRegistry() const = 0;
|
||||||
|
|
||||||
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
|
virtual IExceptionTranslatorRegistry& getExceptionTranslatorRegistry() = 0;
|
||||||
|
|
||||||
|
|
||||||
|
virtual StartupExceptionRegistry const& getStartupExceptionRegistry() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct IMutableRegistryHub {
|
struct IMutableRegistryHub {
|
||||||
virtual ~IMutableRegistryHub();
|
virtual ~IMutableRegistryHub();
|
||||||
virtual void registerReporter( std::string const& name, Ptr<IReporterFactory> const& factory ) = 0;
|
virtual void registerReporter( std::string const& name, IReporterFactoryPtr const& factory ) = 0;
|
||||||
virtual void registerListener( Ptr<IReporterFactory> const& factory ) = 0;
|
virtual void registerListener( IReporterFactoryPtr const& factory ) = 0;
|
||||||
virtual void registerTest( TestCase const& testInfo ) = 0;
|
virtual void registerTest( TestCase const& testInfo ) = 0;
|
||||||
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
|
virtual void registerTranslator( const IExceptionTranslator* translator ) = 0;
|
||||||
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
virtual void registerTagAlias( std::string const& alias, std::string const& tag, SourceLineInfo const& lineInfo ) = 0;
|
||||||
|
virtual void registerStartupException() noexcept = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
IRegistryHub& getRegistryHub();
|
IRegistryHub& getRegistryHub();
|
||||||
|
135
include/internal/catch_interfaces_reporter.cpp
Normal file
135
include/internal/catch_interfaces_reporter.cpp
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 19/07/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_interfaces_reporter.h"
|
||||||
|
#include "../reporters/catch_reporter_multi.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig )
|
||||||
|
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
||||||
|
|
||||||
|
ReporterConfig::ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream )
|
||||||
|
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
||||||
|
|
||||||
|
std::ostream& ReporterConfig::stream() const { return *m_stream; }
|
||||||
|
IConfigPtr ReporterConfig::fullConfig() const { return m_fullConfig; }
|
||||||
|
|
||||||
|
|
||||||
|
TestRunInfo::TestRunInfo( std::string const& _name ) : name( _name ) {}
|
||||||
|
|
||||||
|
GroupInfo::GroupInfo( std::string const& _name,
|
||||||
|
std::size_t _groupIndex,
|
||||||
|
std::size_t _groupsCount )
|
||||||
|
: name( _name ),
|
||||||
|
groupIndex( _groupIndex ),
|
||||||
|
groupsCounts( _groupsCount )
|
||||||
|
{}
|
||||||
|
|
||||||
|
AssertionStats::AssertionStats( AssertionResult const& _assertionResult,
|
||||||
|
std::vector<MessageInfo> const& _infoMessages,
|
||||||
|
Totals const& _totals )
|
||||||
|
: assertionResult( _assertionResult ),
|
||||||
|
infoMessages( _infoMessages ),
|
||||||
|
totals( _totals )
|
||||||
|
{
|
||||||
|
assertionResult.m_resultData.lazyExpression.m_transientExpression = _assertionResult.m_resultData.lazyExpression.m_transientExpression;
|
||||||
|
|
||||||
|
if( assertionResult.hasMessage() ) {
|
||||||
|
// Copy message into messages list.
|
||||||
|
// !TBD This should have been done earlier, somewhere
|
||||||
|
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
||||||
|
builder << assertionResult.getMessage();
|
||||||
|
builder.m_info.message = builder.m_stream.str();
|
||||||
|
|
||||||
|
infoMessages.push_back( builder.m_info );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AssertionStats::~AssertionStats() = default;
|
||||||
|
|
||||||
|
SectionStats::SectionStats( SectionInfo const& _sectionInfo,
|
||||||
|
Counts const& _assertions,
|
||||||
|
double _durationInSeconds,
|
||||||
|
bool _missingAssertions )
|
||||||
|
: sectionInfo( _sectionInfo ),
|
||||||
|
assertions( _assertions ),
|
||||||
|
durationInSeconds( _durationInSeconds ),
|
||||||
|
missingAssertions( _missingAssertions )
|
||||||
|
{}
|
||||||
|
|
||||||
|
SectionStats::~SectionStats() = default;
|
||||||
|
|
||||||
|
|
||||||
|
TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo,
|
||||||
|
Totals const& _totals,
|
||||||
|
std::string const& _stdOut,
|
||||||
|
std::string const& _stdErr,
|
||||||
|
bool _aborting )
|
||||||
|
: testInfo( _testInfo ),
|
||||||
|
totals( _totals ),
|
||||||
|
stdOut( _stdOut ),
|
||||||
|
stdErr( _stdErr ),
|
||||||
|
aborting( _aborting )
|
||||||
|
{}
|
||||||
|
|
||||||
|
TestCaseStats::~TestCaseStats() = default;
|
||||||
|
|
||||||
|
|
||||||
|
TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo,
|
||||||
|
Totals const& _totals,
|
||||||
|
bool _aborting )
|
||||||
|
: groupInfo( _groupInfo ),
|
||||||
|
totals( _totals ),
|
||||||
|
aborting( _aborting )
|
||||||
|
{}
|
||||||
|
|
||||||
|
TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo )
|
||||||
|
: groupInfo( _groupInfo ),
|
||||||
|
aborting( false )
|
||||||
|
{}
|
||||||
|
|
||||||
|
TestGroupStats::~TestGroupStats() = default;
|
||||||
|
|
||||||
|
TestRunStats::TestRunStats( TestRunInfo const& _runInfo,
|
||||||
|
Totals const& _totals,
|
||||||
|
bool _aborting )
|
||||||
|
: runInfo( _runInfo ),
|
||||||
|
totals( _totals ),
|
||||||
|
aborting( _aborting )
|
||||||
|
{}
|
||||||
|
|
||||||
|
TestRunStats::~TestRunStats() = default;
|
||||||
|
|
||||||
|
void IStreamingReporter::fatalErrorEncountered( StringRef ) {}
|
||||||
|
bool IStreamingReporter::isMulti() const { return false; }
|
||||||
|
|
||||||
|
IReporterFactory::~IReporterFactory() = default;
|
||||||
|
IReporterRegistry::~IReporterRegistry() = default;
|
||||||
|
|
||||||
|
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter ) {
|
||||||
|
|
||||||
|
if( !existingReporter ) {
|
||||||
|
existingReporter = std::move( additionalReporter );
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MultipleReporters* multi = nullptr;
|
||||||
|
|
||||||
|
if( existingReporter->isMulti() ) {
|
||||||
|
multi = static_cast<MultipleReporters*>( existingReporter.get() );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
auto newMulti = std::unique_ptr<MultipleReporters>( new MultipleReporters );
|
||||||
|
newMulti->add( std::move( existingReporter ) );
|
||||||
|
multi = newMulti.get();
|
||||||
|
existingReporter = std::move( newMulti );
|
||||||
|
}
|
||||||
|
multi->add( std::move( additionalReporter ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
@ -10,46 +10,42 @@
|
|||||||
|
|
||||||
#include "catch_section_info.h"
|
#include "catch_section_info.h"
|
||||||
#include "catch_common.h"
|
#include "catch_common.h"
|
||||||
#include "catch_totals.hpp"
|
|
||||||
#include "catch_ptr.hpp"
|
|
||||||
#include "catch_config.hpp"
|
#include "catch_config.hpp"
|
||||||
|
#include "catch_totals.h"
|
||||||
#include "catch_test_case_info.h"
|
#include "catch_test_case_info.h"
|
||||||
#include "catch_assertionresult.h"
|
#include "catch_assertionresult.h"
|
||||||
#include "catch_message.h"
|
#include "catch_message.h"
|
||||||
#include "catch_option.hpp"
|
#include "catch_option.hpp"
|
||||||
|
#include "catch_stringref.h"
|
||||||
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <ostream>
|
#include <iosfwd>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
#include <set>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
namespace Catch
|
|
||||||
{
|
|
||||||
struct ReporterConfig {
|
struct ReporterConfig {
|
||||||
explicit ReporterConfig( Ptr<IConfig const> const& _fullConfig )
|
explicit ReporterConfig( IConfigPtr const& _fullConfig );
|
||||||
: m_stream( &_fullConfig->stream() ), m_fullConfig( _fullConfig ) {}
|
|
||||||
|
|
||||||
ReporterConfig( Ptr<IConfig const> const& _fullConfig, std::ostream& _stream )
|
ReporterConfig( IConfigPtr const& _fullConfig, std::ostream& _stream );
|
||||||
: m_stream( &_stream ), m_fullConfig( _fullConfig ) {}
|
|
||||||
|
|
||||||
std::ostream& stream() const { return *m_stream; }
|
std::ostream& stream() const;
|
||||||
Ptr<IConfig const> fullConfig() const { return m_fullConfig; }
|
IConfigPtr fullConfig() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::ostream* m_stream;
|
std::ostream* m_stream;
|
||||||
Ptr<IConfig const> m_fullConfig;
|
IConfigPtr m_fullConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ReporterPreferences {
|
struct ReporterPreferences {
|
||||||
ReporterPreferences()
|
bool shouldRedirectStdOut = false;
|
||||||
: shouldRedirectStdOut( false )
|
|
||||||
{}
|
|
||||||
|
|
||||||
bool shouldRedirectStdOut;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct LazyStat : Option<T> {
|
struct LazyStat : Option<T> {
|
||||||
LazyStat() : used( false ) {}
|
|
||||||
LazyStat& operator=( T const& _value ) {
|
LazyStat& operator=( T const& _value ) {
|
||||||
Option<T>::operator=( _value );
|
Option<T>::operator=( _value );
|
||||||
used = false;
|
used = false;
|
||||||
@ -59,21 +55,17 @@ namespace Catch
|
|||||||
Option<T>::reset();
|
Option<T>::reset();
|
||||||
used = false;
|
used = false;
|
||||||
}
|
}
|
||||||
bool used;
|
bool used = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct TestRunInfo {
|
struct TestRunInfo {
|
||||||
TestRunInfo( std::string const& _name ) : name( _name ) {}
|
TestRunInfo( std::string const& _name );
|
||||||
std::string name;
|
std::string name;
|
||||||
};
|
};
|
||||||
struct GroupInfo {
|
struct GroupInfo {
|
||||||
GroupInfo( std::string const& _name,
|
GroupInfo( std::string const& _name,
|
||||||
std::size_t _groupIndex,
|
std::size_t _groupIndex,
|
||||||
std::size_t _groupsCount )
|
std::size_t _groupsCount );
|
||||||
: name( _name ),
|
|
||||||
groupIndex( _groupIndex ),
|
|
||||||
groupsCounts( _groupsCount )
|
|
||||||
{}
|
|
||||||
|
|
||||||
std::string name;
|
std::string name;
|
||||||
std::size_t groupIndex;
|
std::size_t groupIndex;
|
||||||
@ -83,29 +75,13 @@ namespace Catch
|
|||||||
struct AssertionStats {
|
struct AssertionStats {
|
||||||
AssertionStats( AssertionResult const& _assertionResult,
|
AssertionStats( AssertionResult const& _assertionResult,
|
||||||
std::vector<MessageInfo> const& _infoMessages,
|
std::vector<MessageInfo> const& _infoMessages,
|
||||||
Totals const& _totals )
|
Totals const& _totals );
|
||||||
: assertionResult( _assertionResult ),
|
|
||||||
infoMessages( _infoMessages ),
|
|
||||||
totals( _totals )
|
|
||||||
{
|
|
||||||
if( assertionResult.hasMessage() ) {
|
|
||||||
// Copy message into messages list.
|
|
||||||
// !TBD This should have been done earlier, somewhere
|
|
||||||
MessageBuilder builder( assertionResult.getTestMacroName(), assertionResult.getSourceInfo(), assertionResult.getResultType() );
|
|
||||||
builder << assertionResult.getMessage();
|
|
||||||
builder.m_info.message = builder.m_stream.str();
|
|
||||||
|
|
||||||
infoMessages.push_back( builder.m_info );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
virtual ~AssertionStats();
|
|
||||||
|
|
||||||
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
AssertionStats( AssertionStats const& ) = default;
|
AssertionStats( AssertionStats const& ) = default;
|
||||||
AssertionStats( AssertionStats && ) = default;
|
AssertionStats( AssertionStats && ) = default;
|
||||||
AssertionStats& operator = ( AssertionStats const& ) = default;
|
AssertionStats& operator = ( AssertionStats const& ) = default;
|
||||||
AssertionStats& operator = ( AssertionStats && ) = default;
|
AssertionStats& operator = ( AssertionStats && ) = default;
|
||||||
# endif
|
virtual ~AssertionStats();
|
||||||
|
|
||||||
AssertionResult assertionResult;
|
AssertionResult assertionResult;
|
||||||
std::vector<MessageInfo> infoMessages;
|
std::vector<MessageInfo> infoMessages;
|
||||||
@ -116,19 +92,12 @@ namespace Catch
|
|||||||
SectionStats( SectionInfo const& _sectionInfo,
|
SectionStats( SectionInfo const& _sectionInfo,
|
||||||
Counts const& _assertions,
|
Counts const& _assertions,
|
||||||
double _durationInSeconds,
|
double _durationInSeconds,
|
||||||
bool _missingAssertions )
|
bool _missingAssertions );
|
||||||
: sectionInfo( _sectionInfo ),
|
|
||||||
assertions( _assertions ),
|
|
||||||
durationInSeconds( _durationInSeconds ),
|
|
||||||
missingAssertions( _missingAssertions )
|
|
||||||
{}
|
|
||||||
virtual ~SectionStats();
|
|
||||||
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
SectionStats( SectionStats const& ) = default;
|
SectionStats( SectionStats const& ) = default;
|
||||||
SectionStats( SectionStats && ) = default;
|
SectionStats( SectionStats && ) = default;
|
||||||
SectionStats& operator = ( SectionStats const& ) = default;
|
SectionStats& operator = ( SectionStats const& ) = default;
|
||||||
SectionStats& operator = ( SectionStats && ) = default;
|
SectionStats& operator = ( SectionStats && ) = default;
|
||||||
# endif
|
virtual ~SectionStats();
|
||||||
|
|
||||||
SectionInfo sectionInfo;
|
SectionInfo sectionInfo;
|
||||||
Counts assertions;
|
Counts assertions;
|
||||||
@ -141,21 +110,13 @@ namespace Catch
|
|||||||
Totals const& _totals,
|
Totals const& _totals,
|
||||||
std::string const& _stdOut,
|
std::string const& _stdOut,
|
||||||
std::string const& _stdErr,
|
std::string const& _stdErr,
|
||||||
bool _aborting )
|
bool _aborting );
|
||||||
: testInfo( _testInfo ),
|
|
||||||
totals( _totals ),
|
|
||||||
stdOut( _stdOut ),
|
|
||||||
stdErr( _stdErr ),
|
|
||||||
aborting( _aborting )
|
|
||||||
{}
|
|
||||||
virtual ~TestCaseStats();
|
|
||||||
|
|
||||||
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
TestCaseStats( TestCaseStats const& ) = default;
|
TestCaseStats( TestCaseStats const& ) = default;
|
||||||
TestCaseStats( TestCaseStats && ) = default;
|
TestCaseStats( TestCaseStats && ) = default;
|
||||||
TestCaseStats& operator = ( TestCaseStats const& ) = default;
|
TestCaseStats& operator = ( TestCaseStats const& ) = default;
|
||||||
TestCaseStats& operator = ( TestCaseStats && ) = default;
|
TestCaseStats& operator = ( TestCaseStats && ) = default;
|
||||||
# endif
|
virtual ~TestCaseStats();
|
||||||
|
|
||||||
TestCaseInfo testInfo;
|
TestCaseInfo testInfo;
|
||||||
Totals totals;
|
Totals totals;
|
||||||
@ -167,23 +128,14 @@ namespace Catch
|
|||||||
struct TestGroupStats {
|
struct TestGroupStats {
|
||||||
TestGroupStats( GroupInfo const& _groupInfo,
|
TestGroupStats( GroupInfo const& _groupInfo,
|
||||||
Totals const& _totals,
|
Totals const& _totals,
|
||||||
bool _aborting )
|
bool _aborting );
|
||||||
: groupInfo( _groupInfo ),
|
TestGroupStats( GroupInfo const& _groupInfo );
|
||||||
totals( _totals ),
|
|
||||||
aborting( _aborting )
|
|
||||||
{}
|
|
||||||
TestGroupStats( GroupInfo const& _groupInfo )
|
|
||||||
: groupInfo( _groupInfo ),
|
|
||||||
aborting( false )
|
|
||||||
{}
|
|
||||||
virtual ~TestGroupStats();
|
|
||||||
|
|
||||||
# ifdef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
TestGroupStats( TestGroupStats const& ) = default;
|
TestGroupStats( TestGroupStats const& ) = default;
|
||||||
TestGroupStats( TestGroupStats && ) = default;
|
TestGroupStats( TestGroupStats && ) = default;
|
||||||
TestGroupStats& operator = ( TestGroupStats const& ) = default;
|
TestGroupStats& operator = ( TestGroupStats const& ) = default;
|
||||||
TestGroupStats& operator = ( TestGroupStats && ) = default;
|
TestGroupStats& operator = ( TestGroupStats && ) = default;
|
||||||
# endif
|
virtual ~TestGroupStats();
|
||||||
|
|
||||||
GroupInfo groupInfo;
|
GroupInfo groupInfo;
|
||||||
Totals totals;
|
Totals totals;
|
||||||
@ -193,38 +145,34 @@ namespace Catch
|
|||||||
struct TestRunStats {
|
struct TestRunStats {
|
||||||
TestRunStats( TestRunInfo const& _runInfo,
|
TestRunStats( TestRunInfo const& _runInfo,
|
||||||
Totals const& _totals,
|
Totals const& _totals,
|
||||||
bool _aborting )
|
bool _aborting );
|
||||||
: runInfo( _runInfo ),
|
|
||||||
totals( _totals ),
|
|
||||||
aborting( _aborting )
|
|
||||||
{}
|
|
||||||
virtual ~TestRunStats();
|
|
||||||
|
|
||||||
# ifndef CATCH_CONFIG_CPP11_GENERATED_METHODS
|
|
||||||
TestRunStats( TestRunStats const& _other )
|
|
||||||
: runInfo( _other.runInfo ),
|
|
||||||
totals( _other.totals ),
|
|
||||||
aborting( _other.aborting )
|
|
||||||
{}
|
|
||||||
# else
|
|
||||||
TestRunStats( TestRunStats const& ) = default;
|
TestRunStats( TestRunStats const& ) = default;
|
||||||
TestRunStats( TestRunStats && ) = default;
|
TestRunStats( TestRunStats && ) = default;
|
||||||
TestRunStats& operator = ( TestRunStats const& ) = default;
|
TestRunStats& operator = ( TestRunStats const& ) = default;
|
||||||
TestRunStats& operator = ( TestRunStats && ) = default;
|
TestRunStats& operator = ( TestRunStats && ) = default;
|
||||||
# endif
|
virtual ~TestRunStats();
|
||||||
|
|
||||||
TestRunInfo runInfo;
|
TestRunInfo runInfo;
|
||||||
Totals totals;
|
Totals totals;
|
||||||
bool aborting;
|
bool aborting;
|
||||||
};
|
};
|
||||||
|
|
||||||
class MultipleReporters;
|
struct BenchmarkInfo {
|
||||||
|
std::string name;
|
||||||
|
};
|
||||||
|
struct BenchmarkStats {
|
||||||
|
BenchmarkInfo info;
|
||||||
|
std::size_t iterations;
|
||||||
|
uint64_t elapsedTimeInNanoseconds;
|
||||||
|
};
|
||||||
|
|
||||||
struct IStreamingReporter : IShared {
|
struct IStreamingReporter {
|
||||||
virtual ~IStreamingReporter();
|
virtual ~IStreamingReporter() = default;
|
||||||
|
|
||||||
// Implementing class must also provide the following static method:
|
// Implementing class must also provide the following static methods:
|
||||||
// static std::string getDescription();
|
// static std::string getDescription();
|
||||||
|
// static std::set<Verbosity> getSupportedVerbosities()
|
||||||
|
|
||||||
virtual ReporterPreferences getPreferences() const = 0;
|
virtual ReporterPreferences getPreferences() const = 0;
|
||||||
|
|
||||||
@ -236,11 +184,17 @@ namespace Catch
|
|||||||
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
virtual void testCaseStarting( TestCaseInfo const& testInfo ) = 0;
|
||||||
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
|
virtual void sectionStarting( SectionInfo const& sectionInfo ) = 0;
|
||||||
|
|
||||||
|
// *** experimental ***
|
||||||
|
virtual void benchmarkStarting( BenchmarkInfo const& ) {}
|
||||||
|
|
||||||
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
virtual void assertionStarting( AssertionInfo const& assertionInfo ) = 0;
|
||||||
|
|
||||||
// The return value indicates if the messages buffer should be cleared:
|
// The return value indicates if the messages buffer should be cleared:
|
||||||
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
|
virtual bool assertionEnded( AssertionStats const& assertionStats ) = 0;
|
||||||
|
|
||||||
|
// *** experimental ***
|
||||||
|
virtual void benchmarkEnded( BenchmarkStats const& ) {}
|
||||||
|
|
||||||
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
virtual void sectionEnded( SectionStats const& sectionStats ) = 0;
|
||||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
virtual void testCaseEnded( TestCaseStats const& testCaseStats ) = 0;
|
||||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
virtual void testGroupEnded( TestGroupStats const& testGroupStats ) = 0;
|
||||||
@ -248,28 +202,32 @@ namespace Catch
|
|||||||
|
|
||||||
virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
|
virtual void skipTest( TestCaseInfo const& testInfo ) = 0;
|
||||||
|
|
||||||
virtual MultipleReporters* tryAsMulti() { return CATCH_NULL; }
|
// Default empty implementation provided
|
||||||
|
virtual void fatalErrorEncountered( StringRef name );
|
||||||
|
|
||||||
|
virtual bool isMulti() const;
|
||||||
};
|
};
|
||||||
|
using IStreamingReporterPtr = std::unique_ptr<IStreamingReporter>;
|
||||||
|
|
||||||
|
struct IReporterFactory {
|
||||||
struct IReporterFactory : IShared {
|
|
||||||
virtual ~IReporterFactory();
|
virtual ~IReporterFactory();
|
||||||
virtual IStreamingReporter* create( ReporterConfig const& config ) const = 0;
|
virtual IStreamingReporterPtr create( ReporterConfig const& config ) const = 0;
|
||||||
virtual std::string getDescription() const = 0;
|
virtual std::string getDescription() const = 0;
|
||||||
};
|
};
|
||||||
|
using IReporterFactoryPtr = std::shared_ptr<IReporterFactory>;
|
||||||
|
|
||||||
struct IReporterRegistry {
|
struct IReporterRegistry {
|
||||||
typedef std::map<std::string, Ptr<IReporterFactory> > FactoryMap;
|
using FactoryMap = std::map<std::string, IReporterFactoryPtr>;
|
||||||
typedef std::vector<Ptr<IReporterFactory> > Listeners;
|
using Listeners = std::vector<IReporterFactoryPtr>;
|
||||||
|
|
||||||
virtual ~IReporterRegistry();
|
virtual ~IReporterRegistry();
|
||||||
virtual IStreamingReporter* create( std::string const& name, Ptr<IConfig const> const& config ) const = 0;
|
virtual IStreamingReporterPtr create( std::string const& name, IConfigPtr const& config ) const = 0;
|
||||||
virtual FactoryMap const& getFactories() const = 0;
|
virtual FactoryMap const& getFactories() const = 0;
|
||||||
virtual Listeners const& getListeners() const = 0;
|
virtual Listeners const& getListeners() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
Ptr<IStreamingReporter> addReporter( Ptr<IStreamingReporter> const& existingReporter, Ptr<IStreamingReporter> const& additionalReporter );
|
void addReporter( IStreamingReporterPtr& existingReporter, IStreamingReporterPtr&& additionalReporter );
|
||||||
|
|
||||||
}
|
} // end namespace Catch
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
|
#endif // TWOBLUECUBES_CATCH_INTERFACES_REPORTER_H_INCLUDED
|
||||||
|
5
include/internal/catch_interfaces_runner.cpp
Normal file
5
include/internal/catch_interfaces_runner.cpp
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include "internal/catch_interfaces_runner.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
IRunner::~IRunner() = default;
|
||||||
|
}
|
@ -9,7 +9,6 @@
|
|||||||
#define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_RUNNER_H_INCLUDED
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
class TestCase;
|
|
||||||
|
|
||||||
struct IRunner {
|
struct IRunner {
|
||||||
virtual ~IRunner();
|
virtual ~IRunner();
|
||||||
|
@ -8,14 +8,16 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_TAG_ALIAS_REGISTRY_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_tag_alias.h"
|
#include <string>
|
||||||
#include "catch_option.hpp"
|
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
|
struct TagAlias;
|
||||||
|
|
||||||
struct ITagAliasRegistry {
|
struct ITagAliasRegistry {
|
||||||
virtual ~ITagAliasRegistry();
|
virtual ~ITagAliasRegistry();
|
||||||
virtual Option<TagAlias> find( std::string const& alias ) const = 0;
|
// Nullptr if not present
|
||||||
|
virtual TagAlias const* find( std::string const& alias ) const = 0;
|
||||||
virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
|
virtual std::string expandAliases( std::string const& unexpandedTestSpec ) const = 0;
|
||||||
|
|
||||||
static ITagAliasRegistry const& get();
|
static ITagAliasRegistry const& get();
|
||||||
|
6
include/internal/catch_interfaces_testcase.cpp
Normal file
6
include/internal/catch_interfaces_testcase.cpp
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#include "internal/catch_interfaces_testcase.h"
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
ITestInvoker::~ITestInvoker() = default;
|
||||||
|
ITestCaseRegistry::~ITestCaseRegistry() = default;
|
||||||
|
}
|
@ -8,20 +8,20 @@
|
|||||||
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#ifndef TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
#define TWOBLUECUBES_CATCH_INTERFACES_TESTCASE_H_INCLUDED
|
||||||
|
|
||||||
#include "catch_ptr.hpp"
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class TestSpec;
|
class TestSpec;
|
||||||
|
|
||||||
struct ITestCase : IShared {
|
struct ITestInvoker {
|
||||||
virtual void invoke () const = 0;
|
virtual void invoke () const = 0;
|
||||||
protected:
|
virtual ~ITestInvoker();
|
||||||
virtual ~ITestCase();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
using ITestCasePtr = std::shared_ptr<ITestInvoker>;
|
||||||
|
|
||||||
class TestCase;
|
class TestCase;
|
||||||
struct IConfig;
|
struct IConfig;
|
||||||
|
|
||||||
|
33
include/internal/catch_leak_detector.cpp
Normal file
33
include/internal/catch_leak_detector.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 12/07/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_leak_detector.h"
|
||||||
|
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
#ifdef CATCH_CONFIG_WINDOWS_CRTDBG
|
||||||
|
#include <crtdbg.h>
|
||||||
|
|
||||||
|
LeakDetector::LeakDetector() {
|
||||||
|
int flag = _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG);
|
||||||
|
flag |= _CRTDBG_LEAK_CHECK_DF;
|
||||||
|
flag |= _CRTDBG_ALLOC_MEM_DF;
|
||||||
|
_CrtSetDbgFlag(flag);
|
||||||
|
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE | _CRTDBG_MODE_DEBUG);
|
||||||
|
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
|
||||||
|
// Change this to leaking allocation's number to break there
|
||||||
|
_CrtSetBreakAlloc(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
|
LeakDetector::LeakDetector(){}
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
17
include/internal/catch_leak_detector.h
Normal file
17
include/internal/catch_leak_detector.h
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* Created by Martin on 12/07/2017.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_LEAK_DETECTOR_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_LEAK_DETECTOR_H_INCLUDED
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
struct LeakDetector {
|
||||||
|
LeakDetector();
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
#endif // TWOBLUECUBES_CATCH_LEAK_DETECTOR_H_INCLUDED
|
@ -1,60 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 6th April 2013.
|
|
||||||
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_interfaces_reporter.h"
|
|
||||||
|
|
||||||
namespace Catch
|
|
||||||
{
|
|
||||||
// Deprecated
|
|
||||||
struct IReporter : IShared {
|
|
||||||
virtual ~IReporter();
|
|
||||||
|
|
||||||
virtual bool shouldRedirectStdout() const = 0;
|
|
||||||
|
|
||||||
virtual void StartTesting() = 0;
|
|
||||||
virtual void EndTesting( Totals const& totals ) = 0;
|
|
||||||
virtual void StartGroup( std::string const& groupName ) = 0;
|
|
||||||
virtual void EndGroup( std::string const& groupName, Totals const& totals ) = 0;
|
|
||||||
virtual void StartTestCase( TestCaseInfo const& testInfo ) = 0;
|
|
||||||
virtual void EndTestCase( TestCaseInfo const& testInfo, Totals const& totals, std::string const& stdOut, std::string const& stdErr ) = 0;
|
|
||||||
virtual void StartSection( std::string const& sectionName, std::string const& description ) = 0;
|
|
||||||
virtual void EndSection( std::string const& sectionName, Counts const& assertions ) = 0;
|
|
||||||
virtual void NoAssertionsInSection( std::string const& sectionName ) = 0;
|
|
||||||
virtual void NoAssertionsInTestCase( std::string const& testName ) = 0;
|
|
||||||
virtual void Aborted() = 0;
|
|
||||||
virtual void Result( AssertionResult const& result ) = 0;
|
|
||||||
};
|
|
||||||
|
|
||||||
class LegacyReporterAdapter : public SharedImpl<IStreamingReporter>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter );
|
|
||||||
virtual ~LegacyReporterAdapter();
|
|
||||||
|
|
||||||
virtual ReporterPreferences getPreferences() const;
|
|
||||||
virtual void noMatchingTestCases( std::string const& );
|
|
||||||
virtual void testRunStarting( TestRunInfo const& );
|
|
||||||
virtual void testGroupStarting( GroupInfo const& groupInfo );
|
|
||||||
virtual void testCaseStarting( TestCaseInfo const& testInfo );
|
|
||||||
virtual void sectionStarting( SectionInfo const& sectionInfo );
|
|
||||||
virtual void assertionStarting( AssertionInfo const& );
|
|
||||||
virtual bool assertionEnded( AssertionStats const& assertionStats );
|
|
||||||
virtual void sectionEnded( SectionStats const& sectionStats );
|
|
||||||
virtual void testCaseEnded( TestCaseStats const& testCaseStats );
|
|
||||||
virtual void testGroupEnded( TestGroupStats const& testGroupStats );
|
|
||||||
virtual void testRunEnded( TestRunStats const& testRunStats );
|
|
||||||
virtual void skipTest( TestCaseInfo const& );
|
|
||||||
|
|
||||||
private:
|
|
||||||
Ptr<IReporter> m_legacyReporter;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
|
|
@ -1,84 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 6th April 2013.
|
|
||||||
* Copyright 2013 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_legacy_reporter_adapter.h"
|
|
||||||
|
|
||||||
namespace Catch
|
|
||||||
{
|
|
||||||
LegacyReporterAdapter::LegacyReporterAdapter( Ptr<IReporter> const& legacyReporter )
|
|
||||||
: m_legacyReporter( legacyReporter )
|
|
||||||
{}
|
|
||||||
LegacyReporterAdapter::~LegacyReporterAdapter() {}
|
|
||||||
|
|
||||||
ReporterPreferences LegacyReporterAdapter::getPreferences() const {
|
|
||||||
ReporterPreferences prefs;
|
|
||||||
prefs.shouldRedirectStdOut = m_legacyReporter->shouldRedirectStdout();
|
|
||||||
return prefs;
|
|
||||||
}
|
|
||||||
|
|
||||||
void LegacyReporterAdapter::noMatchingTestCases( std::string const& ) {}
|
|
||||||
void LegacyReporterAdapter::testRunStarting( TestRunInfo const& ) {
|
|
||||||
m_legacyReporter->StartTesting();
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::testGroupStarting( GroupInfo const& groupInfo ) {
|
|
||||||
m_legacyReporter->StartGroup( groupInfo.name );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::testCaseStarting( TestCaseInfo const& testInfo ) {
|
|
||||||
m_legacyReporter->StartTestCase( testInfo );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::sectionStarting( SectionInfo const& sectionInfo ) {
|
|
||||||
m_legacyReporter->StartSection( sectionInfo.name, sectionInfo.description );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::assertionStarting( AssertionInfo const& ) {
|
|
||||||
// Not on legacy interface
|
|
||||||
}
|
|
||||||
|
|
||||||
bool LegacyReporterAdapter::assertionEnded( AssertionStats const& assertionStats ) {
|
|
||||||
if( assertionStats.assertionResult.getResultType() != ResultWas::Ok ) {
|
|
||||||
for( std::vector<MessageInfo>::const_iterator it = assertionStats.infoMessages.begin(), itEnd = assertionStats.infoMessages.end();
|
|
||||||
it != itEnd;
|
|
||||||
++it ) {
|
|
||||||
if( it->type == ResultWas::Info ) {
|
|
||||||
ResultBuilder rb( it->macroName.c_str(), it->lineInfo, "", ResultDisposition::Normal );
|
|
||||||
rb << it->message;
|
|
||||||
rb.setResultType( ResultWas::Info );
|
|
||||||
AssertionResult result = rb.build();
|
|
||||||
m_legacyReporter->Result( result );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
m_legacyReporter->Result( assertionStats.assertionResult );
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::sectionEnded( SectionStats const& sectionStats ) {
|
|
||||||
if( sectionStats.missingAssertions )
|
|
||||||
m_legacyReporter->NoAssertionsInSection( sectionStats.sectionInfo.name );
|
|
||||||
m_legacyReporter->EndSection( sectionStats.sectionInfo.name, sectionStats.assertions );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::testCaseEnded( TestCaseStats const& testCaseStats ) {
|
|
||||||
m_legacyReporter->EndTestCase
|
|
||||||
( testCaseStats.testInfo,
|
|
||||||
testCaseStats.totals,
|
|
||||||
testCaseStats.stdOut,
|
|
||||||
testCaseStats.stdErr );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::testGroupEnded( TestGroupStats const& testGroupStats ) {
|
|
||||||
if( testGroupStats.aborting )
|
|
||||||
m_legacyReporter->Aborted();
|
|
||||||
m_legacyReporter->EndGroup( testGroupStats.groupInfo.name, testGroupStats.totals );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::testRunEnded( TestRunStats const& testRunStats ) {
|
|
||||||
m_legacyReporter->EndTesting( testRunStats.totals );
|
|
||||||
}
|
|
||||||
void LegacyReporterAdapter::skipTest( TestCaseInfo const& ) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_LEGACY_REPORTER_ADAPTER_H_INCLUDED
|
|
165
include/internal/catch_list.cpp
Normal file
165
include/internal/catch_list.cpp
Normal file
@ -0,0 +1,165 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 5/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "catch_list.h"
|
||||||
|
|
||||||
|
#include "catch_interfaces_registry_hub.h"
|
||||||
|
#include "catch_interfaces_reporter.h"
|
||||||
|
#include "catch_interfaces_testcase.h"
|
||||||
|
|
||||||
|
#include "catch_stream.h"
|
||||||
|
#include "catch_text.h"
|
||||||
|
|
||||||
|
#include "catch_console_colour.h"
|
||||||
|
#include "catch_test_spec_parser.h"
|
||||||
|
#include "catch_tostring.h"
|
||||||
|
#include "catch_string_manip.h"
|
||||||
|
|
||||||
|
#include <limits>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
std::size_t listTests( Config const& config ) {
|
||||||
|
TestSpec testSpec = config.testSpec();
|
||||||
|
if( config.testSpec().hasFilters() )
|
||||||
|
Catch::cout() << "Matching test cases:\n";
|
||||||
|
else {
|
||||||
|
Catch::cout() << "All available test cases:\n";
|
||||||
|
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
||||||
|
}
|
||||||
|
|
||||||
|
auto matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
||||||
|
for( auto const& testCaseInfo : matchedTestCases ) {
|
||||||
|
Colour::Code colour = testCaseInfo.isHidden()
|
||||||
|
? Colour::SecondaryText
|
||||||
|
: Colour::None;
|
||||||
|
Colour colourGuard( colour );
|
||||||
|
|
||||||
|
Catch::cout() << Column( testCaseInfo.name ).initialIndent( 2 ).indent( 4 ) << "\n";
|
||||||
|
if( config.verbosity() >= Verbosity::High ) {
|
||||||
|
Catch::cout() << Column( Catch::Detail::stringify( testCaseInfo.lineInfo ) ).indent(4) << std::endl;
|
||||||
|
std::string description = testCaseInfo.description;
|
||||||
|
if( description.empty() )
|
||||||
|
description = "(NO DESCRIPTION)";
|
||||||
|
Catch::cout() << Column( description ).indent(4) << std::endl;
|
||||||
|
}
|
||||||
|
if( !testCaseInfo.tags.empty() )
|
||||||
|
Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if( !config.testSpec().hasFilters() )
|
||||||
|
Catch::cout() << pluralise( matchedTestCases.size(), "test case" ) << '\n' << std::endl;
|
||||||
|
else
|
||||||
|
Catch::cout() << pluralise( matchedTestCases.size(), "matching test case" ) << '\n' << std::endl;
|
||||||
|
return matchedTestCases.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t listTestsNamesOnly( Config const& config ) {
|
||||||
|
TestSpec testSpec = config.testSpec();
|
||||||
|
if( !config.testSpec().hasFilters() )
|
||||||
|
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
||||||
|
std::size_t matchedTests = 0;
|
||||||
|
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
||||||
|
for( auto const& testCaseInfo : matchedTestCases ) {
|
||||||
|
matchedTests++;
|
||||||
|
if( startsWith( testCaseInfo.name, '#' ) )
|
||||||
|
Catch::cout() << '"' << testCaseInfo.name << '"';
|
||||||
|
else
|
||||||
|
Catch::cout() << testCaseInfo.name;
|
||||||
|
if ( config.verbosity() >= Verbosity::High )
|
||||||
|
Catch::cout() << "\t@" << testCaseInfo.lineInfo;
|
||||||
|
Catch::cout() << std::endl;
|
||||||
|
}
|
||||||
|
return matchedTests;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TagInfo::add( std::string const& spelling ) {
|
||||||
|
++count;
|
||||||
|
spellings.insert( spelling );
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string TagInfo::all() const {
|
||||||
|
std::string out;
|
||||||
|
for( auto const& spelling : spellings )
|
||||||
|
out += "[" + spelling + "]";
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t listTags( Config const& config ) {
|
||||||
|
TestSpec testSpec = config.testSpec();
|
||||||
|
if( config.testSpec().hasFilters() )
|
||||||
|
Catch::cout() << "Tags for matching test cases:\n";
|
||||||
|
else {
|
||||||
|
Catch::cout() << "All available tags:\n";
|
||||||
|
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::map<std::string, TagInfo> tagCounts;
|
||||||
|
|
||||||
|
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
||||||
|
for( auto const& testCase : matchedTestCases ) {
|
||||||
|
for( auto const& tagName : testCase.getTestCaseInfo().tags ) {
|
||||||
|
std::string lcaseTagName = toLower( tagName );
|
||||||
|
auto countIt = tagCounts.find( lcaseTagName );
|
||||||
|
if( countIt == tagCounts.end() )
|
||||||
|
countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
|
||||||
|
countIt->second.add( tagName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for( auto const& tagCount : tagCounts ) {
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << " " << std::setw(2) << tagCount.second.count << " ";
|
||||||
|
auto wrapper = Column( tagCount.second.all() )
|
||||||
|
.initialIndent( 0 )
|
||||||
|
.indent( oss.str().size() )
|
||||||
|
.width( CATCH_CONFIG_CONSOLE_WIDTH-10 );
|
||||||
|
Catch::cout() << oss.str() << wrapper << '\n';
|
||||||
|
}
|
||||||
|
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
|
||||||
|
return tagCounts.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::size_t listReporters( Config const& /*config*/ ) {
|
||||||
|
Catch::cout() << "Available reporters:\n";
|
||||||
|
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
||||||
|
std::size_t maxNameLen = 0;
|
||||||
|
for( auto const& factoryKvp : factories )
|
||||||
|
maxNameLen = (std::max)( maxNameLen, factoryKvp.first.size() );
|
||||||
|
|
||||||
|
for( auto const& factoryKvp : factories ) {
|
||||||
|
Catch::cout()
|
||||||
|
<< Column( factoryKvp.first + ":" )
|
||||||
|
.indent(2)
|
||||||
|
.width( 5+maxNameLen )
|
||||||
|
+ Column( factoryKvp.second->getDescription() )
|
||||||
|
.initialIndent(0)
|
||||||
|
.indent(2)
|
||||||
|
.width( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 )
|
||||||
|
<< "\n";
|
||||||
|
}
|
||||||
|
Catch::cout() << std::endl;
|
||||||
|
return factories.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
Option<std::size_t> list( Config const& config ) {
|
||||||
|
Option<std::size_t> listedCount;
|
||||||
|
if( config.listTests() )
|
||||||
|
listedCount = listedCount.valueOr(0) + listTests( config );
|
||||||
|
if( config.listTestNamesOnly() )
|
||||||
|
listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
|
||||||
|
if( config.listTags() )
|
||||||
|
listedCount = listedCount.valueOr(0) + listTags( config );
|
||||||
|
if( config.listReporters() )
|
||||||
|
listedCount = listedCount.valueOr(0) + listReporters( config );
|
||||||
|
return listedCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // end namespace Catch
|
38
include/internal/catch_list.h
Normal file
38
include/internal/catch_list.h
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Created by Phil on 5/11/2010.
|
||||||
|
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
||||||
|
*
|
||||||
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||||
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||||
|
*/
|
||||||
|
#ifndef TWOBLUECUBES_CATCH_LIST_H_INCLUDED
|
||||||
|
#define TWOBLUECUBES_CATCH_LIST_H_INCLUDED
|
||||||
|
|
||||||
|
#include "catch_option.hpp"
|
||||||
|
#include "catch_config.hpp"
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
namespace Catch {
|
||||||
|
|
||||||
|
std::size_t listTests( Config const& config );
|
||||||
|
|
||||||
|
std::size_t listTestsNamesOnly( Config const& config );
|
||||||
|
|
||||||
|
struct TagInfo {
|
||||||
|
void add( std::string const& spelling );
|
||||||
|
std::string all() const;
|
||||||
|
|
||||||
|
std::set<std::string> spellings;
|
||||||
|
std::size_t count = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::size_t listTags( Config const& config );
|
||||||
|
|
||||||
|
std::size_t listReporters( Config const& /*config*/ );
|
||||||
|
|
||||||
|
Option<std::size_t> list( Config const& config );
|
||||||
|
|
||||||
|
} // end namespace Catch
|
||||||
|
|
||||||
|
#endif // TWOBLUECUBES_CATCH_LIST_H_INCLUDED
|
@ -1,190 +0,0 @@
|
|||||||
/*
|
|
||||||
* Created by Phil on 5/11/2010.
|
|
||||||
* Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
|
|
||||||
*
|
|
||||||
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
||||||
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
||||||
*/
|
|
||||||
#ifndef TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
|
||||||
#define TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
|
||||||
|
|
||||||
#include "catch_commandline.hpp"
|
|
||||||
#include "catch_text.h"
|
|
||||||
#include "catch_console_colour.hpp"
|
|
||||||
#include "catch_interfaces_reporter.h"
|
|
||||||
#include "catch_test_spec_parser.hpp"
|
|
||||||
|
|
||||||
#include <limits>
|
|
||||||
#include <algorithm>
|
|
||||||
|
|
||||||
namespace Catch {
|
|
||||||
|
|
||||||
inline std::size_t listTests( Config const& config ) {
|
|
||||||
|
|
||||||
TestSpec testSpec = config.testSpec();
|
|
||||||
if( config.testSpec().hasFilters() )
|
|
||||||
Catch::cout() << "Matching test cases:\n";
|
|
||||||
else {
|
|
||||||
Catch::cout() << "All available test cases:\n";
|
|
||||||
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t matchedTests = 0;
|
|
||||||
TextAttributes nameAttr, descAttr, tagsAttr;
|
|
||||||
nameAttr.setInitialIndent( 2 ).setIndent( 4 );
|
|
||||||
descAttr.setIndent( 4 );
|
|
||||||
tagsAttr.setIndent( 6 );
|
|
||||||
|
|
||||||
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
|
||||||
for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
|
|
||||||
it != itEnd;
|
|
||||||
++it ) {
|
|
||||||
matchedTests++;
|
|
||||||
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
|
|
||||||
Colour::Code colour = testCaseInfo.isHidden()
|
|
||||||
? Colour::SecondaryText
|
|
||||||
: Colour::None;
|
|
||||||
Colour colourGuard( colour );
|
|
||||||
|
|
||||||
Catch::cout() << Text( testCaseInfo.name, nameAttr ) << std::endl;
|
|
||||||
if( config.listExtraInfo() ) {
|
|
||||||
Catch::cout() << " " << testCaseInfo.lineInfo << std::endl;
|
|
||||||
std::string description = testCaseInfo.description;
|
|
||||||
if( description.empty() )
|
|
||||||
description = "(NO DESCRIPTION)";
|
|
||||||
Catch::cout() << Text( description, descAttr ) << std::endl;
|
|
||||||
}
|
|
||||||
if( !testCaseInfo.tags.empty() )
|
|
||||||
Catch::cout() << Text( testCaseInfo.tagsAsString, tagsAttr ) << std::endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
if( !config.testSpec().hasFilters() )
|
|
||||||
Catch::cout() << pluralise( matchedTests, "test case" ) << '\n' << std::endl;
|
|
||||||
else
|
|
||||||
Catch::cout() << pluralise( matchedTests, "matching test case" ) << '\n' << std::endl;
|
|
||||||
return matchedTests;
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::size_t listTestsNamesOnly( Config const& config ) {
|
|
||||||
TestSpec testSpec = config.testSpec();
|
|
||||||
if( !config.testSpec().hasFilters() )
|
|
||||||
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
|
||||||
std::size_t matchedTests = 0;
|
|
||||||
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
|
||||||
for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
|
|
||||||
it != itEnd;
|
|
||||||
++it ) {
|
|
||||||
matchedTests++;
|
|
||||||
TestCaseInfo const& testCaseInfo = it->getTestCaseInfo();
|
|
||||||
if( startsWith( testCaseInfo.name, '#' ) )
|
|
||||||
Catch::cout() << '"' << testCaseInfo.name << '"';
|
|
||||||
else
|
|
||||||
Catch::cout() << testCaseInfo.name;
|
|
||||||
if ( config.listExtraInfo() )
|
|
||||||
Catch::cout() << "\t@" << testCaseInfo.lineInfo;
|
|
||||||
Catch::cout() << std::endl;
|
|
||||||
}
|
|
||||||
return matchedTests;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct TagInfo {
|
|
||||||
TagInfo() : count ( 0 ) {}
|
|
||||||
void add( std::string const& spelling ) {
|
|
||||||
++count;
|
|
||||||
spellings.insert( spelling );
|
|
||||||
}
|
|
||||||
std::string all() const {
|
|
||||||
std::string out;
|
|
||||||
for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
|
|
||||||
it != itEnd;
|
|
||||||
++it )
|
|
||||||
out += "[" + *it + "]";
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
std::set<std::string> spellings;
|
|
||||||
std::size_t count;
|
|
||||||
};
|
|
||||||
|
|
||||||
inline std::size_t listTags( Config const& config ) {
|
|
||||||
TestSpec testSpec = config.testSpec();
|
|
||||||
if( config.testSpec().hasFilters() )
|
|
||||||
Catch::cout() << "Tags for matching test cases:\n";
|
|
||||||
else {
|
|
||||||
Catch::cout() << "All available tags:\n";
|
|
||||||
testSpec = TestSpecParser( ITagAliasRegistry::get() ).parse( "*" ).testSpec();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::map<std::string, TagInfo> tagCounts;
|
|
||||||
|
|
||||||
std::vector<TestCase> matchedTestCases = filterTests( getAllTestCasesSorted( config ), testSpec, config );
|
|
||||||
for( std::vector<TestCase>::const_iterator it = matchedTestCases.begin(), itEnd = matchedTestCases.end();
|
|
||||||
it != itEnd;
|
|
||||||
++it ) {
|
|
||||||
for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
|
|
||||||
tagItEnd = it->getTestCaseInfo().tags.end();
|
|
||||||
tagIt != tagItEnd;
|
|
||||||
++tagIt ) {
|
|
||||||
std::string tagName = *tagIt;
|
|
||||||
std::string lcaseTagName = toLower( tagName );
|
|
||||||
std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
|
|
||||||
if( countIt == tagCounts.end() )
|
|
||||||
countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
|
|
||||||
countIt->second.add( tagName );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
|
|
||||||
countItEnd = tagCounts.end();
|
|
||||||
countIt != countItEnd;
|
|
||||||
++countIt ) {
|
|
||||||
std::ostringstream oss;
|
|
||||||
oss << " " << std::setw(2) << countIt->second.count << " ";
|
|
||||||
Text wrapper( countIt->second.all(), TextAttributes()
|
|
||||||
.setInitialIndent( 0 )
|
|
||||||
.setIndent( oss.str().size() )
|
|
||||||
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
|
|
||||||
Catch::cout() << oss.str() << wrapper << '\n';
|
|
||||||
}
|
|
||||||
Catch::cout() << pluralise( tagCounts.size(), "tag" ) << '\n' << std::endl;
|
|
||||||
return tagCounts.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline std::size_t listReporters( Config const& /*config*/ ) {
|
|
||||||
Catch::cout() << "Available reporters:\n";
|
|
||||||
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
|
||||||
IReporterRegistry::FactoryMap::const_iterator itBegin = factories.begin(), itEnd = factories.end(), it;
|
|
||||||
std::size_t maxNameLen = 0;
|
|
||||||
for(it = itBegin; it != itEnd; ++it )
|
|
||||||
maxNameLen = (std::max)( maxNameLen, it->first.size() );
|
|
||||||
|
|
||||||
for(it = itBegin; it != itEnd; ++it ) {
|
|
||||||
Text wrapper( it->second->getDescription(), TextAttributes()
|
|
||||||
.setInitialIndent( 0 )
|
|
||||||
.setIndent( 7+maxNameLen )
|
|
||||||
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH - maxNameLen-8 ) );
|
|
||||||
Catch::cout() << " "
|
|
||||||
<< it->first
|
|
||||||
<< ':'
|
|
||||||
<< std::string( maxNameLen - it->first.size() + 2, ' ' )
|
|
||||||
<< wrapper << '\n';
|
|
||||||
}
|
|
||||||
Catch::cout() << std::endl;
|
|
||||||
return factories.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
inline Option<std::size_t> list( Config const& config ) {
|
|
||||||
Option<std::size_t> listedCount;
|
|
||||||
if( config.listTests() || ( config.listExtraInfo() && !config.listTestNamesOnly() ) )
|
|
||||||
listedCount = listedCount.valueOr(0) + listTests( config );
|
|
||||||
if( config.listTestNamesOnly() )
|
|
||||||
listedCount = listedCount.valueOr(0) + listTestsNamesOnly( config );
|
|
||||||
if( config.listTags() )
|
|
||||||
listedCount = listedCount.valueOr(0) + listTags( config );
|
|
||||||
if( config.listReporters() )
|
|
||||||
listedCount = listedCount.valueOr(0) + listReporters( config );
|
|
||||||
return listedCount;
|
|
||||||
}
|
|
||||||
|
|
||||||
} // end namespace Catch
|
|
||||||
|
|
||||||
#endif // TWOBLUECUBES_CATCH_LIST_HPP_INCLUDED
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user