mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Console reporter is now the default
This commit is contained in:
parent
f4c0a1848d
commit
bcad093af7
2
README
2
README
@ -1,4 +1,4 @@
|
||||
CATCH v0.9 build 9 (integration branch)
|
||||
CATCH v0.9 build 10 (integration branch)
|
||||
---------------------------------------------
|
||||
|
||||
CATCH is an automated test framework for C, C++ and Objective-C.
|
||||
|
@ -95,7 +95,7 @@ namespace Catch {
|
||||
}
|
||||
void makeReporter() {
|
||||
std::string reporterName = m_config.reporter.empty()
|
||||
? "basic"
|
||||
? "console"
|
||||
: m_config.reporter;
|
||||
|
||||
ReporterConfig reporterConfig( m_configWrapper.stream(), m_config );
|
||||
|
@ -13,7 +13,7 @@
|
||||
namespace Catch {
|
||||
|
||||
// These numbers are maintained by a script
|
||||
Version libraryVersion( 0, 9, 9, "integration" );
|
||||
Version libraryVersion( 0, 9, 10, "integration" );
|
||||
}
|
||||
|
||||
#endif // TWOBLUECUBES_CATCH_VERSION_HPP_INCLUDED
|
||||
|
@ -35,36 +35,17 @@ namespace Catch {
|
||||
}
|
||||
void lazyPrintGroupInfo() {
|
||||
if( !unusedGroupInfo->name.empty() )
|
||||
// stream << "[Group: '" << unusedGroupInfo->name << "']" << std::endl;
|
||||
stream << "[Started group: '" << unusedGroupInfo->name << "']" << std::endl;
|
||||
stream << "[Group: '" << unusedGroupInfo->name << "']" << std::endl;
|
||||
// stream << "[Started group: '" << unusedGroupInfo->name << "']" << std::endl;
|
||||
unusedGroupInfo.reset();
|
||||
}
|
||||
void lazyPrintTestCaseInfo() {
|
||||
// stream << "[Test case: '" << unusedTestCaseInfo->name << "']" << std::endl;
|
||||
stream << "[Running: " << unusedTestCaseInfo->name << "]" << std::endl;
|
||||
stream << "[Test case: '" << unusedTestCaseInfo->name << "']" << std::endl;
|
||||
// stream << "[Running: " << unusedTestCaseInfo->name << "]" << std::endl;
|
||||
unusedTestCaseInfo.reset();
|
||||
}
|
||||
std::string makeSectionPath( ThreadedSectionInfo const * section, std::string const& delimiter ) {
|
||||
std::string sectionPath = "'" + section->name + "'";
|
||||
|
||||
// !TBD: Do this without the assignment in the while as it causes warnings:
|
||||
while( ( section = section->parent.get() ) )
|
||||
sectionPath = "'" + section->name + "'" + delimiter + sectionPath;
|
||||
return sectionPath;
|
||||
}
|
||||
void lazyPrintSectionInfo() {
|
||||
// !TBD use printed flag
|
||||
ThreadedSectionInfo* section = unusedSectionInfo.get();
|
||||
|
||||
std::string sectionPath = makeSectionPath( section, ", " );
|
||||
if( sectionPath.size() > 60 )
|
||||
sectionPath = makeSectionPath( section, ",\n " );
|
||||
|
||||
stream << "[Section: " << sectionPath << "]" << std::endl;
|
||||
unusedSectionInfo.reset();
|
||||
}
|
||||
|
||||
void lazyPrintSectionInfoLegacy() {
|
||||
std::vector<ThreadedSectionInfo*> sections;
|
||||
for( ThreadedSectionInfo* section = unusedSectionInfo.get();
|
||||
section && !section->printed;
|
||||
@ -73,7 +54,8 @@ namespace Catch {
|
||||
|
||||
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
||||
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it ) {
|
||||
stream << "[Started section: " << "'" + (*it)->name + "'" << "]" << std::endl;
|
||||
// stream << "[Started section: " << "'" + (*it)->name + "'" << "]" << std::endl;
|
||||
stream << "[Section: " << "'" + (*it)->name + "'" << "]" << std::endl;
|
||||
(*it)->printed = true;
|
||||
}
|
||||
unusedSectionInfo.reset();
|
||||
@ -86,7 +68,7 @@ namespace Catch {
|
||||
if( unusedTestCaseInfo )
|
||||
lazyPrintTestCaseInfo();
|
||||
if( currentSectionInfo && !currentSectionInfo->printed )
|
||||
lazyPrintSectionInfoLegacy(); // !TBD
|
||||
lazyPrintSectionInfo();
|
||||
}
|
||||
|
||||
virtual void assertionStarting( AssertionInfo const& ) {
|
||||
@ -248,8 +230,8 @@ namespace Catch {
|
||||
stream << "\nNo assertions in section, '" << _sectionStats->sectionInfo.name << "'\n" << std::endl;
|
||||
}
|
||||
if( currentSectionInfo && currentSectionInfo->printed ) {
|
||||
// stream << "[Summary for section '" << _sectionStats->sectionInfo.name << "': ";
|
||||
stream << "[End of section: '" << _sectionStats->sectionInfo.name << "' ";
|
||||
stream << "[Summary for section '" << _sectionStats->sectionInfo.name << "': ";
|
||||
// stream << "[End of section: '" << _sectionStats->sectionInfo.name << "' ";
|
||||
Counts const& assertions = _sectionStats->assertions;
|
||||
if( assertions.failed ) {
|
||||
TextColour colour( TextColour::ResultError );
|
||||
@ -271,8 +253,8 @@ namespace Catch {
|
||||
stream << "\nNo assertions in test case, '" << _testCaseStats->testInfo.name << "'\n" << std::endl;
|
||||
}
|
||||
if( !unusedTestCaseInfo ) {
|
||||
// stream << "[Summary for test case '" << _testCaseStats->testInfo.name << "': ";
|
||||
stream << "[Finished: '" << _testCaseStats->testInfo.name << "' ";
|
||||
stream << "[Summary for test case '" << _testCaseStats->testInfo.name << "': ";
|
||||
// stream << "[Finished: '" << _testCaseStats->testInfo.name << "' ";
|
||||
printTotals( _testCaseStats->totals );
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
@ -280,8 +262,8 @@ namespace Catch {
|
||||
}
|
||||
virtual void testGroupEnded( Ptr<TestGroupStats const> const& _testGroupStats ) {
|
||||
if( !unusedGroupInfo ) {
|
||||
// stream << "[Summary for group '" << _testGroupStats->groupInfo.name << "': ";
|
||||
stream << "[End of group '" << _testGroupStats->groupInfo.name << "'. ";
|
||||
stream << "[Summary for group '" << _testGroupStats->groupInfo.name << "': ";
|
||||
// stream << "[End of group '" << _testGroupStats->groupInfo.name << "'. ";
|
||||
printTotals( _testGroupStats->totals );
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
@ -289,8 +271,8 @@ namespace Catch {
|
||||
}
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& _testRunStats ) {
|
||||
if( !unusedTestCaseInfo ) {
|
||||
// stream << "[Summary for '" << _testRunStats->runInfo.name << "': ";
|
||||
stream << "[Testing completed. ";
|
||||
stream << "[Summary for '" << _testRunStats->runInfo.name << "': ";
|
||||
// stream << "[Testing completed. ";
|
||||
printTotals( _testRunStats->totals );
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -165,10 +165,10 @@ TEST_CASE( "selftest/parser/2", "ConfigData" ) {
|
||||
|
||||
SECTION( "reporter", "" ) {
|
||||
SECTION( "-r/basic", "" ) {
|
||||
const char* argv[] = { "test", "-r", "basic" };
|
||||
const char* argv[] = { "test", "-r", "console" };
|
||||
CHECK_NOTHROW( parseIntoConfig( argv, config ) );
|
||||
|
||||
REQUIRE( config.reporter == "basic" );
|
||||
REQUIRE( config.reporter == "console" );
|
||||
}
|
||||
SECTION( "-r/xml", "" ) {
|
||||
const char* argv[] = { "test", "-r", "xml" };
|
||||
|
@ -53,7 +53,7 @@ namespace Catch {
|
||||
EmbeddedRunner() : m_reporter( new NullStreamingReporter() ) {}
|
||||
|
||||
Totals runMatching( const std::string& rawTestSpec,
|
||||
const std::string& reporter = "basic" );
|
||||
const std::string& reporter = "console" );
|
||||
|
||||
private:
|
||||
Ptr<IStreamingReporter> m_reporter;
|
||||
|
@ -1,6 +1,6 @@
|
||||
/*
|
||||
* CATCH v0.9 build 9 (integration branch)
|
||||
* Generated: 2012-12-06 08:42:33.813351
|
||||
* CATCH v0.9 build 10 (integration branch)
|
||||
* Generated: 2012-12-10 08:54:04.228540
|
||||
* ----------------------------------------------------------
|
||||
* This file has been merged from multiple headers. Please don't edit it directly
|
||||
* Copyright (c) 2012 Two Blue Cubes Ltd. All rights reserved.
|
||||
@ -1990,12 +1990,14 @@ namespace Catch
|
||||
struct ThreadedSectionInfo : SectionInfo, SharedImpl<> {
|
||||
ThreadedSectionInfo( SectionInfo const& _sectionInfo, Ptr<ThreadedSectionInfo> const& _parent = Ptr<ThreadedSectionInfo>() )
|
||||
: SectionInfo( _sectionInfo ),
|
||||
parent( _parent )
|
||||
parent( _parent ),
|
||||
printed( false )
|
||||
{}
|
||||
virtual ~ThreadedSectionInfo();
|
||||
|
||||
std::vector<Ptr<ThreadedSectionInfo> > children;
|
||||
Ptr<ThreadedSectionInfo> parent;
|
||||
bool printed;
|
||||
};
|
||||
|
||||
struct AssertionStats : SharedImpl<> {
|
||||
@ -2110,7 +2112,8 @@ namespace Catch
|
||||
struct AccumulatingReporter : SharedImpl<IStreamingReporter> {
|
||||
|
||||
AccumulatingReporter( ReporterConfig const& _config )
|
||||
: stream( _config.stream() )
|
||||
: m_config( _config ),
|
||||
stream( _config.stream() )
|
||||
{}
|
||||
|
||||
virtual ~AccumulatingReporter();
|
||||
@ -2151,6 +2154,7 @@ namespace Catch
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& /* _testRunStats */ ) {
|
||||
}
|
||||
|
||||
ReporterConfig m_config;
|
||||
Option<TestRunInfo> testRunInfo;
|
||||
Option<GroupInfo> unusedGroupInfo;
|
||||
Option<TestCaseInfo> unusedTestCaseInfo;
|
||||
@ -4595,7 +4599,7 @@ namespace Catch {
|
||||
}
|
||||
void makeReporter() {
|
||||
std::string reporterName = m_config.reporter.empty()
|
||||
? "basic"
|
||||
? "console"
|
||||
: m_config.reporter;
|
||||
|
||||
ReporterConfig reporterConfig( m_configWrapper.stream(), m_config );
|
||||
@ -5706,7 +5710,7 @@ namespace Catch {
|
||||
namespace Catch {
|
||||
|
||||
// These numbers are maintained by a script
|
||||
Version libraryVersion( 0, 9, 9, "integration" );
|
||||
Version libraryVersion( 0, 9, 10, "integration" );
|
||||
}
|
||||
|
||||
// #included from: ../reporters/catch_reporter_basic.hpp
|
||||
@ -6710,26 +6714,28 @@ namespace Catch {
|
||||
void lazyPrintGroupInfo() {
|
||||
if( !unusedGroupInfo->name.empty() )
|
||||
stream << "[Group: '" << unusedGroupInfo->name << "']" << std::endl;
|
||||
// stream << "[Started group: '" << unusedGroupInfo->name << "']" << std::endl;
|
||||
unusedGroupInfo.reset();
|
||||
}
|
||||
void lazyPrintTestCaseInfo() {
|
||||
stream << "[Test case: '" << unusedTestCaseInfo->name << "']" << std::endl;
|
||||
// stream << "[Running: " << unusedTestCaseInfo->name << "]" << std::endl;
|
||||
unusedTestCaseInfo.reset();
|
||||
}
|
||||
std::string makeSectionPath( ThreadedSectionInfo const * section, std::string const& delimiter ) {
|
||||
std::string sectionPath = "'" + section->name + "'";
|
||||
while( ( section = section->parent.get() ) )
|
||||
sectionPath = "'" + section->name + "'" + delimiter + sectionPath;
|
||||
return sectionPath;
|
||||
}
|
||||
|
||||
void lazyPrintSectionInfo() {
|
||||
ThreadedSectionInfo* section = unusedSectionInfo.get();
|
||||
std::vector<ThreadedSectionInfo*> sections;
|
||||
for( ThreadedSectionInfo* section = unusedSectionInfo.get();
|
||||
section && !section->printed;
|
||||
section = section->parent.get() )
|
||||
sections.push_back( section );
|
||||
|
||||
std::string sectionPath = makeSectionPath( section, ", " );
|
||||
if( sectionPath.size() > 60 )
|
||||
sectionPath = makeSectionPath( section, ",\n " );
|
||||
|
||||
stream << "[Section: " << sectionPath << "]" << std::endl;
|
||||
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
|
||||
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it ) {
|
||||
// stream << "[Started section: " << "'" + (*it)->name + "'" << "]" << std::endl;
|
||||
stream << "[Section: " << "'" + (*it)->name + "'" << "]" << std::endl;
|
||||
(*it)->printed = true;
|
||||
}
|
||||
unusedSectionInfo.reset();
|
||||
}
|
||||
void lazyPrint() {
|
||||
@ -6739,15 +6745,132 @@ namespace Catch {
|
||||
lazyPrintGroupInfo();
|
||||
if( unusedTestCaseInfo )
|
||||
lazyPrintTestCaseInfo();
|
||||
if( unusedSectionInfo )
|
||||
if( currentSectionInfo && !currentSectionInfo->printed )
|
||||
lazyPrintSectionInfo();
|
||||
}
|
||||
|
||||
virtual void assertionStarting( AssertionInfo const& _assertionInfo ) {
|
||||
virtual void assertionStarting( AssertionInfo const& ) {
|
||||
}
|
||||
virtual void assertionEnded( Ptr<AssertionStats const> const& _assertionStats ) {
|
||||
if( !_assertionStats->assertionResult.isOk() )
|
||||
lazyPrint();
|
||||
|
||||
AssertionResult const& result = _assertionStats->assertionResult;
|
||||
|
||||
// Drop out if result was successful and we're not printing those
|
||||
if( !m_config.includeSuccessfulResults() && result.isOk() )
|
||||
return;
|
||||
|
||||
lazyPrint();
|
||||
|
||||
if( !result.getSourceInfo().empty() ) {
|
||||
TextColour colour( TextColour::FileName );
|
||||
stream << result.getSourceInfo();
|
||||
}
|
||||
|
||||
if( result.hasExpression() ) {
|
||||
TextColour colour( TextColour::OriginalExpression );
|
||||
stream << result.getExpression();
|
||||
if( result.succeeded() ) {
|
||||
TextColour successColour( TextColour::Success );
|
||||
stream << " succeeded";
|
||||
}
|
||||
else {
|
||||
TextColour errorColour( TextColour::Error );
|
||||
stream << " failed";
|
||||
if( result.isOk() ) {
|
||||
TextColour okAnywayColour( TextColour::Success );
|
||||
stream << " - but was ok";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
switch( result.getResultType() ) {
|
||||
case ResultWas::ThrewException:
|
||||
{
|
||||
TextColour colour( TextColour::Error );
|
||||
if( result.hasExpression() )
|
||||
stream << " with unexpected";
|
||||
else
|
||||
stream << "Unexpected";
|
||||
stream << " exception with message: '" << result.getMessage() << "'";
|
||||
}
|
||||
break;
|
||||
case ResultWas::DidntThrowException:
|
||||
{
|
||||
TextColour colour( TextColour::Error );
|
||||
if( result.hasExpression() )
|
||||
stream << " because no exception was thrown where one was expected";
|
||||
else
|
||||
stream << "No exception thrown where one was expected";
|
||||
}
|
||||
break;
|
||||
case ResultWas::Info:
|
||||
{
|
||||
TextColour colour( TextColour::ReconstructedExpression );
|
||||
streamVariableLengthText( "info", result.getMessage() );
|
||||
}
|
||||
break;
|
||||
case ResultWas::Warning:
|
||||
{
|
||||
TextColour colour( TextColour::ReconstructedExpression );
|
||||
streamVariableLengthText( "warning", result.getMessage() );
|
||||
}
|
||||
break;
|
||||
case ResultWas::ExplicitFailure:
|
||||
{
|
||||
TextColour colour( TextColour::Error );
|
||||
stream << "failed with message: '" << result.getMessage() << "'";
|
||||
}
|
||||
break;
|
||||
case ResultWas::Unknown: // These cases are here to prevent compiler warnings
|
||||
case ResultWas::Ok:
|
||||
case ResultWas::FailureBit:
|
||||
case ResultWas::ExpressionFailed:
|
||||
case ResultWas::Exception:
|
||||
if( !result.hasExpression() ) {
|
||||
if( result.succeeded() ) {
|
||||
TextColour colour( TextColour::Success );
|
||||
stream << " succeeded";
|
||||
}
|
||||
else {
|
||||
TextColour colour( TextColour::Error );
|
||||
stream << " failed";
|
||||
if( result.isOk() ) {
|
||||
TextColour okAnywayColour( TextColour::Success );
|
||||
stream << " - but was ok";
|
||||
}
|
||||
}
|
||||
}
|
||||
if( result.hasMessage() ) {
|
||||
stream << "\n";
|
||||
TextColour colour( TextColour::ReconstructedExpression );
|
||||
streamVariableLengthText( "with message", result.getMessage() );
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if( result.hasExpandedExpression() ) {
|
||||
stream << " for: ";
|
||||
if( result.getExpandedExpression().size() > 40 ) {
|
||||
stream << "\n";
|
||||
if( result.getExpandedExpression().size() < 70 )
|
||||
stream << "\t";
|
||||
}
|
||||
TextColour colour( TextColour::ReconstructedExpression );
|
||||
stream << result.getExpandedExpression();
|
||||
}
|
||||
|
||||
stream << std::endl;
|
||||
}
|
||||
|
||||
void streamVariableLengthText( std::string const& prefix, std::string const& text ) {
|
||||
std::string trimmed = trim( text );
|
||||
if( trimmed.find_first_of( "\r\n" ) == std::string::npos ) {
|
||||
stream << "[" << prefix << ": " << trimmed << "]";
|
||||
}
|
||||
else {
|
||||
stream << "\n[" << prefix << "] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>\n" << trimmed
|
||||
<< "\n[end of " << prefix << "] <<<<<<<<<<<<<<<<<<<<<<<<\n";
|
||||
}
|
||||
}
|
||||
|
||||
void printAssertionCounts( std::string const& label, Counts const& counts, std::string const& allPrefix = "All " ) {
|
||||
@ -6779,27 +6902,58 @@ namespace Catch {
|
||||
}
|
||||
|
||||
virtual void sectionEnded( Ptr<SectionStats const> const& _sectionStats ) {
|
||||
if( !unusedSectionInfo ) {
|
||||
if( _sectionStats->missingAssertions ) {
|
||||
lazyPrint();
|
||||
TextColour colour( TextColour::ResultError );
|
||||
stream << "\nNo assertions in section, '" << _sectionStats->sectionInfo.name << "'\n" << std::endl;
|
||||
}
|
||||
if( currentSectionInfo && currentSectionInfo->printed ) {
|
||||
stream << "[Summary for section '" << _sectionStats->sectionInfo.name << "': ";
|
||||
printAssertionCounts( "assertion", _sectionStats->assertions );
|
||||
// stream << "[End of section: '" << _sectionStats->sectionInfo.name << "' ";
|
||||
Counts const& assertions = _sectionStats->assertions;
|
||||
if( assertions.failed ) {
|
||||
TextColour colour( TextColour::ResultError );
|
||||
printAssertionCounts( "assertion", assertions );
|
||||
}
|
||||
else {
|
||||
TextColour colour( TextColour::ResultSuccess );
|
||||
stream << ( assertions.passed > 1 ? "All " : "" )
|
||||
<< pluralise( assertions.passed, "assertion" ) << " passed" ;
|
||||
}
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
AccumulatingReporter::sectionEnded( _sectionStats );
|
||||
}
|
||||
virtual void testCaseEnded( Ptr<TestCaseStats const> const& _testCaseStats ) {
|
||||
if( _testCaseStats->missingAssertions ) {
|
||||
lazyPrint();
|
||||
TextColour colour( TextColour::ResultError );
|
||||
stream << "\nNo assertions in test case, '" << _testCaseStats->testInfo.name << "'\n" << std::endl;
|
||||
}
|
||||
if( !unusedTestCaseInfo ) {
|
||||
stream << "[Summary for test case '" << _testCaseStats->testInfo.name << "': ";
|
||||
// stream << "[Finished: '" << _testCaseStats->testInfo.name << "' ";
|
||||
printTotals( _testCaseStats->totals );
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
AccumulatingReporter::testCaseEnded( _testCaseStats );
|
||||
}
|
||||
virtual void testGroupEnded( Ptr<TestGroupStats const> const& _testGroupStats ) {
|
||||
// !TBD
|
||||
if( !unusedGroupInfo ) {
|
||||
stream << "[Summary for group '" << _testGroupStats->groupInfo.name << "': ";
|
||||
// stream << "[End of group '" << _testGroupStats->groupInfo.name << "'. ";
|
||||
printTotals( _testGroupStats->totals );
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
AccumulatingReporter::testGroupEnded( _testGroupStats );
|
||||
}
|
||||
virtual void testRunEnded( Ptr<TestRunStats const> const& _testRunStats ) {
|
||||
// !TBD
|
||||
if( !unusedTestCaseInfo ) {
|
||||
stream << "[Summary for '" << _testRunStats->runInfo.name << "': ";
|
||||
// stream << "[Testing completed. ";
|
||||
printTotals( _testRunStats->totals );
|
||||
stream << "]\n" << std::endl;
|
||||
}
|
||||
AccumulatingReporter::testRunEnded( _testRunStats );
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user