2012-12-05 09:40:53 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 5/12/2012.
|
|
|
|
* Copyright 2012 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
* file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
*/
|
|
|
|
#ifndef TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
|
|
|
|
|
2013-12-03 19:52:41 +01:00
|
|
|
#include "catch_reporter_bases.hpp"
|
|
|
|
|
2012-12-05 09:40:53 +01:00
|
|
|
#include "../internal/catch_reporter_registrars.hpp"
|
|
|
|
#include "../internal/catch_console_colour.hpp"
|
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
2013-01-03 10:04:46 +01:00
|
|
|
struct ConsoleReporter : StreamingReporterBase {
|
2012-12-05 09:40:53 +01:00
|
|
|
ConsoleReporter( ReporterConfig const& _config )
|
2013-01-03 10:04:46 +01:00
|
|
|
: StreamingReporterBase( _config ),
|
2013-03-06 20:40:16 +01:00
|
|
|
m_headerPrinted( false ),
|
2012-12-13 13:46:47 +01:00
|
|
|
m_atLeastOneTestCasePrinted( false )
|
2012-12-05 09:40:53 +01:00
|
|
|
{}
|
|
|
|
|
|
|
|
virtual ~ConsoleReporter();
|
|
|
|
static std::string getDescription() {
|
|
|
|
return "Reports test results as plain lines of text";
|
|
|
|
}
|
|
|
|
virtual ReporterPreferences getPreferences() const {
|
|
|
|
ReporterPreferences prefs;
|
|
|
|
prefs.shouldRedirectStdOut = false;
|
|
|
|
return prefs;
|
|
|
|
}
|
2013-03-12 20:06:40 +01:00
|
|
|
|
|
|
|
virtual void noMatchingTestCases( std::string const& spec ) {
|
|
|
|
stream << "No test cases matched '" << spec << "'" << std::endl;
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-12-09 12:20:46 +01:00
|
|
|
virtual void assertionStarting( AssertionInfo const& ) {
|
2012-12-05 09:40:53 +01:00
|
|
|
}
|
|
|
|
|
2013-06-28 17:25:49 +02:00
|
|
|
virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
|
2013-01-03 10:04:46 +01:00
|
|
|
AssertionResult const& result = _assertionStats.assertionResult;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-11-13 09:07:38 +01:00
|
|
|
bool printInfoMessages = true;
|
|
|
|
|
2012-12-09 12:20:46 +01:00
|
|
|
// Drop out if result was successful and we're not printing those
|
2013-11-13 09:07:38 +01:00
|
|
|
if( !m_config->includeSuccessfulResults() && result.isOk() ) {
|
|
|
|
if( result.getResultType() != ResultWas::Warning )
|
|
|
|
return false;
|
|
|
|
printInfoMessages = false;
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-12-09 12:20:46 +01:00
|
|
|
lazyPrint();
|
|
|
|
|
2013-11-13 09:07:38 +01:00
|
|
|
AssertionPrinter printer( stream, _assertionStats, printInfoMessages );
|
2013-01-18 18:50:21 +01:00
|
|
|
printer.print();
|
2013-01-13 22:51:44 +01:00
|
|
|
stream << std::endl;
|
2013-06-28 17:25:49 +02:00
|
|
|
return true;
|
2013-01-13 22:51:44 +01:00
|
|
|
}
|
2013-01-26 21:17:52 +01:00
|
|
|
|
|
|
|
virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
|
2013-03-06 20:40:16 +01:00
|
|
|
m_headerPrinted = false;
|
2013-01-26 21:17:52 +01:00
|
|
|
StreamingReporterBase::sectionStarting( _sectionInfo );
|
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
virtual void sectionEnded( SectionStats const& _sectionStats ) {
|
|
|
|
if( _sectionStats.missingAssertions ) {
|
|
|
|
lazyPrint();
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colour( Colour::ResultError );
|
2013-08-08 09:05:19 +02:00
|
|
|
if( m_sectionStack.size() > 1 )
|
2013-07-26 20:19:44 +02:00
|
|
|
stream << "\nNo assertions in section";
|
|
|
|
else
|
|
|
|
stream << "\nNo assertions in test case";
|
|
|
|
stream << " '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
|
2013-01-18 18:50:21 +01:00
|
|
|
}
|
2013-08-16 19:57:41 +02:00
|
|
|
if( m_headerPrinted ) {
|
|
|
|
if( m_config->showDurations() == ShowDurations::Always )
|
|
|
|
stream << "Completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
|
|
|
|
m_headerPrinted = false;
|
|
|
|
}
|
2013-09-07 13:07:38 +02:00
|
|
|
else {
|
|
|
|
if( m_config->showDurations() == ShowDurations::Always )
|
|
|
|
stream << _sectionStats.sectionInfo.name << " completed in " << _sectionStats.durationInSeconds << "s" << std::endl;
|
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
StreamingReporterBase::sectionEnded( _sectionStats );
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void testCaseEnded( TestCaseStats const& _testCaseStats ) {
|
|
|
|
StreamingReporterBase::testCaseEnded( _testCaseStats );
|
2013-03-06 20:40:16 +01:00
|
|
|
m_headerPrinted = false;
|
2013-01-17 13:07:34 +01:00
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) {
|
2013-08-08 09:24:37 +02:00
|
|
|
if( currentGroupInfo.used ) {
|
2013-01-18 18:50:21 +01:00
|
|
|
printSummaryDivider();
|
|
|
|
stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
|
|
|
|
printTotals( _testGroupStats.totals );
|
|
|
|
stream << "\n" << std::endl;
|
|
|
|
}
|
|
|
|
StreamingReporterBase::testGroupEnded( _testGroupStats );
|
|
|
|
}
|
|
|
|
virtual void testRunEnded( TestRunStats const& _testRunStats ) {
|
|
|
|
if( m_atLeastOneTestCasePrinted )
|
|
|
|
printTotalsDivider();
|
|
|
|
printTotals( _testRunStats.totals );
|
|
|
|
stream << "\n" << std::endl;
|
|
|
|
StreamingReporterBase::testRunEnded( _testRunStats );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-18 18:50:21 +01:00
|
|
|
class AssertionPrinter {
|
2013-07-03 09:25:11 +02:00
|
|
|
void operator= ( AssertionPrinter const& );
|
2013-01-18 18:50:21 +01:00
|
|
|
public:
|
2013-11-13 09:07:38 +01:00
|
|
|
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages )
|
2013-01-18 18:50:21 +01:00
|
|
|
: stream( _stream ),
|
|
|
|
stats( _stats ),
|
|
|
|
result( _stats.assertionResult ),
|
2013-04-05 08:59:28 +02:00
|
|
|
colour( Colour::None ),
|
2013-02-02 20:58:04 +01:00
|
|
|
message( result.getMessage() ),
|
2013-11-13 09:07:38 +01:00
|
|
|
messages( _stats.infoMessages ),
|
|
|
|
printInfoMessages( _printInfoMessages )
|
2013-01-14 20:28:28 +01:00
|
|
|
{
|
2013-01-18 18:50:21 +01:00
|
|
|
switch( result.getResultType() ) {
|
2013-01-14 20:28:28 +01:00
|
|
|
case ResultWas::Ok:
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Success;
|
2013-01-17 13:07:34 +01:00
|
|
|
passOrFail = "PASSED";
|
2013-02-02 20:58:04 +01:00
|
|
|
//if( result.hasMessage() )
|
|
|
|
if( _stats.infoMessages.size() == 1 )
|
2013-01-14 20:28:28 +01:00
|
|
|
messageLabel = "with message";
|
2013-02-02 20:58:04 +01:00
|
|
|
if( _stats.infoMessages.size() > 1 )
|
|
|
|
messageLabel = "with messages";
|
2013-01-14 20:28:28 +01:00
|
|
|
break;
|
|
|
|
case ResultWas::ExpressionFailed:
|
2013-01-18 18:50:21 +01:00
|
|
|
if( result.isOk() ) {
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Success;
|
2013-01-17 13:07:34 +01:00
|
|
|
passOrFail = "FAILED - but was ok";
|
2013-01-14 20:28:28 +01:00
|
|
|
}
|
|
|
|
else {
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Error;
|
2013-01-17 13:07:34 +01:00
|
|
|
passOrFail = "FAILED";
|
2013-01-14 20:28:28 +01:00
|
|
|
}
|
2013-02-02 20:58:04 +01:00
|
|
|
if( _stats.infoMessages.size() == 1 )
|
2013-01-14 20:28:28 +01:00
|
|
|
messageLabel = "with message";
|
2013-02-02 20:58:04 +01:00
|
|
|
if( _stats.infoMessages.size() > 1 )
|
|
|
|
messageLabel = "with messages";
|
2013-01-14 20:28:28 +01:00
|
|
|
break;
|
|
|
|
case ResultWas::ThrewException:
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Error;
|
2013-01-17 13:07:34 +01:00
|
|
|
passOrFail = "FAILED";
|
2013-01-14 20:28:28 +01:00
|
|
|
messageLabel = "due to unexpected exception with message";
|
|
|
|
break;
|
|
|
|
case ResultWas::DidntThrowException:
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Error;
|
2013-01-17 13:07:34 +01:00
|
|
|
passOrFail = "FAILED";
|
2013-01-14 20:28:28 +01:00
|
|
|
messageLabel = "because no exception was thrown where one was expected";
|
|
|
|
break;
|
|
|
|
case ResultWas::Info:
|
|
|
|
messageLabel = "info";
|
|
|
|
break;
|
|
|
|
case ResultWas::Warning:
|
|
|
|
messageLabel = "warning";
|
|
|
|
break;
|
|
|
|
case ResultWas::ExplicitFailure:
|
2013-01-17 13:07:34 +01:00
|
|
|
passOrFail = "FAILED";
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Error;
|
2013-02-02 20:58:04 +01:00
|
|
|
if( _stats.infoMessages.size() == 1 )
|
|
|
|
messageLabel = "explicitly with message";
|
|
|
|
if( _stats.infoMessages.size() > 1 )
|
|
|
|
messageLabel = "explicitly with messages";
|
2013-01-14 20:28:28 +01:00
|
|
|
break;
|
2013-01-15 09:09:20 +01:00
|
|
|
// These cases are here to prevent compiler warnings
|
|
|
|
case ResultWas::Unknown:
|
2013-01-14 20:28:28 +01:00
|
|
|
case ResultWas::FailureBit:
|
2013-04-08 13:05:32 +02:00
|
|
|
case ResultWas::Exception:
|
2013-01-14 20:28:28 +01:00
|
|
|
passOrFail = "** internal error **";
|
2013-04-05 08:59:28 +02:00
|
|
|
colour = Colour::Error;
|
2013-01-14 20:28:28 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-18 18:50:21 +01:00
|
|
|
void print() const {
|
2013-03-04 12:19:15 +01:00
|
|
|
printSourceInfo();
|
2013-01-18 18:50:21 +01:00
|
|
|
if( stats.totals.assertions.total() > 0 ) {
|
2013-03-04 12:19:15 +01:00
|
|
|
if( result.isOk() )
|
|
|
|
stream << "\n";
|
2013-01-18 18:50:21 +01:00
|
|
|
printResultType();
|
|
|
|
printOriginalExpression();
|
|
|
|
printReconstructedExpression();
|
|
|
|
}
|
2013-03-04 12:19:15 +01:00
|
|
|
else {
|
|
|
|
stream << "\n";
|
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
printMessage();
|
2013-01-14 09:34:50 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-18 18:50:21 +01:00
|
|
|
private:
|
|
|
|
void printResultType() const {
|
|
|
|
if( !passOrFail.empty() ) {
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( colour );
|
2013-01-18 18:50:21 +01:00
|
|
|
stream << passOrFail << ":\n";
|
|
|
|
}
|
2013-01-14 09:34:50 +01:00
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
void printOriginalExpression() const {
|
|
|
|
if( result.hasExpression() ) {
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( Colour::OriginalExpression );
|
2013-01-18 18:50:21 +01:00
|
|
|
stream << " ";
|
2013-05-17 20:35:33 +02:00
|
|
|
stream << result.getExpressionInMacro();
|
2013-01-18 18:50:21 +01:00
|
|
|
stream << "\n";
|
|
|
|
}
|
2013-01-14 09:34:50 +01:00
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
void printReconstructedExpression() const {
|
|
|
|
if( result.hasExpandedExpression() ) {
|
|
|
|
stream << "with expansion:\n";
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( Colour::ReconstructedExpression );
|
2013-04-20 20:36:40 +02:00
|
|
|
stream << Text( result.getExpandedExpression(), TextAttributes().setIndent(2) ) << "\n";
|
2013-01-18 18:50:21 +01:00
|
|
|
}
|
2013-01-14 09:34:50 +01:00
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
void printMessage() const {
|
|
|
|
if( !messageLabel.empty() )
|
|
|
|
stream << messageLabel << ":" << "\n";
|
2013-02-02 20:58:04 +01:00
|
|
|
for( std::vector<MessageInfo>::const_iterator it = messages.begin(), itEnd = messages.end();
|
|
|
|
it != itEnd;
|
2013-07-03 20:14:59 +02:00
|
|
|
++it ) {
|
2013-11-13 09:07:38 +01:00
|
|
|
// If this assertion is a warning ignore any INFO messages
|
|
|
|
if( printInfoMessages || it->type != ResultWas::Info )
|
|
|
|
stream << Text( it->message, TextAttributes().setIndent(2) ) << "\n";
|
2013-02-02 20:58:04 +01:00
|
|
|
}
|
2012-12-09 12:20:46 +01:00
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
void printSourceInfo() const {
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( Colour::FileName );
|
2013-03-04 12:19:15 +01:00
|
|
|
stream << result.getSourceInfo() << ": ";
|
2012-12-09 12:20:46 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-18 18:50:21 +01:00
|
|
|
std::ostream& stream;
|
|
|
|
AssertionStats const& stats;
|
|
|
|
AssertionResult const& result;
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour::Code colour;
|
2013-01-18 18:50:21 +01:00
|
|
|
std::string passOrFail;
|
|
|
|
std::string messageLabel;
|
|
|
|
std::string message;
|
2013-02-02 20:58:04 +01:00
|
|
|
std::vector<MessageInfo> messages;
|
2013-11-13 09:07:38 +01:00
|
|
|
bool printInfoMessages;
|
2013-01-18 18:50:21 +01:00
|
|
|
};
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-14 19:51:49 +01:00
|
|
|
void lazyPrint() {
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-08-08 09:24:37 +02:00
|
|
|
if( !currentTestRunInfo.used )
|
2013-01-14 19:51:49 +01:00
|
|
|
lazyPrintRunInfo();
|
2013-08-08 09:24:37 +02:00
|
|
|
if( !currentGroupInfo.used )
|
2013-01-14 19:51:49 +01:00
|
|
|
lazyPrintGroupInfo();
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-03-06 20:40:16 +01:00
|
|
|
if( !m_headerPrinted ) {
|
|
|
|
printTestCaseAndSectionHeader();
|
|
|
|
m_headerPrinted = true;
|
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
m_atLeastOneTestCasePrinted = true;
|
|
|
|
}
|
|
|
|
void lazyPrintRunInfo() {
|
2013-03-16 21:19:38 +01:00
|
|
|
stream << "\n" << getTildes() << "\n";
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colour( Colour::SecondaryText );
|
2013-08-08 09:24:37 +02:00
|
|
|
stream << currentTestRunInfo->name
|
2013-06-05 09:18:52 +02:00
|
|
|
<< " is a Catch v" << libraryVersion.majorVersion << "."
|
2013-01-14 19:51:49 +01:00
|
|
|
<< libraryVersion.minorVersion << " b"
|
|
|
|
<< libraryVersion.buildNumber;
|
2014-04-18 09:28:52 +02:00
|
|
|
if( libraryVersion.branchName != std::string( "master" ) )
|
2013-01-14 19:51:49 +01:00
|
|
|
stream << " (" << libraryVersion.branchName << ")";
|
|
|
|
stream << " host application.\n"
|
|
|
|
<< "Run with -? for options\n\n";
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-08-08 09:24:37 +02:00
|
|
|
currentTestRunInfo.used = true;
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
|
|
|
void lazyPrintGroupInfo() {
|
2013-08-08 09:24:37 +02:00
|
|
|
if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
|
|
|
|
printClosedHeader( "Group: " + currentGroupInfo->name );
|
|
|
|
currentGroupInfo.used = true;
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-06 20:40:16 +01:00
|
|
|
void printTestCaseAndSectionHeader() {
|
2013-08-08 09:05:19 +02:00
|
|
|
assert( !m_sectionStack.empty() );
|
2013-08-08 09:24:37 +02:00
|
|
|
printOpenHeader( currentTestCaseInfo->name );
|
2013-08-08 09:05:19 +02:00
|
|
|
|
|
|
|
if( m_sectionStack.size() > 1 ) {
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( Colour::Headers );
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
std::vector<SectionInfo>::const_iterator
|
2013-08-08 09:05:19 +02:00
|
|
|
it = m_sectionStack.begin()+1, // Skip first section (test case)
|
|
|
|
itEnd = m_sectionStack.end();
|
|
|
|
for( ; it != itEnd; ++it )
|
2013-08-15 19:39:55 +02:00
|
|
|
printHeaderString( it->name, 2 );
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2013-08-08 09:05:19 +02:00
|
|
|
|
2013-08-15 19:39:55 +02:00
|
|
|
SourceLineInfo lineInfo = m_sectionStack.front().lineInfo;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-04-17 01:05:25 +02:00
|
|
|
if( !lineInfo.empty() ){
|
|
|
|
stream << getDashes() << "\n";
|
|
|
|
Colour colourGuard( Colour::FileName );
|
|
|
|
stream << lineInfo << "\n";
|
|
|
|
}
|
2013-03-06 20:40:16 +01:00
|
|
|
stream << getDots() << "\n" << std::endl;
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2013-01-16 10:39:08 +01:00
|
|
|
|
2013-03-06 20:40:16 +01:00
|
|
|
void printClosedHeader( std::string const& _name ) {
|
|
|
|
printOpenHeader( _name );
|
|
|
|
stream << getDots() << "\n";
|
|
|
|
}
|
2013-04-19 20:08:32 +02:00
|
|
|
void printOpenHeader( std::string const& _name ) {
|
2013-04-01 12:25:54 +02:00
|
|
|
stream << getDashes() << "\n";
|
|
|
|
{
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( Colour::Headers );
|
2013-04-19 20:08:32 +02:00
|
|
|
printHeaderString( _name );
|
2013-04-01 12:25:54 +02:00
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2013-04-19 20:08:32 +02:00
|
|
|
|
2013-04-05 21:55:57 +02:00
|
|
|
// if string has a : in first line will set indent to follow it on
|
|
|
|
// subsequent lines
|
2013-04-19 20:08:32 +02:00
|
|
|
void printHeaderString( std::string const& _string, std::size_t indent = 0 ) {
|
2013-04-05 21:55:57 +02:00
|
|
|
std::size_t i = _string.find( ": " );
|
|
|
|
if( i != std::string::npos )
|
|
|
|
i+=2;
|
|
|
|
else
|
|
|
|
i = 0;
|
2013-04-20 20:36:40 +02:00
|
|
|
stream << Text( _string, TextAttributes()
|
|
|
|
.setIndent( indent+i)
|
|
|
|
.setInitialIndent( indent ) ) << "\n";
|
2013-04-05 21:55:57 +02:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-14 19:51:49 +01:00
|
|
|
void printTotals( const Totals& totals ) {
|
2013-11-12 20:06:08 +01:00
|
|
|
if( totals.testCases.total() == 0 ) {
|
2013-01-14 19:51:49 +01:00
|
|
|
stream << "No tests ran";
|
|
|
|
}
|
2013-11-12 20:06:08 +01:00
|
|
|
else if( totals.assertions.total() == 0 ) {
|
|
|
|
Colour colour( Colour::Yellow );
|
|
|
|
printCounts( "test case", totals.testCases );
|
|
|
|
stream << " (no assertions)";
|
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
else if( totals.assertions.failed ) {
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colour( Colour::ResultError );
|
2013-01-14 19:51:49 +01:00
|
|
|
printCounts( "test case", totals.testCases );
|
|
|
|
if( totals.testCases.failed > 0 ) {
|
|
|
|
stream << " (";
|
|
|
|
printCounts( "assertion", totals.assertions );
|
|
|
|
stream << ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colour( Colour::ResultSuccess );
|
2013-01-14 19:51:49 +01:00
|
|
|
stream << "All tests passed ("
|
|
|
|
<< pluralise( totals.assertions.passed, "assertion" ) << " in "
|
|
|
|
<< pluralise( totals.testCases.passed, "test case" ) << ")";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
void printCounts( std::string const& label, Counts const& counts ) {
|
|
|
|
if( counts.total() == 1 ) {
|
|
|
|
stream << "1 " << label << " - ";
|
|
|
|
if( counts.failed )
|
|
|
|
stream << "failed";
|
|
|
|
else
|
|
|
|
stream << "passed";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
stream << counts.total() << " " << label << "s ";
|
|
|
|
if( counts.passed ) {
|
|
|
|
if( counts.failed )
|
|
|
|
stream << "- " << counts.failed << " failed";
|
|
|
|
else if( counts.passed == 2 )
|
|
|
|
stream << "- both passed";
|
|
|
|
else
|
|
|
|
stream << "- all passed";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if( counts.failed == 2 )
|
|
|
|
stream << "- both failed";
|
|
|
|
else
|
|
|
|
stream << "- all failed";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-12-13 13:46:47 +01:00
|
|
|
void printTotalsDivider() {
|
2013-01-13 22:51:44 +01:00
|
|
|
stream << getDoubleDashes() << "\n";
|
2012-12-13 13:46:47 +01:00
|
|
|
}
|
2013-01-13 22:51:44 +01:00
|
|
|
void printSummaryDivider() {
|
|
|
|
stream << getDashes() << "\n";
|
2012-12-11 10:02:31 +01:00
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
static std::string const& getDashes() {
|
2013-01-26 21:06:55 +01:00
|
|
|
static const std::string dashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '-' );
|
2013-01-14 19:51:49 +01:00
|
|
|
return dashes;
|
|
|
|
}
|
2013-01-18 09:09:28 +01:00
|
|
|
static std::string const& getDots() {
|
2013-01-26 21:06:55 +01:00
|
|
|
static const std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '.' );
|
2013-01-18 09:09:28 +01:00
|
|
|
return dots;
|
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
static std::string const& getDoubleDashes() {
|
2013-01-26 21:06:55 +01:00
|
|
|
static const std::string doubleDashes( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
|
2013-01-14 19:51:49 +01:00
|
|
|
return doubleDashes;
|
|
|
|
}
|
2013-03-16 21:19:38 +01:00
|
|
|
static std::string const& getTildes() {
|
|
|
|
static const std::string dots( CATCH_CONFIG_CONSOLE_WIDTH-1, '~' );
|
|
|
|
return dots;
|
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
private:
|
2013-03-06 20:40:16 +01:00
|
|
|
bool m_headerPrinted;
|
2012-12-13 13:46:47 +01:00
|
|
|
bool m_atLeastOneTestCasePrinted;
|
2012-12-05 09:40:53 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
|
|
|
|
|
|
|
|
} // end namespace Catch
|
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_REPORTER_CONSOLE_HPP_INCLUDED
|