Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include/internal
diff options
context:
space:
mode:
authorMartin Hořeňovský2017-03-29 21:12:06 +0200
committerMartin Hořeňovský2017-03-29 21:12:06 +0200
commit4fe2432e0512bfb735cebe04fdec8f93637c77ff (patch)
treed475901cf859a04f619cbafade81082040caba39 /include/internal
parentc3a41e26a7cc76a297990e66fe4bed7f5788a7a3 (diff)
downloadcatch3-4fe2432e0512bfb735cebe04fdec8f93637c77ff.tar.gz
Rework of REQUIRE* changes in CATCH_CONFIG_FAST_COMPILE
`ResultBuilder`s destructor now checks for exceptions, preventing false negatives. The speedup should remain the same give or take a tiny bit.
Diffstat (limited to 'include/internal')
-rw-r--r--include/internal/catch_capture.hpp7
-rw-r--r--include/internal/catch_result_builder.h5
-rw-r--r--include/internal/catch_result_builder.hpp18
3 files changed, 27 insertions, 3 deletions
diff --git a/include/internal/catch_capture.hpp b/include/internal/catch_capture.hpp
index 87f78f4e..58993718 100644
--- a/include/internal/catch_capture.hpp
+++ b/include/internal/catch_capture.hpp
@@ -34,9 +34,11 @@
#define INTERNAL_CATCH_TEST_NO_TRY( macroName, resultDisposition, expr ) \
do { \
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #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 &&.
@@ -44,8 +46,9 @@
#define INTERNAL_CHECK_THAT_NO_TRY( macroName, matcher, resultDisposition, arg ) \
do { \
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \
- __catchResult.captureMatch( arg, matcher, #matcher ); \
- __catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
+ __catchResult.setExceptionGuard(); \
+ __catchResult.captureMatch( arg, matcher, #matcher ); \
+ __catchResult.unsetExceptionGuard(); \
INTERNAL_CATCH_REACT( __catchResult ) \
} while( Catch::alwaysFalse() )
diff --git a/include/internal/catch_result_builder.h b/include/internal/catch_result_builder.h
index 305c21e6..82494566 100644
--- a/include/internal/catch_result_builder.h
+++ b/include/internal/catch_result_builder.h
@@ -39,6 +39,7 @@ namespace Catch {
char const* capturedExpression,
ResultDisposition::Flags resultDisposition,
char const* secondArg = "" );
+ ~ResultBuilder();
template<typename T>
ExpressionLhs<T const&> operator <= ( T const& operand );
@@ -73,6 +74,9 @@ namespace Catch {
template<typename ArgT, typename MatcherT>
void captureMatch( ArgT const& arg, MatcherT const& matcher, char const* matcherString );
+ void setExceptionGuard();
+ void unsetExceptionGuard();
+
private:
AssertionInfo m_assertionInfo;
AssertionResultData m_data;
@@ -80,6 +84,7 @@ namespace Catch {
bool m_shouldDebugBreak;
bool m_shouldThrow;
+ bool m_guardException;
};
} // namespace Catch
diff --git a/include/internal/catch_result_builder.hpp b/include/internal/catch_result_builder.hpp
index aaa37a8a..7e671087 100644
--- a/include/internal/catch_result_builder.hpp
+++ b/include/internal/catch_result_builder.hpp
@@ -30,9 +30,18 @@ namespace Catch {
char const* secondArg )
: m_assertionInfo( macroName, lineInfo, capturedExpressionWithSecondArgument( capturedExpression, secondArg ), resultDisposition ),
m_shouldDebugBreak( false ),
- m_shouldThrow( false )
+ m_shouldThrow( false ),
+ m_guardException( false )
{}
+ ResultBuilder::~ResultBuilder() {
+#if defined(CATCH_CONFIG_FAST_COMPILE)
+ if ( m_guardException ) {
+ useActiveException( m_assertionInfo.resultDisposition );
+ }
+#endif
+ }
+
ResultBuilder& ResultBuilder::setResultType( ResultWas::OfType result ) {
m_data.resultType = result;
return *this;
@@ -146,6 +155,13 @@ namespace Catch {
dest = m_assertionInfo.capturedExpression;
}
+ void ResultBuilder::setExceptionGuard() {
+ m_guardException = true;
+ }
+ void ResultBuilder::unsetExceptionGuard() {
+ m_guardException = false;
+ }
+
} // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RESULT_BUILDER_HPP_INCLUDED