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)
|
|
|
|
*/
|
|
|
|
|
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"
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "internal/catch_console_colour.h"
|
2017-07-10 11:33:18 +02:00
|
|
|
#include "../internal/catch_version.h"
|
2017-07-21 00:20:42 +02:00
|
|
|
#include "../internal/catch_text.h"
|
2017-08-05 22:41:56 +02:00
|
|
|
#include "../internal/catch_stringref.h"
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2017-02-27 11:34:15 +01:00
|
|
|
#include <cfloat>
|
|
|
|
#include <cstdio>
|
|
|
|
|
2017-07-25 17:16:28 +02:00
|
|
|
namespace {
|
|
|
|
std::size_t makeRatio( std::size_t number, std::size_t total ) {
|
|
|
|
std::size_t ratio = total > 0 ? CATCH_CONFIG_CONSOLE_WIDTH * number/ total : 0;
|
|
|
|
return ( ratio == 0 && number > 0 ) ? 1 : ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::size_t& findMax( std::size_t& i, std::size_t& j, std::size_t& k ) {
|
|
|
|
if( i > j && i > k )
|
|
|
|
return i;
|
|
|
|
else if( j > k )
|
|
|
|
return j;
|
|
|
|
else
|
|
|
|
return k;
|
|
|
|
}
|
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
struct ColumnInfo {
|
|
|
|
enum Justification { Left, Right };
|
|
|
|
std::string name;
|
|
|
|
int width;
|
|
|
|
Justification justification;
|
|
|
|
};
|
|
|
|
struct ColumnBreak {};
|
|
|
|
struct RowBreak {};
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
class TablePrinter {
|
|
|
|
std::ostream& m_os;
|
|
|
|
std::vector<ColumnInfo> m_columnInfos;
|
|
|
|
std::ostringstream m_oss;
|
|
|
|
int m_currentColumn = -1;
|
|
|
|
bool m_isOpen = false;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TablePrinter( std::ostream& os, std::vector<ColumnInfo> const& columnInfos )
|
|
|
|
: m_os( os ),
|
|
|
|
m_columnInfos( columnInfos )
|
|
|
|
{}
|
|
|
|
|
|
|
|
auto columnInfos() const -> std::vector<ColumnInfo> const& {
|
|
|
|
return m_columnInfos;
|
|
|
|
}
|
|
|
|
|
|
|
|
void open() {
|
|
|
|
if( !m_isOpen ) {
|
|
|
|
m_isOpen = true;
|
|
|
|
*this << RowBreak();
|
|
|
|
for( auto const& info : m_columnInfos )
|
|
|
|
*this << info.name << ColumnBreak();
|
|
|
|
*this << RowBreak();
|
2017-08-10 00:27:29 +02:00
|
|
|
m_os << Catch::getLineOfChars<'-'>() << "\n";
|
2017-08-05 00:54:51 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void close() {
|
|
|
|
if( m_isOpen ) {
|
|
|
|
*this << RowBreak();
|
|
|
|
m_os << std::endl;
|
|
|
|
m_isOpen = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
friend TablePrinter& operator << ( TablePrinter& tp, T const& value ) {
|
|
|
|
tp.m_oss << value;
|
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend TablePrinter& operator << ( TablePrinter& tp, ColumnBreak ) {
|
|
|
|
auto colStr = tp.m_oss.str();
|
2017-08-05 22:41:56 +02:00
|
|
|
// This takes account of utf8 encodings
|
2017-08-14 09:54:57 +02:00
|
|
|
auto strSize = Catch::StringRef( colStr ).numberOfCharacters();
|
2017-08-05 00:54:51 +02:00
|
|
|
tp.m_oss.str("");
|
|
|
|
tp.open();
|
|
|
|
if( tp.m_currentColumn == static_cast<int>(tp.m_columnInfos.size()-1) ) {
|
|
|
|
tp.m_currentColumn = -1;
|
|
|
|
tp.m_os << "\n";
|
|
|
|
}
|
|
|
|
tp.m_currentColumn++;
|
|
|
|
|
|
|
|
auto colInfo = tp.m_columnInfos[tp.m_currentColumn];
|
2017-09-18 18:13:17 +02:00
|
|
|
auto padding = ( strSize+2 < static_cast<std::size_t>( colInfo.width ) )
|
2017-08-05 22:41:56 +02:00
|
|
|
? std::string( colInfo.width-(strSize+2), ' ' )
|
2017-08-05 00:54:51 +02:00
|
|
|
: std::string();
|
|
|
|
if( colInfo.justification == ColumnInfo::Left )
|
2017-08-10 00:27:29 +02:00
|
|
|
tp.m_os << colStr << padding << " ";
|
2017-08-05 00:54:51 +02:00
|
|
|
else
|
2017-08-10 00:27:29 +02:00
|
|
|
tp.m_os << padding << colStr << " ";
|
2017-08-05 00:54:51 +02:00
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
|
|
|
|
friend TablePrinter& operator << ( TablePrinter& tp, RowBreak ) {
|
|
|
|
if( tp.m_currentColumn > 0 ) {
|
|
|
|
tp.m_os << "\n";
|
|
|
|
tp.m_currentColumn = -1;
|
|
|
|
}
|
|
|
|
return tp;
|
|
|
|
}
|
|
|
|
};
|
2017-08-05 22:41:56 +02:00
|
|
|
|
|
|
|
class Duration {
|
|
|
|
enum class Unit {
|
|
|
|
Auto,
|
|
|
|
Nanoseconds,
|
|
|
|
Microseconds,
|
|
|
|
Milliseconds,
|
|
|
|
Seconds,
|
|
|
|
Minutes
|
|
|
|
};
|
|
|
|
static const uint64_t s_nanosecondsInAMicrosecond = 1000;
|
|
|
|
static const uint64_t s_nanosecondsInAMillisecond = 1000*s_nanosecondsInAMicrosecond;
|
|
|
|
static const uint64_t s_nanosecondsInASecond = 1000*s_nanosecondsInAMillisecond;
|
|
|
|
static const uint64_t s_nanosecondsInAMinute = 60*s_nanosecondsInASecond;
|
|
|
|
|
|
|
|
uint64_t m_inNanoseconds;
|
|
|
|
Unit m_units;
|
|
|
|
|
|
|
|
public:
|
|
|
|
Duration( uint64_t inNanoseconds, Unit units = Unit::Auto )
|
|
|
|
: m_inNanoseconds( inNanoseconds ),
|
|
|
|
m_units( units )
|
|
|
|
{
|
|
|
|
if( m_units == Unit::Auto ) {
|
|
|
|
if( m_inNanoseconds < s_nanosecondsInAMicrosecond )
|
|
|
|
m_units = Unit::Nanoseconds;
|
|
|
|
else if( m_inNanoseconds < s_nanosecondsInAMillisecond )
|
|
|
|
m_units = Unit::Microseconds;
|
|
|
|
else if( m_inNanoseconds < s_nanosecondsInASecond )
|
|
|
|
m_units = Unit::Milliseconds;
|
|
|
|
else if( m_inNanoseconds < s_nanosecondsInAMinute )
|
|
|
|
m_units = Unit::Seconds;
|
|
|
|
else
|
|
|
|
m_units = Unit::Minutes;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
auto value() const -> double {
|
|
|
|
switch( m_units ) {
|
|
|
|
case Unit::Microseconds:
|
|
|
|
return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMicrosecond );
|
|
|
|
case Unit::Milliseconds:
|
|
|
|
return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMillisecond );
|
|
|
|
case Unit::Seconds:
|
|
|
|
return m_inNanoseconds / static_cast<double>( s_nanosecondsInASecond );
|
|
|
|
case Unit::Minutes:
|
|
|
|
return m_inNanoseconds / static_cast<double>( s_nanosecondsInAMinute );
|
|
|
|
default:
|
|
|
|
return static_cast<double>( m_inNanoseconds );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
auto unitsAsString() const -> std::string {
|
|
|
|
switch( m_units ) {
|
|
|
|
case Unit::Nanoseconds:
|
|
|
|
return "ns";
|
|
|
|
case Unit::Microseconds:
|
|
|
|
return "µs";
|
|
|
|
case Unit::Milliseconds:
|
|
|
|
return "ms";
|
|
|
|
case Unit::Seconds:
|
|
|
|
return "s";
|
|
|
|
case Unit::Minutes:
|
|
|
|
return "m";
|
|
|
|
default:
|
|
|
|
return "** internal error **";
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
friend auto operator << ( std::ostream& os, Duration const& duration ) -> std::ostream& {
|
|
|
|
return os << duration.value() << " " << duration.unitsAsString();
|
|
|
|
}
|
|
|
|
};
|
2017-08-05 00:54:51 +02:00
|
|
|
}
|
2017-08-04 20:23:30 +02:00
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
namespace Catch {
|
2017-08-04 20:23:30 +02:00
|
|
|
|
2017-07-09 11:46:53 +02:00
|
|
|
struct ConsoleReporter : StreamingReporterBase<ConsoleReporter> {
|
2017-08-05 00:54:51 +02:00
|
|
|
TablePrinter m_tablePrinter;
|
2017-07-10 11:33:18 +02:00
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
ConsoleReporter( ReporterConfig const& config )
|
|
|
|
: StreamingReporterBase( config ),
|
|
|
|
m_tablePrinter( config.stream(),
|
|
|
|
{
|
2017-08-10 00:27:29 +02:00
|
|
|
{ "benchmark name", CATCH_CONFIG_CONSOLE_WIDTH-32, ColumnInfo::Left },
|
2017-08-05 00:54:51 +02:00
|
|
|
{ "iters", 8, ColumnInfo::Right },
|
2017-08-05 22:41:56 +02:00
|
|
|
{ "elapsed ns", 14, ColumnInfo::Right },
|
|
|
|
{ "average", 14, ColumnInfo::Right }
|
2017-08-05 00:54:51 +02:00
|
|
|
} )
|
|
|
|
{}
|
2017-07-20 16:57:17 +02:00
|
|
|
~ConsoleReporter() override;
|
2012-12-05 09:40:53 +01:00
|
|
|
static std::string getDescription() {
|
|
|
|
return "Reports test results as plain lines of text";
|
|
|
|
}
|
2013-03-12 20:06:40 +01:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
void noMatchingTestCases( std::string const& spec ) override {
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << "No test cases matched '" << spec << '\'' << std::endl;
|
2013-03-12 20:06:40 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-08-04 20:23:30 +02:00
|
|
|
void assertionStarting( AssertionInfo const& ) override {
|
|
|
|
}
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
bool assertionEnded( AssertionStats const& _assertionStats ) override {
|
2013-01-03 10:04:46 +01:00
|
|
|
AssertionResult const& result = _assertionStats.assertionResult;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2017-03-03 15:19:41 +01:00
|
|
|
bool includeResults = m_config->includeSuccessfulResults() || !result.isOk();
|
2013-11-13 09:07:38 +01:00
|
|
|
|
2017-03-03 15:19:41 +01:00
|
|
|
// Drop out if result was successful but we're not printing them.
|
|
|
|
if( !includeResults && result.getResultType() != ResultWas::Warning )
|
|
|
|
return false;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2012-12-09 12:20:46 +01:00
|
|
|
lazyPrint();
|
|
|
|
|
2017-03-03 15:19:41 +01:00
|
|
|
AssertionPrinter printer( stream, _assertionStats, includeResults );
|
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
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
void sectionStarting( SectionInfo const& _sectionInfo ) override {
|
2013-03-06 20:40:16 +01:00
|
|
|
m_headerPrinted = false;
|
2013-01-26 21:17:52 +01:00
|
|
|
StreamingReporterBase::sectionStarting( _sectionInfo );
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void sectionEnded( SectionStats const& _sectionStats ) override {
|
2017-08-05 00:54:51 +02:00
|
|
|
m_tablePrinter.close();
|
2013-01-18 18:50:21 +01:00
|
|
|
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
|
|
|
}
|
2017-02-17 15:07:56 +01:00
|
|
|
if( m_config->showDurations() == ShowDurations::Always ) {
|
2017-02-27 11:34:15 +01:00
|
|
|
stream << getFormattedDuration(_sectionStats.durationInSeconds) << " s: " << _sectionStats.sectionInfo.name << std::endl;
|
2017-02-17 15:07:56 +01:00
|
|
|
}
|
2013-08-16 19:57:41 +02:00
|
|
|
if( m_headerPrinted ) {
|
|
|
|
m_headerPrinted = false;
|
|
|
|
}
|
2013-01-18 18:50:21 +01:00
|
|
|
StreamingReporterBase::sectionEnded( _sectionStats );
|
|
|
|
}
|
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
|
2017-08-04 20:23:30 +02:00
|
|
|
void benchmarkStarting( BenchmarkInfo const& info ) override {
|
2017-08-05 00:54:51 +02:00
|
|
|
lazyPrintWithoutClosingBenchmarkTable();
|
|
|
|
|
|
|
|
auto nameCol = Column( info.name ).width( m_tablePrinter.columnInfos()[0].width-2 );
|
|
|
|
|
2017-08-04 20:23:30 +02:00
|
|
|
bool firstLine = true;
|
|
|
|
for( auto line : nameCol ) {
|
|
|
|
if( !firstLine )
|
2017-08-05 00:54:51 +02:00
|
|
|
m_tablePrinter << ColumnBreak() << ColumnBreak() << ColumnBreak();
|
2017-08-04 20:23:30 +02:00
|
|
|
else
|
|
|
|
firstLine = false;
|
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
m_tablePrinter << line << ColumnBreak();
|
2017-08-04 20:23:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
void benchmarkEnded( BenchmarkStats const& stats ) override {
|
2017-08-05 22:41:56 +02:00
|
|
|
Duration average( stats.elapsedTimeInNanoseconds/stats.iterations );
|
2017-08-05 00:54:51 +02:00
|
|
|
m_tablePrinter
|
|
|
|
<< stats.iterations << ColumnBreak()
|
|
|
|
<< stats.elapsedTimeInNanoseconds << ColumnBreak()
|
2017-08-05 22:41:56 +02:00
|
|
|
<< average << ColumnBreak();
|
2017-08-04 20:23:30 +02:00
|
|
|
}
|
|
|
|
|
2017-07-20 16:57:17 +02:00
|
|
|
void testCaseEnded( TestCaseStats const& _testCaseStats ) override {
|
2017-08-05 00:54:51 +02:00
|
|
|
m_tablePrinter.close();
|
2013-01-18 18:50:21 +01:00
|
|
|
StreamingReporterBase::testCaseEnded( _testCaseStats );
|
2013-03-06 20:40:16 +01:00
|
|
|
m_headerPrinted = false;
|
2013-01-17 13:07:34 +01:00
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void testGroupEnded( TestGroupStats const& _testGroupStats ) override {
|
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 );
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\n' << std::endl;
|
2013-01-18 18:50:21 +01:00
|
|
|
}
|
|
|
|
StreamingReporterBase::testGroupEnded( _testGroupStats );
|
|
|
|
}
|
2017-07-20 16:57:17 +02:00
|
|
|
void testRunEnded( TestRunStats const& _testRunStats ) override {
|
2014-07-03 09:09:57 +02:00
|
|
|
printTotalsDivider( _testRunStats.totals );
|
2013-01-18 18:50:21 +01:00
|
|
|
printTotals( _testRunStats.totals );
|
2014-07-03 09:09:57 +02:00
|
|
|
stream << std::endl;
|
2013-01-18 18:50:21 +01:00
|
|
|
StreamingReporterBase::testRunEnded( _testRunStats );
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-18 18:50:21 +01:00
|
|
|
class AssertionPrinter {
|
|
|
|
public:
|
2017-07-20 00:27:28 +02:00
|
|
|
AssertionPrinter& operator= ( AssertionPrinter const& ) = delete;
|
|
|
|
AssertionPrinter( AssertionPrinter const& ) = delete;
|
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";
|
2017-03-31 00:06:35 +02:00
|
|
|
messageLabel = "due to unexpected exception with ";
|
|
|
|
if (_stats.infoMessages.size() == 1)
|
|
|
|
messageLabel += "message";
|
|
|
|
if (_stats.infoMessages.size() > 1)
|
|
|
|
messageLabel += "messages";
|
2013-01-14 20:28:28 +01:00
|
|
|
break;
|
2014-08-22 09:07:39 +02:00
|
|
|
case ResultWas::FatalErrorCondition:
|
|
|
|
colour = Colour::Error;
|
|
|
|
passOrFail = "FAILED";
|
|
|
|
messageLabel = "due to a fatal error condition";
|
|
|
|
break;
|
2013-01-14 20:28:28 +01:00
|
|
|
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() )
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\n';
|
2013-01-18 18:50:21 +01:00
|
|
|
printResultType();
|
|
|
|
printOriginalExpression();
|
|
|
|
printReconstructedExpression();
|
|
|
|
}
|
2013-03-04 12:19:15 +01:00
|
|
|
else {
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\n';
|
2013-03-04 12:19:15 +01:00
|
|
|
}
|
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();
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\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 printReconstructedExpression() const {
|
|
|
|
if( result.hasExpandedExpression() ) {
|
|
|
|
stream << "with expansion:\n";
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colourGuard( Colour::ReconstructedExpression );
|
2017-07-21 00:13:08 +02:00
|
|
|
stream << Column( result.getExpandedExpression() ).indent(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() )
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << messageLabel << ':' << '\n';
|
2017-04-25 12:41:30 +02:00
|
|
|
for( auto const& msg : messages ) {
|
2013-11-13 09:07:38 +01:00
|
|
|
// If this assertion is a warning ignore any INFO messages
|
2017-04-25 12:41:30 +02:00
|
|
|
if( printInfoMessages || msg.type != ResultWas::Info )
|
2017-07-21 00:13:08 +02:00
|
|
|
stream << Column( msg.message ).indent(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
|
|
|
|
2017-08-05 00:54:51 +02:00
|
|
|
m_tablePrinter.close();
|
|
|
|
lazyPrintWithoutClosingBenchmarkTable();
|
|
|
|
}
|
|
|
|
|
|
|
|
void lazyPrintWithoutClosingBenchmarkTable() {
|
|
|
|
|
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
|
|
|
}
|
|
|
|
void lazyPrintRunInfo() {
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\n' << getLineOfChars<'~'>() << '\n';
|
2013-04-05 08:59:28 +02:00
|
|
|
Colour colour( Colour::SecondaryText );
|
2013-08-08 09:24:37 +02:00
|
|
|
stream << currentTestRunInfo->name
|
2017-03-16 19:17:45 +01:00
|
|
|
<< " is a Catch v" << libraryVersion() << " host application.\n"
|
2013-01-14 19:51:49 +01:00
|
|
|
<< "Run with -? for options\n\n";
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2014-09-15 19:39:31 +02:00
|
|
|
if( m_config->rngSeed() != 0 )
|
|
|
|
stream << "Randomness seeded to: " << m_config->rngSeed() << "\n\n";
|
|
|
|
|
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
|
|
|
|
2017-07-18 09:08:17 +02:00
|
|
|
auto
|
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
|
|
|
|
2017-02-10 12:56:46 +01:00
|
|
|
SourceLineInfo lineInfo = m_sectionStack.back().lineInfo;
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-04-17 01:05:25 +02:00
|
|
|
if( !lineInfo.empty() ){
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << getLineOfChars<'-'>() << '\n';
|
2013-04-17 01:05:25 +02:00
|
|
|
Colour colourGuard( Colour::FileName );
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << lineInfo << '\n';
|
2013-04-17 01:05:25 +02:00
|
|
|
}
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << getLineOfChars<'.'>() << '\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 );
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << getLineOfChars<'.'>() << '\n';
|
2013-03-06 20:40:16 +01:00
|
|
|
}
|
2013-04-19 20:08:32 +02:00
|
|
|
void printOpenHeader( std::string const& _name ) {
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << getLineOfChars<'-'>() << '\n';
|
2013-04-01 12:25:54 +02:00
|
|
|
{
|
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;
|
2017-07-21 00:13:08 +02:00
|
|
|
stream << Column( _string ).indent( indent+i ).initialIndent( indent ) << '\n';
|
2013-04-05 21:55:57 +02:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2014-07-09 20:20:24 +02:00
|
|
|
struct SummaryColumn {
|
|
|
|
|
|
|
|
SummaryColumn( std::string const& _label, Colour::Code _colour )
|
|
|
|
: label( _label ),
|
|
|
|
colour( _colour )
|
|
|
|
{}
|
|
|
|
SummaryColumn addRow( std::size_t count ) {
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << count;
|
|
|
|
std::string row = oss.str();
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto& oldRow : rows ) {
|
|
|
|
while( oldRow.size() < row.size() )
|
|
|
|
oldRow = ' ' + oldRow;
|
|
|
|
while( oldRow.size() > row.size() )
|
2017-01-29 23:07:15 +01:00
|
|
|
row = ' ' + row;
|
2014-07-09 20:20:24 +02:00
|
|
|
}
|
|
|
|
rows.push_back( row );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string label;
|
|
|
|
Colour::Code colour;
|
|
|
|
std::vector<std::string> rows;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2014-07-03 09:09:57 +02:00
|
|
|
void printTotals( Totals const& totals ) {
|
2013-11-12 20:06:08 +01:00
|
|
|
if( totals.testCases.total() == 0 ) {
|
2014-07-03 09:09:57 +02:00
|
|
|
stream << Colour( Colour::Warning ) << "No tests ran\n";
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2016-03-14 20:13:34 +01:00
|
|
|
else if( totals.assertions.total() > 0 && totals.testCases.allPassed() ) {
|
2014-07-03 09:09:57 +02:00
|
|
|
stream << Colour( Colour::ResultSuccess ) << "All tests passed";
|
|
|
|
stream << " ("
|
2013-01-14 19:51:49 +01:00
|
|
|
<< pluralise( totals.assertions.passed, "assertion" ) << " in "
|
2017-01-29 23:07:15 +01:00
|
|
|
<< pluralise( totals.testCases.passed, "test case" ) << ')'
|
|
|
|
<< '\n';
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2014-07-09 20:20:24 +02:00
|
|
|
else {
|
|
|
|
|
|
|
|
std::vector<SummaryColumn> columns;
|
|
|
|
columns.push_back( SummaryColumn( "", Colour::None )
|
|
|
|
.addRow( totals.testCases.total() )
|
|
|
|
.addRow( totals.assertions.total() ) );
|
|
|
|
columns.push_back( SummaryColumn( "passed", Colour::Success )
|
|
|
|
.addRow( totals.testCases.passed )
|
|
|
|
.addRow( totals.assertions.passed ) );
|
|
|
|
columns.push_back( SummaryColumn( "failed", Colour::ResultError )
|
|
|
|
.addRow( totals.testCases.failed )
|
|
|
|
.addRow( totals.assertions.failed ) );
|
|
|
|
columns.push_back( SummaryColumn( "failed as expected", Colour::ResultExpectedFailure )
|
|
|
|
.addRow( totals.testCases.failedButOk )
|
|
|
|
.addRow( totals.assertions.failedButOk ) );
|
|
|
|
|
|
|
|
printSummaryRow( "test cases", columns, 0 );
|
|
|
|
printSummaryRow( "assertions", columns, 1 );
|
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2014-07-09 20:20:24 +02:00
|
|
|
void printSummaryRow( std::string const& label, std::vector<SummaryColumn> const& cols, std::size_t row ) {
|
2017-04-25 12:06:52 +02:00
|
|
|
for( auto col : cols ) {
|
|
|
|
std::string value = col.rows[row];
|
|
|
|
if( col.label.empty() ) {
|
2014-07-09 20:20:24 +02:00
|
|
|
stream << label << ": ";
|
|
|
|
if( value != "0" )
|
|
|
|
stream << value;
|
|
|
|
else
|
|
|
|
stream << Colour( Colour::Warning ) << "- none -";
|
|
|
|
}
|
|
|
|
else if( value != "0" ) {
|
|
|
|
stream << Colour( Colour::LightGrey ) << " | ";
|
2017-04-25 12:06:52 +02:00
|
|
|
stream << Colour( col.colour )
|
|
|
|
<< value << ' ' << col.label;
|
2014-07-09 20:20:24 +02:00
|
|
|
}
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\n';
|
2013-01-14 19:51:49 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2014-07-03 09:09:57 +02:00
|
|
|
void printTotalsDivider( Totals const& totals ) {
|
|
|
|
if( totals.testCases.total() > 0 ) {
|
|
|
|
std::size_t failedRatio = makeRatio( totals.testCases.failed, totals.testCases.total() );
|
|
|
|
std::size_t failedButOkRatio = makeRatio( totals.testCases.failedButOk, totals.testCases.total() );
|
|
|
|
std::size_t passedRatio = makeRatio( totals.testCases.passed, totals.testCases.total() );
|
|
|
|
while( failedRatio + failedButOkRatio + passedRatio < CATCH_CONFIG_CONSOLE_WIDTH-1 )
|
|
|
|
findMax( failedRatio, failedButOkRatio, passedRatio )++;
|
|
|
|
while( failedRatio + failedButOkRatio + passedRatio > CATCH_CONFIG_CONSOLE_WIDTH-1 )
|
|
|
|
findMax( failedRatio, failedButOkRatio, passedRatio )--;
|
|
|
|
|
|
|
|
stream << Colour( Colour::Error ) << std::string( failedRatio, '=' );
|
|
|
|
stream << Colour( Colour::ResultExpectedFailure ) << std::string( failedButOkRatio, '=' );
|
2014-07-09 19:24:24 +02:00
|
|
|
if( totals.testCases.allPassed() )
|
|
|
|
stream << Colour( Colour::ResultSuccess ) << std::string( passedRatio, '=' );
|
|
|
|
else
|
|
|
|
stream << Colour( Colour::Success ) << std::string( passedRatio, '=' );
|
2014-07-03 09:09:57 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
stream << Colour( Colour::Warning ) << std::string( CATCH_CONFIG_CONSOLE_WIDTH-1, '=' );
|
|
|
|
}
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << '\n';
|
2012-12-13 13:46:47 +01:00
|
|
|
}
|
2013-01-13 22:51:44 +01:00
|
|
|
void printSummaryDivider() {
|
2017-01-29 23:07:15 +01:00
|
|
|
stream << getLineOfChars<'-'>() << '\n';
|
2012-12-11 10:02:31 +01:00
|
|
|
}
|
2013-07-03 20:14:59 +02:00
|
|
|
|
2013-01-13 22:51:44 +01:00
|
|
|
private:
|
2017-04-25 19:56:53 +02:00
|
|
|
bool m_headerPrinted = false;
|
2012-12-05 09:40:53 +01:00
|
|
|
};
|
|
|
|
|
2017-08-17 18:07:24 +02:00
|
|
|
CATCH_REGISTER_REPORTER( "console", ConsoleReporter )
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
ConsoleReporter::~ConsoleReporter() {}
|
2012-12-05 09:40:53 +01:00
|
|
|
|
2017-07-10 11:33:18 +02:00
|
|
|
} // end namespace Catch
|