Changed header and summary logs to multiline forms

This commit is contained in:
Phil Nash 2012-12-13 12:46:47 +00:00
parent f117812cff
commit a7079a2dbe
2 changed files with 866 additions and 428 deletions

View File

@ -16,7 +16,8 @@ namespace Catch {
struct ConsoleReporter : AccumulatingReporter { struct ConsoleReporter : AccumulatingReporter {
ConsoleReporter( ReporterConfig const& _config ) ConsoleReporter( ReporterConfig const& _config )
: AccumulatingReporter( _config ) : AccumulatingReporter( _config ),
m_atLeastOneTestCasePrinted( false )
{} {}
virtual ~ConsoleReporter(); virtual ~ConsoleReporter();
@ -30,19 +31,18 @@ namespace Catch {
} }
void lazyPrintRunInfo() { void lazyPrintRunInfo() {
stream << "[Started testing: " << testRunInfo->name << "]" << std::endl; printHeader( "Started testing", testRunInfo->name );
testRunInfo.reset(); testRunInfo.reset();
} }
void lazyPrintGroupInfo() { void lazyPrintGroupInfo() {
if( !unusedGroupInfo->name.empty() ) if( !unusedGroupInfo->name.empty() )
stream << "[Group: '" << unusedGroupInfo->name << "']" << std::endl; printHeader( "Group", unusedGroupInfo->name );
unusedGroupInfo.reset(); unusedGroupInfo.reset();
} }
void lazyPrintTestCaseInfo() { void lazyPrintTestCaseInfo() {
stream << "[Test case: '" << unusedTestCaseInfo->name << "']" << std::endl; printHeader( "Test case", unusedTestCaseInfo->name );
unusedTestCaseInfo.reset(); unusedTestCaseInfo.reset();
} }
void lazyPrintSectionInfo() { void lazyPrintSectionInfo() {
std::vector<ThreadedSectionInfo*> sections; std::vector<ThreadedSectionInfo*> sections;
for( ThreadedSectionInfo* section = unusedSectionInfo.get(); for( ThreadedSectionInfo* section = unusedSectionInfo.get();
@ -52,11 +52,26 @@ namespace Catch {
typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It; typedef std::vector<ThreadedSectionInfo*>::const_reverse_iterator It;
for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it ) { for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it ) {
stream << "[Section: " << "'" + (*it)->name + "'" << "]" << std::endl; printHeader( "Section", (*it)->name );
(*it)->printed = true; (*it)->printed = true;
} }
unusedSectionInfo.reset(); unusedSectionInfo.reset();
} }
static std::string const& getDashes() {
static const std::string dashes = "----------------------------------------------------------------";
return dashes;
}
static std::string const& getDoubleDashes() {
static const std::string doubleDashes = "================================================================";
return doubleDashes;
}
void printHeader( std::string const& _type, std::string const& _name ) {
stream << "-- " << _type << ": '" << _name << "' "
<< getDashes().substr( 0, getDashes().size() - ( _type.size() + _name.size() + 9 ) )
<< std::endl;
}
void lazyPrint() { void lazyPrint() {
if( testRunInfo ) if( testRunInfo )
lazyPrintRunInfo(); lazyPrintRunInfo();
@ -245,7 +260,8 @@ namespace Catch {
stream << "\nNo assertions in section, '" << _sectionStats->sectionInfo.name << "'\n" << std::endl; stream << "\nNo assertions in section, '" << _sectionStats->sectionInfo.name << "'\n" << std::endl;
} }
if( currentSectionInfo && currentSectionInfo->printed ) { if( currentSectionInfo && currentSectionInfo->printed ) {
stream << "[Summary for section '" << _sectionStats->sectionInfo.name << "': "; printSummarDivider();
stream << "Summary for section '" << _sectionStats->sectionInfo.name << "':\n";
Counts const& assertions = _sectionStats->assertions; Counts const& assertions = _sectionStats->assertions;
if( assertions.failed ) { if( assertions.failed ) {
TextColour colour( TextColour::ResultError ); TextColour colour( TextColour::ResultError );
@ -256,7 +272,7 @@ namespace Catch {
stream << ( assertions.passed > 1 ? "All " : "" ) stream << ( assertions.passed > 1 ? "All " : "" )
<< pluralise( assertions.passed, "assertion" ) << " passed" ; << pluralise( assertions.passed, "assertion" ) << " passed" ;
} }
stream << "]\n" << std::endl; stream << "\n" << std::endl;
} }
AccumulatingReporter::sectionEnded( _sectionStats ); AccumulatingReporter::sectionEnded( _sectionStats );
} }
@ -268,29 +284,40 @@ namespace Catch {
stream << "\nNo assertions in test case, '" << _testCaseStats->testInfo.name << "'\n" << std::endl; stream << "\nNo assertions in test case, '" << _testCaseStats->testInfo.name << "'\n" << std::endl;
} }
if( !unusedTestCaseInfo ) { if( !unusedTestCaseInfo ) {
stream << "[Summary for test case '" << _testCaseStats->testInfo.name << "': "; m_atLeastOneTestCasePrinted = true;
printSummarDivider();
stream << "Summary for test case '" << _testCaseStats->testInfo.name << "':\n";
printTotals( _testCaseStats->totals ); printTotals( _testCaseStats->totals );
stream << "]\n" << std::endl; stream << "\n" << std::endl;
} }
AccumulatingReporter::testCaseEnded( _testCaseStats ); AccumulatingReporter::testCaseEnded( _testCaseStats );
} }
virtual void testGroupEnded( Ptr<TestGroupStats const> const& _testGroupStats ) { virtual void testGroupEnded( Ptr<TestGroupStats const> const& _testGroupStats ) {
if( !unusedGroupInfo ) { if( !unusedGroupInfo ) {
stream << "[Summary for group '" << _testGroupStats->groupInfo.name << "': "; printSummarDivider();
stream << "Summary for group '" << _testGroupStats->groupInfo.name << "':\n";
printTotals( _testGroupStats->totals ); printTotals( _testGroupStats->totals );
stream << "]\n" << std::endl; stream << "\n" << std::endl;
} }
AccumulatingReporter::testGroupEnded( _testGroupStats ); AccumulatingReporter::testGroupEnded( _testGroupStats );
} }
virtual void testRunEnded( Ptr<TestRunStats const> const& _testRunStats ) { virtual void testRunEnded( Ptr<TestRunStats const> const& _testRunStats ) {
if( !unusedTestCaseInfo ) { if( m_atLeastOneTestCasePrinted )
stream << "[Summary for '" << _testRunStats->runInfo.name << "': "; printTotalsDivider();
printTotals( _testRunStats->totals ); stream << "Summary for all tests in '" << _testRunStats->runInfo.name << "':\n";
stream << "]\n" << std::endl; printTotals( _testRunStats->totals );
} stream << "\n" << std::endl;
AccumulatingReporter::testRunEnded( _testRunStats ); AccumulatingReporter::testRunEnded( _testRunStats );
} }
private:
void printTotalsDivider() {
stream << "================================================================\n";
}
void printSummarDivider() {
stream << "----------------------------------------------------------------\n";
}
void printLineInfo( SourceLineInfo const& lineInfo ) { void printLineInfo( SourceLineInfo const& lineInfo ) {
if( !lineInfo.empty() ) { if( !lineInfo.empty() ) {
if( m_lastPrintedLine.empty() || if( m_lastPrintedLine.empty() ||
@ -309,6 +336,7 @@ namespace Catch {
void resetLastPrintedLine() { void resetLastPrintedLine() {
m_lastPrintedLine = SourceLineInfo(); m_lastPrintedLine = SourceLineInfo();
} }
bool m_atLeastOneTestCasePrinted;
SourceLineInfo m_lastPrintedLine; SourceLineInfo m_lastPrintedLine;
}; };

File diff suppressed because it is too large Load Diff