Lines Matching defs:suite

31 suite = None
196 global suite
197 if suite:
198 scanLineInsideSuite( suite, lineNo, line )
200 def scanLineInsideSuite( suite, lineNo, line ):
201 '''Analyze line which is part of a suite'''
203 if lineBelongsToSuite( suite, lineNo, line ):
204 scanLineForTest( suite, lineNo, line )
205 scanLineForCreate( suite, lineNo, line )
206 scanLineForDestroy( suite, lineNo, line )
208 def lineBelongsToSuite( suite, lineNo, line ):
209 '''Returns whether current line is part of the current suite.
210 This can be false when we are in a generated suite outside of CXXTEST_CODE() blocks
211 If the suite is generated, adds the line to the list of lines'''
212 if not suite['generated']:
219 inBlock = addLineToBlock( suite, lineNo, line )
242 '''Check if current line starts a new test suite'''
252 '''Start scanning a new suite'''
253 global suite
255 suite = { 'name' : name,
271 def scanLineForTest( suite, lineNo, line ):
275 addTest( suite, m.group(2), lineNo )
277 def addTest( suite, name, line ):
278 '''Add a test function to the current suite'''
280 'suite' : suite,
281 'class' : 'TestDescription_%s_%s' % (suite['name'], name),
282 'object' : 'testDescription_%s_%s' % (suite['name'], name),
285 suite['tests'].append( test )
287 def addLineToBlock( suite, lineNo, line ):
289 line = fixBlockLine( suite, lineNo, line )
295 suite['lines'].append( line )
298 def fixBlockLine( suite, lineNo, line):
301 r'_\1(%s,%s,' % (suite['cfile'], lineNo),
305 def scanLineForCreate( suite, lineNo, line ):
308 addSuiteCreateDestroy( suite, 'create', lineNo )
311 def scanLineForDestroy( suite, lineNo, line ):
314 addSuiteCreateDestroy( suite, 'destroy', lineNo )
321 def addSuiteCreateDestroy( suite, which, line ):
322 '''Add createSuite()/destroySuite() to current suite'''
323 if suite.has_key(which):
324 abort( '%s:%s: %sSuite() already declared' % ( suite['file'], str(line), which ) )
325 suite[which] = line
328 '''Close current suite and add it to the list if valid'''
329 global suite
330 if suite is not None:
331 if len(suite['tests']) is not 0:
332 verifySuite(suite)
333 rememberSuite(suite)
334 suite = None
336 def verifySuite(suite):
337 '''Verify current suite is legal'''
338 if suite.has_key('create') and not suite.has_key('destroy'):
340 (suite['file'], suite['create'], suite['name']) )
341 if suite.has_key('destroy') and not suite.has_key('create'):
343 (suite['file'], suite['destroy'], suite['name']) )
345 def rememberSuite(suite):
346 '''Add current suite to list'''
348 suites.append( suite )
459 for suite in suites:
460 writeInclude( output, suite['file'] )
461 if isGenerated(suite):
462 generateSuite( output, suite )
463 if isDynamic(suite):
464 writeSuitePointer( output, suite )
466 writeSuiteObject( output, suite )
467 writeTestList( output, suite )
468 writeSuiteDescription( output, suite )
469 writeTestDescriptions( output, suite )
471 def isGenerated(suite):
472 '''Checks whether a suite class should be created'''
473 return suite['generated']
475 def isDynamic(suite):
476 '''Checks whether a suite is dynamic'''
477 return suite.has_key('create')
487 def generateSuite( output, suite ):
488 '''Write a suite declared with CXXTEST_SUITE()'''
489 output.write( 'class %s : public CxxTest::TestSuite {\n' % suite['name'] )
491 for line in suite['lines']:
495 def writeSuitePointer( output, suite ):
496 '''Create static suite pointer object for dynamic suites'''
498 output.write( 'static %s *%s;\n\n' % (suite['name'], suite['object']) )
500 output.write( 'static %s *%s = 0;\n\n' % (suite['name'], suite['object']) )
502 def writeSuiteObject( output, suite ):
503 '''Create static suite object for non-dynamic suites'''
504 output.writelines( [ "static ", suite['name'], " ", suite['object'], ";\n\n" ] )
506 def writeTestList( output, suite ):
507 '''Write the head of the test linked list for a suite'''
509 output.write( 'static CxxTest::List %s;\n' % suite['tlist'] )
511 output.write( 'static CxxTest::List %s = { 0, 0 };\n' % suite['tlist'] )
513 def writeTestDescriptions( output, suite ):
514 '''Write all test descriptions for a suite'''
515 for test in suite['tests']:
516 writeTestDescription( output, suite, test )
518 def writeTestDescription( output, suite, test ):
524 (test['class'], suite['tlist'], suite['dobject'], test['line'], test['name']) )
525 output.write( ' void runTest() { %s }\n' % runBody( suite, test ) )
528 def runBody( suite, test ):
530 if isDynamic(suite): return dynamicRun( suite, test )
531 else: return staticRun( suite, test )
533 def dynamicRun( suite, test ):
534 '''Body of TestDescription::run() for test in a dynamic suite'''
535 return 'if ( ' + suite['object'] + ' ) ' + suite['object'] + '->' + test['name'] + '();'
537 def staticRun( suite, test ):
538 '''Body of TestDescription::run() for test in a non-dynamic suite'''
539 return suite['object'] + '.' + test['name'] + '();'
541 def writeSuiteDescription( output, suite ):
543 if isDynamic( suite ):
544 writeDynamicDescription( output, suite )
546 writeStaticDescription( output, suite )
548 def writeDynamicDescription( output, suite ):
549 '''Write SuiteDescription for a dynamic suite'''
550 output.write( 'CxxTest::DynamicSuiteDescription<%s> %s' % (suite['name'], suite['dobject']) )
553 (suite['cfile'], suite['line'], suite['name'], suite['tlist'],
554 suite['object'], suite['create'], suite['destroy']) )
557 def writeStaticDescription( output, suite ):
558 '''Write SuiteDescription for a static suite'''
559 output.write( 'CxxTest::StaticSuiteDescription %s' % suite['dobject'] )
562 (suite['cfile'], suite['line'], suite['name'], suite['object'], suite['tlist']) )
574 for suite in suites:
575 output.write( ' %s.initialize();\n' % suite['tlist'] )
576 if isDynamic(suite):
577 output.write( ' %s = 0;\n' % suite['object'] )
579 (suite['dobject'], suite['cfile'], suite['line'], suite['name'],
580 suite['tlist'], suite['object'], suite['create'], suite['destroy']) )
583 (suite['dobject'], suite['cfile'], suite['line'], suite['name'],
584 suite['object'], suite['tlist']) )
586 for test in suite['tests']:
588 (test['object'], suite['tlist'], suite['dobject'], test['line'], test['name']) )