8#ifndef TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED
9#define TWOBLUECUBES_CATCH_REPORTER_TAP_HPP_INCLUDED
22 struct TAPReporter : StreamingReporterBase<TAPReporter> {
29 return "Reports test results in TAP format, suitable for test harnesses";
37 stream <<
"# No test cases matched '" << spec <<
"'" << std::endl;
46 AssertionPrinter printer(
stream, _assertionStats, counter );
54 printTotals( _testRunStats.
totals );
55 stream <<
"\n" << std::endl;
60 std::size_t counter = 0;
61 class AssertionPrinter {
63 AssertionPrinter& operator= ( AssertionPrinter
const& ) =
delete;
64 AssertionPrinter( AssertionPrinter
const& ) =
delete;
65 AssertionPrinter( std::ostream& _stream,
AssertionStats const& _stats, std::size_t _counter )
67 , result( _stats.assertionResult )
68 , messages( _stats.infoMessages )
69 , itMessage( _stats.infoMessages.begin() )
70 , printInfoMessages( true )
75 itMessage = messages.begin();
79 printResultType( passedString() );
80 printOriginalExpression();
81 printReconstructedExpression();
85 printRemainingMessages();
89 printResultType(passedString());
91 printResultType(failedString());
93 printOriginalExpression();
94 printReconstructedExpression();
96 printIssue(
" # TODO");
98 printRemainingMessages();
101 printResultType( failedString() );
102 printIssue(
"unexpected exception with message:" );
104 printExpressionWas();
105 printRemainingMessages();
108 printResultType( failedString() );
109 printIssue(
"fatal error condition with message:" );
111 printExpressionWas();
112 printRemainingMessages();
115 printResultType( failedString() );
116 printIssue(
"expected exception, got none" );
117 printExpressionWas();
118 printRemainingMessages();
121 printResultType(
"info" );
123 printRemainingMessages();
126 printResultType(
"warning" );
128 printRemainingMessages();
131 printResultType( failedString() );
132 printIssue(
"explicitly" );
139 printResultType(
"** internal error **" );
147 static const char* failedString() {
return "not ok"; }
148 static const char* passedString() {
return "ok"; }
150 void printSourceInfo()
const {
151 Colour colourGuard( dimColour() );
155 void printResultType( std::string
const& passOrFail )
const {
156 if( !passOrFail.empty() ) {
157 stream << passOrFail <<
' ' << counter <<
" -";
161 void printIssue( std::string
const& issue )
const {
162 stream <<
" " << issue;
165 void printExpressionWas() {
169 Colour colour( dimColour() );
170 stream <<
" expression was:";
172 printOriginalExpression();
176 void printOriginalExpression()
const {
182 void printReconstructedExpression()
const {
185 Colour colour( dimColour() );
189 std::replace( expr.begin(), expr.end(),
'\n',
' ');
194 void printMessage() {
195 if ( itMessage != messages.end() ) {
196 stream <<
" '" << itMessage->message <<
"'";
201 void printRemainingMessages(
Colour::Code colour = dimColour() ) {
202 if (itMessage == messages.end()) {
207 std::vector<MessageInfo>::const_iterator itEnd = messages.end();
208 const std::size_t
N =
static_cast<std::size_t
>( std::distance( itMessage, itEnd ) );
211 Colour colourGuard( colour );
212 stream <<
" with " << pluralise(
N,
"message" ) <<
":";
215 for(; itMessage != itEnd; ) {
218 stream <<
" '" << itMessage->message <<
"'";
219 if ( ++itMessage != itEnd ) {
220 Colour colourGuard( dimColour() );
228 std::ostream& stream;
229 AssertionResult
const& result;
230 std::vector<MessageInfo> messages;
231 std::vector<MessageInfo>::const_iterator itMessage;
232 bool printInfoMessages;
236 void printTotals(
const Totals& totals )
const {
237 if( totals.testCases.total() == 0 ) {
238 stream <<
"1..0 # Skipped: No tests ran.";
240 stream <<
"1.." << counter;
#define CATCH_REGISTER_REPORTER(name, reporterType)
std::string getExpression() const
bool hasExpandedExpression() const
SourceLineInfo getSourceInfo() const
std::string getExpandedExpression() const
bool hasExpression() const
ResultWas::OfType getResultType() const
void testRunEnded(TestRunStats const &) override
LazyStat< TestCaseInfo > currentTestCaseInfo
StreamingReporterBase(ReporterConfig const &_config)
ReporterPreferences m_reporterPrefs
ReporterPreferences getPreferences() const override
static std::string getDescription()
void testRunEnded(TestRunStats const &_testRunStats) override
void noMatchingTestCases(std::string const &spec) override
bool assertionEnded(AssertionStats const &_assertionStats) override
void assertionStarting(AssertionInfo const &) override