4
4
#include <cpptl/stringtools.h>
11
Reindenter( CppTL::StringBuffer &text )
13
, pos_( text.length() )
17
void apply( const std::string &indent )
19
CppTL::ConstString textToIndex = text_.substr( pos_ );
20
if ( !textToIndex.empty() )
22
text_.truncate( pos_ );
23
const char *it = textToIndex.c_str();
24
const char *itEnd = textToIndex.end_c_str();
25
const char *sliceBegin = it;
26
for ( ++it; it <= itEnd; ++it )
31
text_ += CppTL::ConstCharView( sliceBegin, it );
39
CppTL::StringBuffer &text_;
40
CppTL::StringBuffer::size_type pos_;
42
} // end anonymous namespace
9
46
LightTestRunner::LightTestRunner()
213
250
++ignoredFailureCount_;
215
252
report_ += "[failure type: " + failureType + "]\n";
216
const Json::Value &detail = failure.detail();
253
reportFailureDetail( failure.detail(), "" );
259
LightTestRunner::reportFailureDetail( const Json::Value &detail,
260
const std::string &detailName,
263
Reindenter reindenter( report_ );
264
// Predicate name if any
265
if ( !detail["name"].isNull() )
267
report_ += "predicate";
268
//if ( !detailName.empty() )
269
// report_ += " " + detailName;
270
report_ += ": " + detail["name"].asString() + "\n";
217
272
// Get assertion messages
218
273
const Json::Value &messages = detail["message"];
219
274
const int nbMessage = messages.size();
220
275
if ( nbMessage > 0 )
222
report_ += "Messages:\n";
277
report_ += nbMessage > 1 ? "Messages:\n"
223
279
for ( int index = 0; index < nbMessage; ++index )
224
280
report_ += messages[index].asString() + "\n";
226
// Predicate name if any
227
if ( !detail["name"].isNull() )
228
report_ += "predicate: " + detail["name"].asString() + "\n";
229
282
// Compute max data name length
230
283
const Json::Value &data = detail["data"];
231
284
int nbDetailData = data.size();
245
298
// @todo nice conversion to string
246
299
report_ += data[index]["value"].toStyledString();
300
if ( report_[report_.length()-1] != '\n' )
303
// Reports composite assertions
304
const Json::Value &composites = detail["composite"];
305
const Json::Value::UInt nbComposite = composites.size();
306
for ( Json::Value::UInt indexComposite = 0; indexComposite < nbComposite; ++indexComposite )
308
const Json::Value &composite = composites[indexComposite];
309
CPPTL_ASSERT_MESSAGE( composite.size() == 1, "Composite must have a name" );
310
const char *compositeName = composite.begin().memberName();
311
const Json::Value &compositeDetail = *(composite.begin());
312
report_ += "context: ";
313
report_ += compositeName;
315
reportFailureDetail( compositeDetail, compositeName, nestingLevel + 1 );
317
if ( nestingLevel > 0 )
319
reindenter.apply( std::string( 2, ' ' ) );