~blep/cppunit2/cpptl-integration

« back to all changes in this revision

Viewing changes to src/cpput/lighttestrunner.cpp

  • Committer: Baptiste Lepilleur
  • Date: 2009-08-27 17:50:15 UTC
  • mfrom: (467.1.2 cpptl-integration)
  • Revision ID: blep@users.sourceforge.net-20090827175015-op04km4ev3b2x0f5
sync.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
#include <cpptl/stringtools.h>
5
5
#include <stdio.h>
6
6
 
 
7
namespace {
 
8
   class Reindenter
 
9
   {
 
10
   public:
 
11
      Reindenter( CppTL::StringBuffer &text )
 
12
         : text_( text )
 
13
         , pos_( text.length() )
 
14
      {
 
15
      }
 
16
 
 
17
      void apply( const std::string &indent )
 
18
      {
 
19
         CppTL::ConstString textToIndex = text_.substr( pos_ );
 
20
         if ( !textToIndex.empty() )
 
21
         {
 
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 )
 
27
            {
 
28
               if ( it[-1] == '\n' )
 
29
               {
 
30
                  text_ += indent;
 
31
                  text_ += CppTL::ConstCharView( sliceBegin, it );
 
32
                  sliceBegin = it;
 
33
               }
 
34
            }
 
35
         }
 
36
      }
 
37
 
 
38
   private:
 
39
      CppTL::StringBuffer &text_;
 
40
      CppTL::StringBuffer::size_type pos_;
 
41
   };
 
42
} // end anonymous namespace
 
43
 
7
44
namespace CppUT {
8
45
 
9
46
LightTestRunner::LightTestRunner()
213
250
      ++ignoredFailureCount_;
214
251
   }
215
252
   report_ += "[failure type: " + failureType + "]\n";
216
 
   const Json::Value &detail = failure.detail();
 
253
   reportFailureDetail( failure.detail(), "" );
 
254
   report_ += "\n";
 
255
}
 
256
 
 
257
 
 
258
void 
 
259
LightTestRunner::reportFailureDetail( const Json::Value &detail, 
 
260
                                      const std::string &detailName,
 
261
                                      int nestingLevel )
 
262
{
 
263
   Reindenter reindenter( report_ );
 
264
   // Predicate name if any
 
265
   if ( !detail["name"].isNull() )
 
266
   {
 
267
      report_ += "predicate";
 
268
      //if ( !detailName.empty() )
 
269
      //   report_ += " " + detailName; 
 
270
      report_ += ": " + detail["name"].asString() + "\n";
 
271
   }
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 )
221
276
   {
222
 
      report_ += "Messages:\n";
 
277
      report_ += nbMessage > 1 ? "Messages:\n"
 
278
                               : "Message: ";
223
279
      for ( int index = 0; index < nbMessage; ++index )
224
280
         report_ += messages[index].asString() + "\n";
225
281
   }
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();
244
297
      report_ += ": ";
245
298
      // @todo nice conversion to string
246
299
      report_ += data[index]["value"].toStyledString();
 
300
      if ( report_[report_.length()-1] != '\n' )
 
301
         report_ += "\n";
 
302
   }
 
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 )
 
307
   {
 
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;
247
314
      report_ += "\n";
248
 
   }
249
 
   report_ += "\n";
 
315
      reportFailureDetail( compositeDetail, compositeName, nestingLevel + 1 );
 
316
   }
 
317
   if ( nestingLevel > 0 )
 
318
   {
 
319
      reindenter.apply( std::string( 2, ' ' ) );
 
320
   }
250
321
}
251
322
 
252
323