diff --git a/include/internal/catch_enforce.h b/include/internal/catch_enforce.h index ad11c815..0484724d 100644 --- a/include/internal/catch_enforce.h +++ b/include/internal/catch_enforce.h @@ -38,13 +38,13 @@ namespace Catch { (Catch::ReusableStringStream() << __VA_ARGS__).str() #define CATCH_INTERNAL_ERROR(...) \ - Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__)); + Catch::throw_logic_error(CATCH_MAKE_MSG( CATCH_INTERNAL_LINEINFO << ": Internal Catch2 error: " << __VA_ARGS__)) #define CATCH_ERROR(...) \ - Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ )); + Catch::throw_domain_error(CATCH_MAKE_MSG( __VA_ARGS__ )) #define CATCH_RUNTIME_ERROR(...) \ - Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ )); + Catch::throw_runtime_error(CATCH_MAKE_MSG( __VA_ARGS__ )) #define CATCH_ENFORCE( condition, ... ) \ do{ if( !(condition) ) CATCH_ERROR( __VA_ARGS__ ); } while(false) diff --git a/projects/CMakeLists.txt b/projects/CMakeLists.txt index 94233d7c..1f84ba09 100644 --- a/projects/CMakeLists.txt +++ b/projects/CMakeLists.txt @@ -17,6 +17,7 @@ endif(MSVC) #Temporary workaround set(TEST_SOURCES ${SELF_TEST_DIR}/TestMain.cpp ${SELF_TEST_DIR}/IntrospectiveTests/CmdLine.tests.cpp + ${SELF_TEST_DIR}/IntrospectiveTests/Details.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/GeneratorsImpl.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/InternalBenchmark.tests.cpp ${SELF_TEST_DIR}/IntrospectiveTests/PartTracker.tests.cpp diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index 45a37c57..14fba5d7 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -265,6 +265,10 @@ ToStringGeneral.tests.cpp:: passed: c == i for: 2 == 2 ToStringGeneral.tests.cpp:: passed: c == i for: 3 == 3 ToStringGeneral.tests.cpp:: passed: c == i for: 4 == 4 ToStringGeneral.tests.cpp:: passed: c == i for: 5 == 5 +Details.tests.cpp:: passed: Catch::throw_logic_error((Catch::ReusableStringStream() << ::Catch::SourceLineInfo( "projects//IntrospectiveTests/Details.tests.cpp", static_cast( 9 ) ) << ": Internal Catch2 error: " << "").str()), std::logic_error +Details.tests.cpp:: passed: Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()), std::domain_error +Details.tests.cpp:: passed: Catch::throw_runtime_error((Catch::ReusableStringStream() << "").str()), std::runtime_error +Details.tests.cpp:: passed: [](){do{ if( !(false) ) Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()); } while(false);}(), std::domain_error Tricky.tests.cpp:: passed: std::vector{constructor_throws{}, constructor_throws{}} Tricky.tests.cpp:: passed: std::vector{constructor_throws{}, constructor_throws{}} Tricky.tests.cpp:: passed: std::vector{1, 2, 3} == std::vector{1, 2, 3} diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 917ff6ff..d627e4e8 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1380,6 +1380,6 @@ due to unexpected exception with message: Why would you throw a std::string? =============================================================================== -test cases: 298 | 224 passed | 70 failed | 4 failed as expected -assertions: 1553 | 1401 passed | 131 failed | 21 failed as expected +test cases: 299 | 225 passed | 70 failed | 4 failed as expected +assertions: 1557 | 1405 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 73c23901..2bfd5580 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -2128,6 +2128,24 @@ ToStringGeneral.tests.cpp:: PASSED: with expansion: 5 == 5 +------------------------------------------------------------------------------- +Check that our error handling macros throw the right exceptions +------------------------------------------------------------------------------- +Details.tests.cpp: +............................................................................... + +Details.tests.cpp:: PASSED: + REQUIRE_THROWS_AS( Catch::throw_logic_error((Catch::ReusableStringStream() << ::Catch::SourceLineInfo( "projects//IntrospectiveTests/Details.tests.cpp", static_cast( 9 ) ) << ": Internal Catch2 error: " << "").str()), std::logic_error ) + +Details.tests.cpp:: PASSED: + REQUIRE_THROWS_AS( Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()), std::domain_error ) + +Details.tests.cpp:: PASSED: + REQUIRE_THROWS_AS( Catch::throw_runtime_error((Catch::ReusableStringStream() << "").str()), std::runtime_error ) + +Details.tests.cpp:: PASSED: + REQUIRE_THROWS_AS( [](){do{ if( !(false) ) Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()); } while(false);}(), std::domain_error ) + ------------------------------------------------------------------------------- Commas in various macros are allowed ------------------------------------------------------------------------------- @@ -12409,6 +12427,6 @@ Misc.tests.cpp: Misc.tests.cpp:: PASSED: =============================================================================== -test cases: 298 | 208 passed | 86 failed | 4 failed as expected -assertions: 1570 | 1401 passed | 148 failed | 21 failed as expected +test cases: 299 | 209 passed | 86 failed | 4 failed as expected +assertions: 1574 | 1405 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 2cd6081e..c512748c 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ - + @@ -241,6 +241,7 @@ Exception.tests.cpp: + diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 05875d0a..8e9f45b3 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -2438,6 +2438,41 @@ Nor would this + + + + Catch::throw_logic_error((Catch::ReusableStringStream() << ::Catch::SourceLineInfo( "projects//IntrospectiveTests/Details.tests.cpp", static_cast<std::size_t>( 9 ) ) << ": Internal Catch2 error: " << "").str()), std::logic_error + + + Catch::throw_logic_error((Catch::ReusableStringStream() << ::Catch::SourceLineInfo( "projects//IntrospectiveTests/Details.tests.cpp", static_cast<std::size_t>( 9 ) ) << ": Internal Catch2 error: " << "").str()), std::logic_error + + + + + Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()), std::domain_error + + + Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()), std::domain_error + + + + + Catch::throw_runtime_error((Catch::ReusableStringStream() << "").str()), std::runtime_error + + + Catch::throw_runtime_error((Catch::ReusableStringStream() << "").str()), std::runtime_error + + + + + [](){do{ if( !(false) ) Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()); } while(false);}(), std::domain_error + + + [](){do{ if( !(false) ) Catch::throw_domain_error((Catch::ReusableStringStream() << "").str()); } while(false);}(), std::domain_error + + + + @@ -14767,7 +14802,7 @@ loose text artifact - + - + diff --git a/projects/SelfTest/IntrospectiveTests/Details.tests.cpp b/projects/SelfTest/IntrospectiveTests/Details.tests.cpp new file mode 100644 index 00000000..289e5bb6 --- /dev/null +++ b/projects/SelfTest/IntrospectiveTests/Details.tests.cpp @@ -0,0 +1,23 @@ +/* + * 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.hpp" + +#if defined(_MSC_VER) +#pragma warning(push) +#pragma warning(disable:4702) // unreachable code in the macro expansions +#endif + +TEST_CASE("Check that our error handling macros throw the right exceptions", "[!throws][internals]") { + REQUIRE_THROWS_AS(CATCH_INTERNAL_ERROR(""), std::logic_error); + REQUIRE_THROWS_AS(CATCH_ERROR(""), std::domain_error); + REQUIRE_THROWS_AS(CATCH_RUNTIME_ERROR(""), std::runtime_error); + REQUIRE_THROWS_AS([](){CATCH_ENFORCE(false, "");}(), std::domain_error); + REQUIRE_NOTHROW([](){CATCH_ENFORCE(true, "");}()); +} + +#if defined(_MSC_VER) +#pragma warning(pop) // unreachable code in the macro expansions +#endif