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

summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorMartin Hořeňovský2020-05-10 19:19:42 +0200
committerMartin Hořeňovský2020-05-10 20:21:02 +0200
commit27f1756d8e7d2a59832cac83f3219c9ebd286abf (patch)
tree17c4e4c0e4c737ba0f64e7c77a323883c1aca497
parent824ffe6525dbb9f27cd4a6cfeac54a6971a67a3e (diff)
downloadcatch3-27f1756d8e7d2a59832cac83f3219c9ebd286abf.tar.gz
Split out LazyExpr into its own header
This enables us to avoid `catch_reporter_bases.hpp` being indirectly dependent on `catch_tostring.hpp`, cutting apart quite a bit indirect inclusions.
-rw-r--r--src/CMakeLists.txt2
-rw-r--r--src/catch2/catch_all.hpp1
-rw-r--r--src/catch2/catch_assertion_result.cpp2
-rw-r--r--src/catch2/catch_assertion_result.hpp2
-rw-r--r--src/catch2/internal/catch_assertion_handler.cpp23
-rw-r--r--src/catch2/internal/catch_assertion_handler.hpp22
-rw-r--r--src/catch2/internal/catch_lazy_expr.cpp30
-rw-r--r--src/catch2/internal/catch_lazy_expr.hpp33
-rw-r--r--src/catch2/reporters/catch_reporter_bases.cpp1
-rw-r--r--src/catch2/reporters/catch_reporter_console.cpp1
10 files changed, 72 insertions, 45 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 41d93ae0..a8d7799d 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -72,6 +72,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/interfaces/catch_interfaces_runner.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_tag_alias_registry.hpp
${SOURCES_DIR}/interfaces/catch_interfaces_testcase.hpp
+ ${SOURCES_DIR}/internal/catch_lazy_expr.hpp
${SOURCES_DIR}/internal/catch_leak_detector.hpp
${SOURCES_DIR}/internal/catch_list.hpp
${SOURCES_DIR}/matchers/catch_matchers.hpp
@@ -147,6 +148,7 @@ set(IMPL_SOURCES
${SOURCES_DIR}/generators/internal/catch_generators_combined_tu.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_combined_tu.cpp
${SOURCES_DIR}/interfaces/catch_interfaces_reporter.cpp
+ ${SOURCES_DIR}/internal/catch_lazy_expr.cpp
${SOURCES_DIR}/internal/catch_list.cpp
${SOURCES_DIR}/matchers/catch_matchers_floating.cpp
${SOURCES_DIR}/matchers/catch_matchers_string.cpp
diff --git a/src/catch2/catch_all.hpp b/src/catch2/catch_all.hpp
index 3920e822..019c1bfe 100644
--- a/src/catch2/catch_all.hpp
+++ b/src/catch2/catch_all.hpp
@@ -54,6 +54,7 @@
#include <catch2/internal/catch_errno_guard.hpp>
#include <catch2/internal/catch_exception_translator_registry.hpp>
#include <catch2/internal/catch_fatal_condition_handler.hpp>
+#include <catch2/internal/catch_lazy_expr.hpp>
#include <catch2/internal/catch_leak_detector.hpp>
#include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_message_info.hpp>
diff --git a/src/catch2/catch_assertion_result.cpp b/src/catch2/catch_assertion_result.cpp
index 4bbf0416..84bb94c9 100644
--- a/src/catch2/catch_assertion_result.cpp
+++ b/src/catch2/catch_assertion_result.cpp
@@ -7,8 +7,10 @@
*/
#include <catch2/catch_assertion_result.hpp>
+#include <catch2/internal/catch_stream.hpp>
namespace Catch {
+
AssertionResultData::AssertionResultData(ResultWas::OfType _resultType, LazyExpression const & _lazyExpression):
lazyExpression(_lazyExpression),
resultType(_resultType) {}
diff --git a/src/catch2/catch_assertion_result.hpp b/src/catch2/catch_assertion_result.hpp
index 56b3d1cb..b39e71f7 100644
--- a/src/catch2/catch_assertion_result.hpp
+++ b/src/catch2/catch_assertion_result.hpp
@@ -13,7 +13,7 @@
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_stringref.hpp>
-#include <catch2/internal/catch_assertion_handler.hpp>
+#include <catch2/internal/catch_lazy_expr.hpp>
namespace Catch {
diff --git a/src/catch2/internal/catch_assertion_handler.cpp b/src/catch2/internal/catch_assertion_handler.cpp
index 14036062..54153462 100644
--- a/src/catch2/internal/catch_assertion_handler.cpp
+++ b/src/catch2/internal/catch_assertion_handler.cpp
@@ -19,29 +19,6 @@
namespace Catch {
- namespace {
- auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
- expr.streamReconstructedExpression( os );
- return os;
- }
- }
-
- 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 const& macroName,
SourceLineInfo const& lineInfo,
diff --git a/src/catch2/internal/catch_assertion_handler.hpp b/src/catch2/internal/catch_assertion_handler.hpp
index 646f12f4..df687f5d 100644
--- a/src/catch2/internal/catch_assertion_handler.hpp
+++ b/src/catch2/internal/catch_assertion_handler.hpp
@@ -11,6 +11,7 @@
#include <catch2/catch_assertion_info.hpp>
#include <catch2/internal/catch_decomposer.hpp>
#include <catch2/interfaces/catch_interfaces_capture.hpp>
+#include <catch2/internal/catch_lazy_expr.hpp>
namespace Catch {
@@ -19,27 +20,6 @@ namespace Catch {
struct IResultCapture;
class RunContext;
- class LazyExpression {
- friend class AssertionHandler;
- friend struct AssertionStats;
- friend class RunContext;
-
- ITransientExpression const* m_transientExpression = nullptr;
- bool m_isNegated;
- public:
- LazyExpression( bool isNegated ):
- m_isNegated(isNegated)
- {}
- LazyExpression(LazyExpression const& other) = default;
- LazyExpression& operator = ( LazyExpression const& ) = delete;
-
- explicit operator bool() const {
- return m_transientExpression != nullptr;
- }
-
- friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
- };
-
struct AssertionReaction {
bool shouldDebugBreak = false;
bool shouldThrow = false;
diff --git a/src/catch2/internal/catch_lazy_expr.cpp b/src/catch2/internal/catch_lazy_expr.cpp
new file mode 100644
index 00000000..21a33cdc
--- /dev/null
+++ b/src/catch2/internal/catch_lazy_expr.cpp
@@ -0,0 +1,30 @@
+#include <catch2/internal/catch_lazy_expr.hpp>
+
+#include <catch2/internal/catch_decomposer.hpp>
+
+
+namespace Catch {
+
+ namespace {
+ auto operator <<(std::ostream& os, ITransientExpression const& expr) -> std::ostream& {
+ expr.streamReconstructedExpression(os);
+ return os;
+ }
+ }
+
+ 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;
+ }
+
+} // namespace Catch
diff --git a/src/catch2/internal/catch_lazy_expr.hpp b/src/catch2/internal/catch_lazy_expr.hpp
new file mode 100644
index 00000000..8efc24fc
--- /dev/null
+++ b/src/catch2/internal/catch_lazy_expr.hpp
@@ -0,0 +1,33 @@
+#ifndef CATCH_LAZY_EXPR_HPP_INCLUDED
+#define CATCH_LAZY_EXPR_HPP_INCLUDED
+
+#include <iosfwd>
+
+namespace Catch {
+
+ struct ITransientExpression;
+
+ class LazyExpression {
+ friend class AssertionHandler;
+ friend struct AssertionStats;
+ friend class RunContext;
+
+ ITransientExpression const* m_transientExpression = nullptr;
+ bool m_isNegated;
+ public:
+ LazyExpression( bool isNegated ):
+ m_isNegated(isNegated)
+ {}
+ LazyExpression(LazyExpression const& other) = default;
+ LazyExpression& operator = ( LazyExpression const& ) = delete;
+
+ explicit operator bool() const {
+ return m_transientExpression != nullptr;
+ }
+
+ friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
+ };
+
+} // namespace Catch
+
+#endif // CATCH_LAZY_EXPR_HPP_INCLUDED
diff --git a/src/catch2/reporters/catch_reporter_bases.cpp b/src/catch2/reporters/catch_reporter_bases.cpp
index de302d18..f0343a19 100644
--- a/src/catch2/reporters/catch_reporter_bases.cpp
+++ b/src/catch2/reporters/catch_reporter_bases.cpp
@@ -9,6 +9,7 @@
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/internal/catch_errno_guard.hpp>
#include <catch2/reporters/catch_reporter_bases.hpp>
+#include <catch2/internal/catch_stream.hpp>
#include <cstring>
#include <cfloat>
diff --git a/src/catch2/reporters/catch_reporter_console.cpp b/src/catch2/reporters/catch_reporter_console.cpp
index cb38318b..e9bea0ee 100644
--- a/src/catch2/reporters/catch_reporter_console.cpp
+++ b/src/catch2/reporters/catch_reporter_console.cpp
@@ -13,6 +13,7 @@
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/catch_version.hpp>
#include <catch2/internal/catch_text.hpp>
+#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_stringref.hpp>
#include <cfloat>