catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Split out internal error macros from the common path
- Commit
feca97dfde802825222b1ac8eb715ba636b42586- Author
- Martin Hořeňovský ·
- Parents
c815ad1d534e
Changes
CMakeLists.txt | 1 + include/catch_session.hpp | 1 + include/internal/catch_common.cpp | 1 + include/internal/catch_common.h | 13 +++--------- include/internal/catch_config.cpp | 1 + include/internal/catch_console_colour.cpp | 1 + include/internal/catch_enforce.h | 24 ++++++++++++++++++++++ include/internal/catch_matchers.hpp | 1 + include/internal/catch_message.h | 1 + include/internal/catch_notimplemented_exception.h | 2 ++ include/internal/catch_result_builder.h | 2 ++ include/internal/catch_run_context.cpp | 1 + include/internal/catch_stream.hpp | 1 + include/internal/catch_tag_alias_registry.cpp | 1 + include/internal/catch_test_case_info.cpp | 3 ++- include/internal/catch_test_case_info.h | 2 ++ include/internal/catch_test_case_registry_impl.cpp | 1 + include/internal/catch_test_case_registry_impl.hpp | 2 +- include/internal/catch_test_case_tracker.cpp | 2 ++ include/internal/catch_wildcard_pattern.cpp | 1 + include/reporters/catch_reporter_bases.hpp | 2 ++ 21 files changed, 52 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6af88fdd..715ac0ae 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,7 @@ set(INTERNAL_HEADERS ${HEADER_DIR}/internal/catch_context.h ${HEADER_DIR}/internal/catch_debugger.h ${HEADER_DIR}/internal/catch_default_main.hpp + ${HEADER_DIR}/internal/catch_enforce.h ${HEADER_DIR}/internal/catch_errno_guard.h ${HEADER_DIR}/internal/catch_evaluate.hpp ${HEADER_DIR}/internal/catch_exception_translator_registry.h diff --git a/include/catch_session.hpp b/include/catch_session.hpp index 7bbd34b2..93c75cf3 100644 --- a/include/catch_session.hpp +++ b/include/catch_session.hpp @@ -10,6 +10,7 @@ #include "internal/catch_commandline.hpp" #include "internal/catch_console_colour.hpp" +#include "internal/catch_enforce.h" #include "internal/catch_list.h" #include "internal/catch_run_context.hpp" #include "internal/catch_test_spec.hpp" diff --git a/include/internal/catch_common.cpp b/include/internal/catch_common.cpp index d865cd52..753b9487 100644 --- a/include/internal/catch_common.cpp +++ b/include/internal/catch_common.cpp @@ -11,6 +11,7 @@ #include "catch_interfaces_config.h" #include <cstring> +#include <ostream> namespace Catch { diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h index 5c5de452..c62fafe2 100644 --- a/include/internal/catch_common.h +++ b/include/internal/catch_common.h @@ -21,8 +21,9 @@ #define INTERNAL_CATCH_STRINGIFY2( expr ) #expr #define INTERNAL_CATCH_STRINGIFY( expr ) INTERNAL_CATCH_STRINGIFY2( expr ) -#include <sstream> -#include <exception> +#include <iosfwd> +#include <string> +#include <cstdint> namespace Catch { @@ -87,14 +88,6 @@ namespace Catch { #define CATCH_INTERNAL_LINEINFO \ ::Catch::SourceLineInfo( __FILE__, static_cast<std::size_t>( __LINE__ ) ) -#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_COMMON_H_INCLUDED diff --git a/include/internal/catch_config.cpp b/include/internal/catch_config.cpp index dd3bbdc6..ae1e95dd 100644 --- a/include/internal/catch_config.cpp +++ b/include/internal/catch_config.cpp @@ -6,6 +6,7 @@ */ #include "catch_config.hpp" +#include "catch_enforce.h" namespace Catch { diff --git a/include/internal/catch_console_colour.cpp b/include/internal/catch_console_colour.cpp index 1f382030..a444b076 100644 --- a/include/internal/catch_console_colour.cpp +++ b/include/internal/catch_console_colour.cpp @@ -7,6 +7,7 @@ */ #include "catch_console_colour.hpp" +#include "catch_enforce.h" #include "catch_errno_guard.h" #include "catch_interfaces_config.h" #include "catch_stream.h" diff --git a/include/internal/catch_enforce.h b/include/internal/catch_enforce.h new file mode 100644 index 00000000..b500949d --- /dev/null +++ b/include/internal/catch_enforce.h @@ -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 <exception> + +#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 diff --git a/include/internal/catch_matchers.hpp b/include/internal/catch_matchers.hpp index 12aa0d7b..c120bbf3 100644 --- a/include/internal/catch_matchers.hpp +++ b/include/internal/catch_matchers.hpp @@ -12,6 +12,7 @@ #include "catch_common.h" +#include <string> #include <vector> namespace Catch { diff --git a/include/internal/catch_message.h b/include/internal/catch_message.h index e2cc65aa..2550fb41 100644 --- a/include/internal/catch_message.h +++ b/include/internal/catch_message.h @@ -9,6 +9,7 @@ #define TWOBLUECUBES_CATCH_MESSAGE_H_INCLUDED #include <string> +#include <sstream> #include "catch_result_type.h" #include "catch_common.h" diff --git a/include/internal/catch_notimplemented_exception.h b/include/internal/catch_notimplemented_exception.h index 640cc167..4769c57d 100644 --- a/include/internal/catch_notimplemented_exception.h +++ b/include/internal/catch_notimplemented_exception.h @@ -10,6 +10,8 @@ #include "catch_common.h" +#include <exception> + namespace Catch { class NotImplementedException : public std::exception diff --git a/include/internal/catch_result_builder.h b/include/internal/catch_result_builder.h index 9ea6d038..90cbf5be 100644 --- a/include/internal/catch_result_builder.h +++ b/include/internal/catch_result_builder.h @@ -13,6 +13,8 @@ #include "catch_common.h" #include "catch_matchers.hpp" +#include <sstream> + namespace Catch { struct TestFailureException{}; diff --git a/include/internal/catch_run_context.cpp b/include/internal/catch_run_context.cpp index 68f824fa..31d6b8a6 100644 --- a/include/internal/catch_run_context.cpp +++ b/include/internal/catch_run_context.cpp @@ -1,4 +1,5 @@ #include "catch_run_context.hpp" +#include "catch_enforce.h" #include <cassert> #include <algorithm> diff --git a/include/internal/catch_stream.hpp b/include/internal/catch_stream.hpp index 89f6cdea..3b7bbe60 100644 --- a/include/internal/catch_stream.hpp +++ b/include/internal/catch_stream.hpp @@ -10,6 +10,7 @@ #define TWOBLUECUBES_CATCH_STREAM_HPP_INCLUDED #include "catch_common.h" +#include "catch_enforce.h" #include "catch_stream.h" #include "catch_debugger.h" diff --git a/include/internal/catch_tag_alias_registry.cpp b/include/internal/catch_tag_alias_registry.cpp index 3bf14c82..f100ea9d 100644 --- a/include/internal/catch_tag_alias_registry.cpp +++ b/include/internal/catch_tag_alias_registry.cpp @@ -8,6 +8,7 @@ #include "catch_tag_alias_registry.h" #include "catch_console_colour.hpp" +#include "catch_enforce.h" #include "catch_interfaces_registry_hub.h" #include "catch_stream.h" #include "catch_string_manip.h" diff --git a/include/internal/catch_test_case_info.cpp b/include/internal/catch_test_case_info.cpp index 4a392da6..5a8d8c0f 100644 --- a/include/internal/catch_test_case_info.cpp +++ b/include/internal/catch_test_case_info.cpp @@ -6,8 +6,9 @@ * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ -#include "catch_test_spec.hpp" #include "catch_test_case_info.h" +#include "catch_enforce.h" +#include "catch_test_spec.hpp" #include "catch_interfaces_testcase.h" #include "catch_string_manip.h" diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h index 44b9fa38..626f95cb 100644 --- a/include/internal/catch_test_case_info.h +++ b/include/internal/catch_test_case_info.h @@ -8,6 +8,8 @@ #ifndef TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED +#include "catch_common.h" + #include <string> #include <vector> #include <memory> diff --git a/include/internal/catch_test_case_registry_impl.cpp b/include/internal/catch_test_case_registry_impl.cpp index d7cab1d8..0bf0000f 100644 --- a/include/internal/catch_test_case_registry_impl.cpp +++ b/include/internal/catch_test_case_registry_impl.cpp @@ -8,6 +8,7 @@ #include "catch_test_case_registry_impl.hpp" #include "catch_context.h" +#include "catch_enforce.h" #include "catch_interfaces_registry_hub.h" #include "catch_string_manip.h" #include "catch_test_case_info.h" diff --git a/include/internal/catch_test_case_registry_impl.hpp b/include/internal/catch_test_case_registry_impl.hpp index 956b3dbf..ee412d9e 100644 --- a/include/internal/catch_test_case_registry_impl.hpp +++ b/include/internal/catch_test_case_registry_impl.hpp @@ -15,7 +15,7 @@ #include <vector> #include <set> #include <algorithm> - +#include <ios> namespace Catch { diff --git a/include/internal/catch_test_case_tracker.cpp b/include/internal/catch_test_case_tracker.cpp index 2616afe4..6960c75f 100644 --- a/include/internal/catch_test_case_tracker.cpp +++ b/include/internal/catch_test_case_tracker.cpp @@ -7,6 +7,8 @@ #include "catch_test_case_tracker.hpp" +#include "catch_enforce.h" + #include <algorithm> #include <assert.h> #include <stdexcept> diff --git a/include/internal/catch_wildcard_pattern.cpp b/include/internal/catch_wildcard_pattern.cpp index f33035dd..106e49b4 100644 --- a/include/internal/catch_wildcard_pattern.cpp +++ b/include/internal/catch_wildcard_pattern.cpp @@ -6,6 +6,7 @@ */ #include "catch_wildcard_pattern.hpp" +#include "catch_enforce.h" #include "catch_string_manip.h" diff --git a/include/reporters/catch_reporter_bases.hpp b/include/reporters/catch_reporter_bases.hpp index 6fd40243..6d627839 100644 --- a/include/reporters/catch_reporter_bases.hpp +++ b/include/reporters/catch_reporter_bases.hpp @@ -8,8 +8,10 @@ #ifndef TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_BASES_HPP_INCLUDED +#include "../internal/catch_enforce.h" #include "../internal/catch_interfaces_reporter.h" + #include <algorithm> #include <cstring> #include <cfloat>