Fixed-up TAP reporter a bit.

This commit is contained in:
Martin Hořeňovský 2017-02-22 13:28:13 +01:00
parent a63ce953a0
commit b0260c615d
2 changed files with 44 additions and 70 deletions

View File

@ -216,6 +216,7 @@ set(REPORTER_HEADERS
${HEADER_DIR}/reporters/catch_reporter_console.hpp ${HEADER_DIR}/reporters/catch_reporter_console.hpp
${HEADER_DIR}/reporters/catch_reporter_junit.hpp ${HEADER_DIR}/reporters/catch_reporter_junit.hpp
${HEADER_DIR}/reporters/catch_reporter_multi.hpp ${HEADER_DIR}/reporters/catch_reporter_multi.hpp
${HEADER_DIR}/reporters/catch_reporter_tap.hpp
${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp ${HEADER_DIR}/reporters/catch_reporter_teamcity.hpp
${HEADER_DIR}/reporters/catch_reporter_xml.hpp ${HEADER_DIR}/reporters/catch_reporter_xml.hpp
) )

View File

@ -1,6 +1,6 @@
/* /*
* Created by Martin Moene on 2013-12-05. * Created by Colton Wolkins on 2015-08-15.
* Copyright 2012 Martin Moene. All rights reserved. * Copyright 2015 Martin Moene. All rights reserved.
* *
* Distributed under the Boost Software License, Version 1.0. (See accompanying * 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) * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
@ -8,11 +8,14 @@
#ifndef TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED #ifndef TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED
#define TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED #define TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED
#include "catch_reporter_bases.hpp"
#include <algorithm>
#include "../internal/catch_reporter_registrars.hpp" // Don't #include any Catch headers here - we can assume they are already
#include "../internal/catch_console_colour.hpp" // included before this header.
// This is not good practice in general but is necessary in this case so this
// file can be distributed as a single header that works with the main
// Catch single header.
#include <algorithm>
namespace Catch { namespace Catch {
@ -38,8 +41,7 @@ namespace Catch {
stream << "# No test cases matched '" << spec << "'" << std::endl; stream << "# No test cases matched '" << spec << "'" << std::endl;
} }
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; AssertionResult const& result = _assertionStats.assertionResult;
@ -47,15 +49,15 @@ namespace Catch {
bool printInfoMessages = true; bool printInfoMessages = true;
// Drop out if result was successful and we're not printing those // Drop out if result was successful and we're not printing those
if( !m_config->includeSuccessfulResults() && result.isOk() ) { if ( !m_config->includeSuccessfulResults() && result.isOk() ) {
if( result.getResultType() != ResultWas::Warning ) if ( result.getResultType() != ResultWas::Warning )
return false; return false;
printInfoMessages = false; printInfoMessages = false;
} }
AssertionPrinter printer( stream, _assertionStats, printInfoMessages, ++counter ); AssertionPrinter printer( stream, _assertionStats, printInfoMessages, ++counter );
printer.print(); printer.print();
stream << " # " << currentTestCaseInfo->name ; stream << " # " << currentTestCaseInfo->name ;
stream << std::endl; stream << std::endl;
return true; return true;
@ -68,7 +70,7 @@ namespace Catch {
} }
private: private:
size_t counter = 0; size_t counter = 0;
class AssertionPrinter { class AssertionPrinter {
void operator= ( AssertionPrinter const& ); void operator= ( AssertionPrinter const& );
public: public:
@ -79,67 +81,67 @@ namespace Catch {
, messages( _stats.infoMessages ) , messages( _stats.infoMessages )
, itMessage( _stats.infoMessages.begin() ) , itMessage( _stats.infoMessages.begin() )
, printInfoMessages( _printInfoMessages ) , printInfoMessages( _printInfoMessages )
, counter(counter) , counter(counter)
{} {}
void print() { void print() {
//printSourceInfo();
itMessage = messages.begin(); itMessage = messages.begin();
switch( result.getResultType() ) { switch( result.getResultType() ) {
case ResultWas::Ok: case ResultWas::Ok:
printResultType( Colour::ResultSuccess, passedString() ); printResultType( passedString() );
printOriginalExpression(); printOriginalExpression();
//printReconstructedExpression(); printReconstructedExpression();
if ( ! result.hasExpression() ) if ( ! result.hasExpression() )
printRemainingMessages( Colour::None ); printRemainingMessages( Colour::None );
else else
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::ExpressionFailed: case ResultWas::ExpressionFailed:
//if( result.isOk() ) if (result.isOk()) {
// printResultType( Colour::ResultSuccess, failedString() + std::string( " # TODO" ) ); printResultType(passedString());
//else } else {
printResultType( Colour::Error, failedString() ); printResultType(failedString());
}
printOriginalExpression(); printOriginalExpression();
//printReconstructedExpression(); printReconstructedExpression();
if( result.isOk() ) if (result.isOk()) {
printIssue( " # TODO" ); printIssue(" # TODO");
}
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::ThrewException: case ResultWas::ThrewException:
printResultType( Colour::Error, failedString() ); printResultType( failedString() );
printIssue( "unexpected exception with message:" ); printIssue( "unexpected exception with message:" );
printMessage(); printMessage();
printExpressionWas(); printExpressionWas();
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::FatalErrorCondition: case ResultWas::FatalErrorCondition:
printResultType( Colour::Error, failedString() ); printResultType( failedString() );
printIssue( "fatal error condition with message:" ); printIssue( "fatal error condition with message:" );
printMessage(); printMessage();
printExpressionWas(); printExpressionWas();
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::DidntThrowException: case ResultWas::DidntThrowException:
printResultType( Colour::Error, failedString() ); printResultType( failedString() );
printIssue( "expected exception, got none" ); printIssue( "expected exception, got none" );
printExpressionWas(); printExpressionWas();
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::Info: case ResultWas::Info:
printResultType( Colour::None, "info" ); printResultType( "info" );
printMessage(); printMessage();
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::Warning: case ResultWas::Warning:
printResultType( Colour::None, "warning" ); printResultType( "warning" );
printMessage(); printMessage();
printRemainingMessages(); printRemainingMessages();
break; break;
case ResultWas::ExplicitFailure: case ResultWas::ExplicitFailure:
printResultType( Colour::Error, failedString() ); printResultType( failedString() );
printIssue( "explicitly" ); printIssue( "explicitly" );
printRemainingMessages( Colour::None ); printRemainingMessages( Colour::None );
break; break;
@ -147,13 +149,12 @@ namespace Catch {
case ResultWas::Unknown: case ResultWas::Unknown:
case ResultWas::FailureBit: case ResultWas::FailureBit:
case ResultWas::Exception: case ResultWas::Exception:
printResultType( Colour::Error, "** internal error **" ); printResultType( "** internal error **" );
break; break;
} }
} }
private: private:
// Colour::LightGrey
static Colour::Code dimColour() { return Colour::FileName; } static Colour::Code dimColour() { return Colour::FileName; }
@ -165,7 +166,7 @@ namespace Catch {
stream << result.getSourceInfo() << ":"; stream << result.getSourceInfo() << ":";
} }
void printResultType( Colour::Code colour, std::string passOrFail ) const { void printResultType( std::string passOrFail ) const {
if( !passOrFail.empty() ) { if( !passOrFail.empty() ) {
{ {
//Colour colourGuard( colour ); //Colour colourGuard( colour );
@ -202,8 +203,8 @@ namespace Catch {
Colour colour( dimColour() ); Colour colour( dimColour() );
stream << " for: "; stream << " for: ";
} }
std::string expr = result.getExpandedExpression(); std::string expr = result.getExpandedExpression();
std::replace( expr.begin(), expr.end(), '\n', ' '); std::replace( expr.begin(), expr.end(), '\n', ' ');
stream << expr; stream << expr;
} }
} }
@ -247,7 +248,7 @@ namespace Catch {
std::vector<MessageInfo> messages; std::vector<MessageInfo> messages;
std::vector<MessageInfo>::const_iterator itMessage; std::vector<MessageInfo>::const_iterator itMessage;
bool printInfoMessages; bool printInfoMessages;
size_t counter; size_t counter;
}; };
// Colour, message variants: // Colour, message variants:
@ -264,44 +265,16 @@ namespace Catch {
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.";
//stream << "No tests ran."; } else {
}
else {
stream << "1.." << counter; stream << "1.." << counter;
} }
//else if( totals.testCases.failed == totals.testCases.total() ) {
// Colour colour( Colour::ResultError );
// const std::string qualify_assertions_failed =
// totals.assertions.failed == totals.assertions.total() ?
// bothOrAll( totals.assertions.failed ) : "";
// stream <<
// "Failed " << bothOrAll( totals.testCases.failed )
// << pluralise( totals.testCases.failed, "test case" ) << ", "
// "failed " << qualify_assertions_failed <<
// pluralise( totals.assertions.failed, "assertion" ) << ".";
//}
//else if( totals.assertions.total() == 0 ) {
// stream <<
// "Passed " << bothOrAll( totals.testCases.total() )
// << pluralise( totals.testCases.total(), "test case" )
// << " (no assertions).";
//}
//else if( totals.assertions.failed ) {
// Colour colour( Colour::ResultError );
// stream <<
// "Failed " << pluralise( totals.testCases.failed, "test case" ) << ", "
// "failed " << pluralise( totals.assertions.failed, "assertion" ) << ".";
//}
//else {
// Colour colour( Colour::ResultSuccess );
// stream <<
// "Passed " << bothOrAll( totals.testCases.passed )
// << pluralise( totals.testCases.passed, "test case" ) <<
// " with " << pluralise( totals.assertions.passed, "assertion" ) << ".";
//}
} }
}; };
#ifdef CATCH_IMPL
TAPReporter::~TAPReporter() {}
#endif
INTERNAL_CATCH_REGISTER_REPORTER( "tap", TAPReporter ) INTERNAL_CATCH_REGISTER_REPORTER( "tap", TAPReporter )
} // end namespace Catch } // end namespace Catch