1
0
mirror of https://github.com/catchorg/Catch2.git synced 2025-01-16 07:08:01 +00:00

Compare commits

...

9 Commits

Author SHA1 Message Date
Martin Hořeňovský
a39154e115
Do not explicitly default smfs if all of them are defaulted 2020-05-11 00:00:55 +02:00
Martin Hořeňovský
7c622a79d4
Unvirtual bunch off destructors of simple data classes 2020-05-10 23:57:05 +02:00
Martin Hořeňovský
04cbbb8a4b
Replace getLineOfChars with non-templated, runtime version 2020-05-10 23:52:38 +02:00
Martin Hořeňovský
f64487bf70
Move LazyExpr's and MessageInfo's implementation to the combined TU
Some of the implementations were inlined instead.
2020-05-10 20:21:04 +02:00
Martin Hořeňovský
27f1756d8e
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.
2020-05-10 20:21:02 +02:00
Martin Hořeňovský
824ffe6525
Inline and default LazyExpression's constructor 2020-05-10 20:20:59 +02:00
Martin Hořeňovský
d5e08a4beb
Rename catch_assertionhandler -> catch_assertion_handler 2020-05-10 20:20:56 +02:00
Martin Hořeňovský
ed967fd7fc
Split MessageInfo into its own header
This is first step towards splitting apart reporter implementation
and `catch_string.hpp`.
2020-05-10 20:20:52 +02:00
Martin Hořeňovský
7030d7740d
Remove some superfluous includes from reporters 2020-05-10 20:20:47 +02:00
23 changed files with 171 additions and 155 deletions

View File

@ -38,7 +38,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/matchers/internal/catch_matchers_impl.hpp
${SOURCES_DIR}/internal/catch_container_nonmembers.hpp
${SOURCES_DIR}/catch_approx.hpp
${SOURCES_DIR}/internal/catch_assertionhandler.hpp
${SOURCES_DIR}/internal/catch_assertion_handler.hpp
${SOURCES_DIR}/catch_assertion_info.hpp
${SOURCES_DIR}/catch_assertion_result.hpp
${SOURCES_DIR}/internal/catch_test_macro_impl.hpp
@ -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
@ -84,6 +85,7 @@ set(INTERNAL_HEADERS
${SOURCES_DIR}/matchers/catch_matchers_templated.hpp
${SOURCES_DIR}/matchers/catch_matchers_vector.hpp
${SOURCES_DIR}/catch_message.hpp
${SOURCES_DIR}/internal/catch_message_info.hpp
${SOURCES_DIR}/internal/catch_meta.hpp
${SOURCES_DIR}/internal/catch_option.hpp
${SOURCES_DIR}/internal/catch_output_redirect.hpp
@ -129,7 +131,7 @@ set(INTERNAL_HEADERS
)
set(IMPL_SOURCES
${SOURCES_DIR}/catch_approx.cpp
${SOURCES_DIR}/internal/catch_assertionhandler.cpp
${SOURCES_DIR}/internal/catch_assertion_handler.cpp
${SOURCES_DIR}/catch_assertion_result.cpp
${SOURCES_DIR}/matchers/internal/catch_matchers_combined_tu.cpp
${SOURCES_DIR}/internal/catch_commandline.cpp

View File

@ -37,7 +37,7 @@
#include <catch2/catch_version_macros.hpp>
#include <catch2/generators/catch_generators_all.hpp>
#include <catch2/interfaces/catch_interfaces_all.hpp>
#include <catch2/internal/catch_assertionhandler.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_clara.hpp>
#include <catch2/internal/catch_clara_upstream.hpp>
#include <catch2/internal/catch_commandline.hpp>
@ -54,8 +54,10 @@
#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>
#include <catch2/internal/catch_meta.hpp>
#include <catch2/internal/catch_option.hpp>
#include <catch2/internal/catch_output_redirect.hpp>

View File

@ -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) {}

View File

@ -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_assertionhandler.hpp>
#include <catch2/internal/catch_lazy_expr.hpp>
namespace Catch {

View File

@ -16,27 +16,6 @@
namespace Catch {
MessageInfo::MessageInfo( StringRef const& _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
: macroName( _macroName ),
lineInfo( _lineInfo ),
type( _type ),
sequence( ++globalCount )
{}
bool MessageInfo::operator==( MessageInfo const& other ) const {
return sequence == other.sequence;
}
bool MessageInfo::operator<( MessageInfo const& other ) const {
return sequence < other.sequence;
}
// This may need protecting if threading support is added
unsigned int MessageInfo::globalCount = 0;
////////////////////////////////////////////////////////////////////////////
Catch::MessageBuilder::MessageBuilder( StringRef const& macroName,

View File

@ -11,6 +11,7 @@
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_common.hpp>
#include <catch2/internal/catch_stream.hpp>
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/interfaces/catch_interfaces_capture.hpp>
#include <catch2/catch_tostring.hpp>
@ -19,23 +20,6 @@
namespace Catch {
struct MessageInfo {
MessageInfo( StringRef const& _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type );
StringRef macroName;
std::string message;
SourceLineInfo lineInfo;
ResultWas::OfType type;
unsigned int sequence;
bool operator == ( MessageInfo const& other ) const;
bool operator < ( MessageInfo const& other ) const;
private:
static unsigned int globalCount;
};
struct MessageStream {
template<typename T>

View File

@ -7,6 +7,7 @@
#include <catch2/interfaces/catch_interfaces_reporter.hpp>
#include <catch2/internal/catch_console_colour.hpp>
#include <catch2/catch_message.hpp>
#include <catch2/internal/catch_list.hpp>
#include <catch2/internal/catch_text.hpp>
#include <catch2/internal/catch_string_manip.hpp>
@ -56,8 +57,6 @@ namespace Catch {
}
}
AssertionStats::~AssertionStats() = default;
SectionStats::SectionStats( SectionInfo const& _sectionInfo,
Counts const& _assertions,
double _durationInSeconds,
@ -68,8 +67,6 @@ namespace Catch {
missingAssertions( _missingAssertions )
{}
SectionStats::~SectionStats() = default;
TestCaseStats::TestCaseStats( TestCaseInfo const& _testInfo,
Totals const& _totals,
@ -83,8 +80,6 @@ namespace Catch {
aborting( _aborting )
{}
TestCaseStats::~TestCaseStats() = default;
TestGroupStats::TestGroupStats( GroupInfo const& _groupInfo,
Totals const& _totals,
@ -99,7 +94,6 @@ namespace Catch {
aborting( false )
{}
TestGroupStats::~TestGroupStats() = default;
TestRunStats::TestRunStats( TestRunInfo const& _runInfo,
Totals const& _totals,
@ -109,8 +103,6 @@ namespace Catch {
aborting( _aborting )
{}
TestRunStats::~TestRunStats() = default;
void IStreamingReporter::fatalErrorEncountered( StringRef ) {}
void IStreamingReporter::listReporters(std::vector<ReporterDescription> const& descriptions, Config const& config) {

View File

@ -14,7 +14,7 @@
#include <catch2/catch_totals.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/catch_message.hpp>
#include <catch2/internal/catch_message_info.hpp>
#include <catch2/internal/catch_option.hpp>
#include <catch2/internal/catch_stringref.hpp>
@ -25,7 +25,6 @@
#include <string>
#include <iosfwd>
#include <map>
#include <set>
#include <memory>
#include <algorithm>
@ -89,7 +88,6 @@ namespace Catch {
AssertionStats( AssertionStats && ) = default;
AssertionStats& operator = ( AssertionStats const& ) = delete;
AssertionStats& operator = ( AssertionStats && ) = delete;
virtual ~AssertionStats();
AssertionResult assertionResult;
std::vector<MessageInfo> infoMessages;
@ -101,11 +99,6 @@ namespace Catch {
Counts const& _assertions,
double _durationInSeconds,
bool _missingAssertions );
SectionStats( SectionStats const& ) = default;
SectionStats( SectionStats && ) = default;
SectionStats& operator = ( SectionStats const& ) = default;
SectionStats& operator = ( SectionStats && ) = default;
virtual ~SectionStats();
SectionInfo sectionInfo;
Counts assertions;
@ -120,12 +113,6 @@ namespace Catch {
std::string const& _stdErr,
bool _aborting );
TestCaseStats( TestCaseStats const& ) = default;
TestCaseStats( TestCaseStats && ) = default;
TestCaseStats& operator = ( TestCaseStats const& ) = default;
TestCaseStats& operator = ( TestCaseStats && ) = default;
virtual ~TestCaseStats();
TestCaseInfo const * testInfo;
Totals totals;
std::string stdOut;
@ -139,12 +126,6 @@ namespace Catch {
bool _aborting );
TestGroupStats( GroupInfo const& _groupInfo );
TestGroupStats( TestGroupStats const& ) = default;
TestGroupStats( TestGroupStats && ) = default;
TestGroupStats& operator = ( TestGroupStats const& ) = default;
TestGroupStats& operator = ( TestGroupStats && ) = default;
virtual ~TestGroupStats();
GroupInfo groupInfo;
Totals totals;
bool aborting;
@ -155,12 +136,6 @@ namespace Catch {
Totals const& _totals,
bool _aborting );
TestRunStats( TestRunStats const& ) = default;
TestRunStats( TestRunStats && ) = default;
TestRunStats& operator = ( TestRunStats const& ) = default;
TestRunStats& operator = ( TestRunStats && ) = default;
virtual ~TestRunStats();
TestRunInfo runInfo;
Totals totals;
bool aborting;

View File

@ -6,7 +6,7 @@
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#include <catch2/internal/catch_assertionhandler.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/catch_assertion_result.hpp>
#include <catch2/interfaces/catch_interfaces_runner.hpp>
#include <catch2/interfaces/catch_interfaces_config.hpp>
@ -19,39 +19,6 @@
namespace Catch {
namespace {
auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
expr.streamReconstructedExpression( os );
return os;
}
}
LazyExpression::LazyExpression( bool isNegated )
: m_isNegated( isNegated )
{}
LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
LazyExpression::operator bool() const {
return m_transientExpression != nullptr;
}
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,

View File

@ -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,23 +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 );
LazyExpression( LazyExpression const& other );
LazyExpression& operator = ( LazyExpression const& ) = delete;
explicit operator bool() const;
friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
};
struct AssertionReaction {
bool shouldDebugBreak = false;
bool shouldThrow = false;

View File

@ -171,3 +171,54 @@ namespace Catch {
Catch::LeakDetector::~LeakDetector() {
Catch::cleanUp();
}
/////////////////////////////////////////////
// vvv formerly catch_message_info.cpp vvv //
/////////////////////////////////////////////
#include <catch2/internal/catch_message_info.hpp>
namespace Catch {
MessageInfo::MessageInfo( StringRef const& _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type )
: macroName( _macroName ),
lineInfo( _lineInfo ),
type( _type ),
sequence( ++globalCount )
{}
// This may need protecting if threading support is added
unsigned int MessageInfo::globalCount = 0;
} // end namespace Catch
//////////////////////////////////////////
// vvv formerly catch_lazy_expr.cpp vvv //
//////////////////////////////////////////
#include <catch2/internal/catch_lazy_expr.hpp>
#include <catch2/internal/catch_decomposer.hpp>
namespace Catch {
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

View File

@ -49,7 +49,10 @@ namespace Catch {
bool m_isBinaryExpression;
bool m_result;
friend std::ostream& operator<<(std::ostream& out, ITransientExpression const& expr) {
expr.streamReconstructedExpression(out);
return out;
}
};
void formatReconstructedExpression( std::ostream &os, std::string const& lhs, StringRef op, std::string const& rhs );

View File

@ -7,7 +7,7 @@
*/
#include <catch2/internal/catch_exception_translator_registry.hpp>
#include <catch2/internal/catch_assertionhandler.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/internal/catch_compiler_capabilities.hpp>
#include <catch2/internal/catch_enforce.hpp>

View 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

View File

@ -0,0 +1,35 @@
#ifndef CATCH_MESSAGE_INFO_HPP_INCLUDED
#define CATCH_MESSAGE_INFO_HPP_INCLUDED
#include <catch2/internal/catch_result_type.hpp>
#include <catch2/internal/catch_common.hpp>
#include <catch2/interfaces/catch_interfaces_capture.hpp>
#include <string>
namespace Catch {
struct MessageInfo {
MessageInfo( StringRef const& _macroName,
SourceLineInfo const& _lineInfo,
ResultWas::OfType _type );
StringRef macroName;
std::string message;
SourceLineInfo lineInfo;
ResultWas::OfType type;
unsigned int sequence;
bool operator == (MessageInfo const& other) const {
return sequence == other.sequence;
}
bool operator < (MessageInfo const& other) const {
return sequence < other.sequence;
}
private:
static unsigned int globalCount;
};
} // end namespace Catch
#endif // CATCH_MESSAGE_INFO_HPP_INCLUDED

View File

@ -16,10 +16,11 @@
#include <catch2/internal/catch_test_registry.hpp>
#include <catch2/catch_test_case_info.hpp>
#include <catch2/internal/catch_test_macro_impl.hpp>
#include <catch2/catch_message.hpp>
#include <catch2/catch_totals.hpp>
#include <catch2/catch_test_spec.hpp>
#include <catch2/internal/catch_test_case_tracker.hpp>
#include <catch2/internal/catch_assertionhandler.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <string>

View File

@ -8,7 +8,7 @@
#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
#include <catch2/internal/catch_assertionhandler.hpp>
#include <catch2/internal/catch_assertion_handler.hpp>
#include <catch2/interfaces/catch_interfaces_capture.hpp>
#include <catch2/internal/catch_stringref.hpp>

View File

@ -9,6 +9,8 @@
#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 <catch2/catch_config.hpp>
#include <cstring>
#include <cfloat>
@ -69,4 +71,12 @@ namespace Catch {
StreamingReporterBase::~StreamingReporterBase() = default;
CumulativeReporterBase::~CumulativeReporterBase() = default;
std::ostream& operator<<(std::ostream& out, lineOfChars value) {
for (size_t idx = 0; idx < CATCH_CONFIG_CONSOLE_WIDTH - 1; ++idx) {
out.put(value.c);
}
return out;
}
} // end namespace Catch

View File

@ -241,16 +241,14 @@ namespace Catch {
ReporterPreferences m_reporterPrefs;
};
template<char C>
char const* getLineOfChars() {
static char line[CATCH_CONFIG_CONSOLE_WIDTH] = {0};
if( !*line ) {
std::memset( line, C, CATCH_CONFIG_CONSOLE_WIDTH-1 );
line[CATCH_CONFIG_CONSOLE_WIDTH-1] = 0;
}
return line;
}
struct lineOfChars {
char c;
constexpr lineOfChars(char c):
c(c)
{}
friend std::ostream& operator<< (std::ostream& out, lineOfChars value);
};
struct TestEventListenerBase : StreamingReporterBase {
TestEventListenerBase( ReporterConfig const& _config );

View File

@ -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>
@ -299,7 +300,7 @@ public:
}
m_os << headerCols << '\n';
m_os << Catch::getLineOfChars<'-'>() << '\n';
m_os << lineOfChars('-') << '\n';
}
}
void close() {
@ -518,7 +519,7 @@ void ConsoleReporter::lazyPrintWithoutClosingBenchmarkTable() {
}
}
void ConsoleReporter::lazyPrintRunInfo() {
stream << '\n' << getLineOfChars<'~'>() << '\n';
stream << '\n' << lineOfChars('~') << '\n';
Colour colour(Colour::SecondaryText);
stream << currentTestRunInfo->name
<< " is a Catch v" << libraryVersion() << " host application.\n"
@ -552,18 +553,18 @@ void ConsoleReporter::printTestCaseAndSectionHeader() {
SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
stream << getLineOfChars<'-'>() << '\n';
stream << lineOfChars('-') << '\n';
Colour colourGuard(Colour::FileName);
stream << lineInfo << '\n';
stream << getLineOfChars<'.'>() << '\n' << std::endl;
stream << lineOfChars('.') << '\n' << std::endl;
}
void ConsoleReporter::printClosedHeader(std::string const& _name) {
printOpenHeader(_name);
stream << getLineOfChars<'.'>() << '\n';
stream << lineOfChars('.') << '\n';
}
void ConsoleReporter::printOpenHeader(std::string const& _name) {
stream << getLineOfChars<'-'>() << '\n';
stream << lineOfChars('-') << '\n';
{
Colour colourGuard(Colour::Headers);
printHeaderString(_name);
@ -675,7 +676,7 @@ void ConsoleReporter::printTotalsDivider(Totals const& totals) {
stream << '\n';
}
void ConsoleReporter::printSummaryDivider() {
stream << getLineOfChars<'-'>() << '\n';
stream << lineOfChars('-') << '\n';
}
void ConsoleReporter::printTestFilters() {

View File

@ -16,7 +16,6 @@
#include <catch2/internal/catch_text.hpp>
#include <cassert>
#include <sstream>
#include <ctime>
#include <algorithm>

View File

@ -22,7 +22,7 @@ namespace Catch {
i = 0;
os << Column(_string)
.indent(indent + i)
.initialIndent(indent) << "\n";
.initialIndent(indent) << '\n';
}
std::string escape(std::string const& str) {
@ -152,20 +152,20 @@ namespace Catch {
assert(!m_sectionStack.empty());
if (m_sectionStack.size() > 1) {
os << getLineOfChars<'-'>() << '\n';
os << lineOfChars('-') << '\n';
std::vector<SectionInfo>::const_iterator
it = m_sectionStack.begin() + 1, // Skip first section (test case)
itEnd = m_sectionStack.end();
for (; it != itEnd; ++it)
printHeaderString(os, it->name);
os << getLineOfChars<'-'>() << '\n';
os << lineOfChars('-') << '\n';
}
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
os << lineInfo << '\n';
os << getLineOfChars<'.'>() << "\n\n";
os << lineOfChars('.') << "\n\n";
}
} // end namespace Catch

View File

@ -8,9 +8,7 @@
#include <catch2/reporters/catch_reporter_xml.hpp>
#include <catch2/internal/catch_test_macro_impl.hpp>
#include <catch2/internal/catch_string_manip.hpp>
#include <catch2/catch_reporter_registrars.hpp>
#include <catch2/internal/catch_list.hpp>
#if defined(_MSC_VER)