mirror of
https://github.com/catchorg/Catch2.git
synced 2024-12-23 03:43:28 +01:00
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.
This commit is contained in:
parent
824ffe6525
commit
27f1756d8e
@ -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
|
||||
|
@ -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>
|
||||
|
@ -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) {}
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
30
src/catch2/internal/catch_lazy_expr.cpp
Normal file
30
src/catch2/internal/catch_lazy_expr.cpp
Normal file
@ -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
|
33
src/catch2/internal/catch_lazy_expr.hpp
Normal file
33
src/catch2/internal/catch_lazy_expr.hpp
Normal file
@ -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
|
@ -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>
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user