diff --git a/include/internal/catch_assertionhandler.cpp b/include/internal/catch_assertionhandler.cpp index 8d99e3d0..26f727a9 100644 --- a/include/internal/catch_assertionhandler.cpp +++ b/include/internal/catch_assertionhandler.cpp @@ -13,6 +13,7 @@ #include "catch_context.h" #include "catch_debugger.h" #include "catch_interfaces_registry_hub.h" +#include "catch_matchers_string.h" #include @@ -140,5 +141,14 @@ namespace Catch { m_inExceptionGuard = false; } + using StringMatcher = Matchers::Impl::MatcherBase; + + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ) { + MatchExpr expr( Catch::translateActiveException(), matcher, matcherString ); + handler.handle( expr ); + } + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ) { + handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString ); + } } // namespace Catch diff --git a/include/internal/catch_assertionhandler.h b/include/internal/catch_assertionhandler.h index dbbd5157..21a09875 100644 --- a/include/internal/catch_assertionhandler.h +++ b/include/internal/catch_assertionhandler.h @@ -10,6 +10,7 @@ #include "catch_decomposer.h" #include "catch_assertioninfo.h" +#include "catch_matchers_string.h" // !TBD: for exception matchers namespace Catch { @@ -67,6 +68,11 @@ namespace Catch { void unsetExceptionGuard(); }; + using StringMatcher = Matchers::Impl::MatcherBase; + + void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef matcherString ); + void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef matcherString ); + } // namespace Catch #endif // TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp index ee63e044..6615edf1 100644 --- a/include/internal/catch_capture.hpp +++ b/include/internal/catch_capture.hpp @@ -159,18 +159,18 @@ /////////////////////////////////////////////////////////////////////////////// #define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \ do { \ - Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__ ", " #matcher, resultDisposition); \ - if( __catchResult.allowThrows() ) \ + Catch::AssertionHandler catchAssertionHandler( macroName, CATCH_INTERNAL_LINEINFO, #__VA_ARGS__ ", " #matcher, resultDisposition ); \ + if( catchAssertionHandler.allowThrows() ) \ try { \ static_cast(__VA_ARGS__); \ - __catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \ + catchAssertionHandler.handle( Catch::ResultWas::DidntThrowException ); \ } \ catch( ... ) { \ - __catchResult.captureExpectedException( matcher ); \ + handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher ); \ } \ else \ - __catchResult.captureResult( Catch::ResultWas::Ok ); \ - INTERNAL_CATCH_REACT( __catchResult ) \ + catchAssertionHandler.handle( Catch::ResultWas::Ok ); \ + INTERNAL_CATCH_REACT2( catchAssertionHandler ) \ } while( Catch::alwaysFalse() ) diff --git a/include/internal/catch_decomposer.cpp b/include/internal/catch_decomposer.cpp index 6e69bc43..f7da22b5 100644 --- a/include/internal/catch_decomposer.cpp +++ b/include/internal/catch_decomposer.cpp @@ -12,7 +12,6 @@ namespace Catch { void formatReconstructedExpression( std::ostream &os, std::string const& lhs, std::string const& op, std::string const& rhs ) { - if( lhs.size() + rhs.size() < 40 && lhs.find('\n') == std::string::npos && rhs.find('\n') == std::string::npos ) @@ -20,4 +19,4 @@ namespace Catch { else os << lhs << "\n" << op << "\n" << rhs; } -} \ No newline at end of file +} diff --git a/include/internal/catch_decomposer.h b/include/internal/catch_decomposer.h index f289387a..3182b84a 100644 --- a/include/internal/catch_decomposer.h +++ b/include/internal/catch_decomposer.h @@ -10,6 +10,7 @@ #include "catch_tostring.h" #include "catch_stringref.h" +#include "catch_matchers.hpp" // !TBD: for exception matchers - move this #include @@ -148,7 +149,7 @@ namespace Catch { template class MatchExpr : public ITransientExpression { ArgT const& m_arg; - MatcherT const& m_matcher; + MatcherT m_matcher; StringRef m_matcherString; bool m_result; public: @@ -171,6 +172,7 @@ namespace Catch { os << matcherAsString; } }; + template auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef matcherString ) -> MatchExpr { return MatchExpr( arg, matcher, matcherString ); diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 9e41f7f5..cd406b0c 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -485,7 +485,7 @@ ExceptionTests.cpp: ExceptionTests.cpp:: FAILED: REQUIRE_THROWS_WITH( thisThrows(), "should fail" ) with expansion: - expected exception + "expected exception" equals: "should fail" ------------------------------------------------------------------------------- Nice descriptive name diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 971c0e32..80fd38c9 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -1428,6 +1428,8 @@ ExceptionTests.cpp: ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), "expected exception" ) +with expansion: + "expected exception" equals: "expected exception" ------------------------------------------------------------------------------- Exception messages can be tested for @@ -1439,6 +1441,8 @@ ExceptionTests.cpp: ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) ) +with expansion: + "expected exception" equals: "expected exception" (case insensitive) ------------------------------------------------------------------------------- Exception messages can be tested for @@ -1450,18 +1454,26 @@ ExceptionTests.cpp: ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), StartsWith( "expected" ) ) +with expansion: + "expected exception" starts with: "expected" ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), EndsWith( "exception" ) ) +with expansion: + "expected exception" ends with: "exception" ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), Contains( "except" ) ) +with expansion: + "expected exception" contains: "except" ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) ) +with expansion: + "expected exception" contains: "except" (case insensitive) ------------------------------------------------------------------------------- Expected exceptions that don't throw or unexpected exceptions fail the test @@ -1882,11 +1894,13 @@ ExceptionTests.cpp: ExceptionTests.cpp:: PASSED: REQUIRE_THROWS_WITH( thisThrows(), "expected exception" ) +with expansion: + "expected exception" equals: "expected exception" ExceptionTests.cpp:: FAILED: REQUIRE_THROWS_WITH( thisThrows(), "should fail" ) with expansion: - expected exception + "expected exception" equals: "should fail" ------------------------------------------------------------------------------- Nice descriptive name diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 58807c18..3a1ebdab 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -311,7 +311,7 @@ MatchersTests.cpp: - + ExceptionTests.cpp: diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index e70ad12e..9cec8235 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -1646,7 +1646,7 @@ thisThrows(), "expected exception" - thisThrows(), "expected exception" + "expected exception" equals: "expected exception" @@ -1657,7 +1657,7 @@ thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) - thisThrows(), Equals( "expecteD Exception", Catch::CaseSensitive::No ) + "expected exception" equals: "expected exception" (case insensitive) @@ -1668,7 +1668,7 @@ thisThrows(), StartsWith( "expected" ) - thisThrows(), StartsWith( "expected" ) + "expected exception" starts with: "expected" @@ -1676,7 +1676,7 @@ thisThrows(), EndsWith( "exception" ) - thisThrows(), EndsWith( "exception" ) + "expected exception" ends with: "exception" @@ -1684,7 +1684,7 @@ thisThrows(), Contains( "except" ) - thisThrows(), Contains( "except" ) + "expected exception" contains: "except" @@ -1692,7 +1692,7 @@ thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) - thisThrows(), Contains( "exCept", Catch::CaseSensitive::No ) + "expected exception" contains: "except" (case insensitive) @@ -2172,7 +2172,7 @@ thisThrows(), "expected exception" - thisThrows(), "expected exception" + "expected exception" equals: "expected exception" @@ -2180,7 +2180,7 @@ thisThrows(), "should fail" - expected exception + "expected exception" equals: "should fail"