TAP reporter now behaves as if -s was always set

This should fulfill the TAP specification better.
This commit is contained in:
Martin Hořeňovský 2017-03-02 15:54:08 +01:00
parent 0b28d3daf2
commit 95b0eb2b6c
1 changed files with 7 additions and 32 deletions

View File

@ -45,19 +45,9 @@ namespace Catch {
virtual void assertionStarting( AssertionInfo const& ) {} virtual void assertionStarting( AssertionInfo const& ) {}
virtual bool assertionEnded( AssertionStats const& _assertionStats ) { virtual bool assertionEnded( AssertionStats const& _assertionStats ) {
AssertionResult const& result = _assertionStats.assertionResult;
++counter; ++counter;
bool printInfoMessages = true; AssertionPrinter printer( stream, _assertionStats, counter );
// Drop out if result was successful and we're not printing those
if ( !m_config->includeSuccessfulResults() && result.isOk() ) {
if ( result.getResultType() != ResultWas::Warning )
return false;
printInfoMessages = false;
}
AssertionPrinter printer( stream, _assertionStats, printInfoMessages, counter );
printer.print(); printer.print();
stream << " # " << currentTestCaseInfo->name ; stream << " # " << currentTestCaseInfo->name ;
@ -76,13 +66,13 @@ namespace Catch {
class AssertionPrinter { class AssertionPrinter {
void operator= ( AssertionPrinter const& ); void operator= ( AssertionPrinter const& );
public: public:
AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, bool _printInfoMessages, size_t counter ) AssertionPrinter( std::ostream& _stream, AssertionStats const& _stats, size_t counter )
: stream( _stream ) : stream( _stream )
, stats( _stats ) , stats( _stats )
, result( _stats.assertionResult ) , result( _stats.assertionResult )
, messages( _stats.infoMessages ) , messages( _stats.infoMessages )
, itMessage( _stats.infoMessages.begin() ) , itMessage( _stats.infoMessages.begin() )
, printInfoMessages( _printInfoMessages ) , printInfoMessages( true )
, counter(counter) , counter(counter)
{} {}
@ -157,24 +147,19 @@ namespace Catch {
} }
private: private:
static Colour::Code dimColour() { return Colour::FileName; } static Colour::Code dimColour() { return Colour::FileName; }
static const char* failedString() { return "not ok"; } static const char* failedString() { return "not ok"; }
static const char* passedString() { return "ok"; } static const char* passedString() { return "ok"; }
void printSourceInfo() const { void printSourceInfo() const {
Colour colourGuard( Colour::FileName ); Colour colourGuard( dimColour() );
stream << result.getSourceInfo() << ":"; stream << result.getSourceInfo() << ":";
} }
void printResultType( std::string passOrFail ) const { void printResultType( std::string passOrFail ) const {
if( !passOrFail.empty() ) { if( !passOrFail.empty() ) {
{ stream << passOrFail << ' ' << counter << " -";
//Colour colourGuard( colour );
stream << passOrFail << " " << counter;
}
stream << " -";
} }
} }
@ -219,8 +204,9 @@ namespace Catch {
} }
void printRemainingMessages( Colour::Code colour = dimColour() ) { void printRemainingMessages( Colour::Code colour = dimColour() ) {
if ( itMessage == messages.end() ) if (itMessage == messages.end()) {
return; return;
}
// using messages.end() directly yields compilation error: // using messages.end() directly yields compilation error:
std::vector<MessageInfo>::const_iterator itEnd = messages.end(); std::vector<MessageInfo>::const_iterator itEnd = messages.end();
@ -253,17 +239,6 @@ namespace Catch {
size_t counter; size_t counter;
}; };
// Colour, message variants:
// - white: No tests ran.
// - red: Failed [both/all] N test cases, failed [both/all] M assertions.
// - white: Passed [both/all] N test cases (no assertions).
// - red: Failed N tests cases, failed M assertions.
// - green: Passed [both/all] N tests cases with M assertions.
std::string bothOrAll( std::size_t count ) const {
return count == 1 ? "" : count == 2 ? "both " : "all " ;
}
void printTotals( const Totals& totals ) const { void printTotals( const Totals& totals ) const {
if( totals.testCases.total() == 0 ) { if( totals.testCases.total() == 0 ) {
stream << "1..0 # Skipped: No tests ran."; stream << "1..0 # Skipped: No tests ran.";