PageRenderTime 48ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/python/cxxtest/cxxtest_fog.py

https://github.com/kindkaktus/cxxtest
Python | 99 lines | 69 code | 7 blank | 23 comment | 16 complexity | 5d3ddabbd6752704c7537fcedb7edccb MD5 | raw file
Possible License(s): LGPL-3.0
  1. #-------------------------------------------------------------------------
  2. # CxxTest: A lightweight C++ unit testing library.
  3. # Copyright (c) 2008 Sandia Corporation.
  4. # This software is distributed under the LGPL License v3
  5. # For more information, see the COPYING file in the top CxxTest directory.
  6. # Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
  7. # the U.S. Government retains certain rights in this software.
  8. #-------------------------------------------------------------------------
  9. #
  10. # TODO: add line number info
  11. # TODO: add test function names
  12. #
  13. from __future__ import division
  14. import sys
  15. import re
  16. from cxxtest_misc import abort
  17. import cxx_parser
  18. import re
  19. def cstr( str ):
  20. '''Convert a string to its C representation'''
  21. return '"' + re.sub('\\\\', '\\\\\\\\', str ) + '"'
  22. def scanInputFiles(files, _options):
  23. '''Scan all input files for test suites'''
  24. suites=[]
  25. for file in files:
  26. try:
  27. print "Parsing file "+file,
  28. sys.stdout.flush()
  29. parse_info = cxx_parser.parse_cpp(filename=file,optimize=1)
  30. except IOError, err:
  31. print " error."
  32. print str(err)
  33. continue
  34. print "done."
  35. sys.stdout.flush()
  36. #
  37. # WEH: see if it really makes sense to use parse information to
  38. # initialize this data. I don't think so...
  39. #
  40. _options.haveStandardLibrary=1
  41. if not parse_info.noExceptionLogic:
  42. _options.haveExceptionHandling=1
  43. #
  44. keys = list(parse_info.index.keys())
  45. tpat = re.compile("[Tt][Ee][Ss][Tt]")
  46. for key in keys:
  47. if parse_info.index[key].scope_t == "class" and parse_info.is_baseclass(key,"CxxTest::TestSuite"):
  48. name=parse_info.index[key].name
  49. if key.startswith('::'):
  50. fullname = key[2:]
  51. else:
  52. fullname = key
  53. suite = {
  54. 'fullname' : fullname,
  55. 'name' : name,
  56. 'file' : file,
  57. 'cfile' : cstr(file),
  58. 'line' : str(parse_info.index[key].lineno),
  59. 'generated' : 0,
  60. 'object' : 'suite_%s' % fullname.replace('::','_'),
  61. 'dobject' : 'suiteDescription_%s' % fullname.replace('::','_'),
  62. 'tlist' : 'Tests_%s' % fullname.replace('::','_'),
  63. 'tests' : [],
  64. 'lines' : [] }
  65. for fn in parse_info.get_functions(key,quiet=True):
  66. tname = fn[0]
  67. lineno = str(fn[1])
  68. if tname.startswith('createSuite'):
  69. # Indicate that we're using a dynamically generated test suite
  70. suite['create'] = str(lineno) # (unknown line)
  71. if tname.startswith('destroySuite'):
  72. # Indicate that we're using a dynamically generated test suite
  73. suite['destroy'] = str(lineno) # (unknown line)
  74. if not tpat.match(tname):
  75. # Skip non-test methods
  76. continue
  77. test = { 'name' : tname,
  78. 'suite' : suite,
  79. 'class' : 'TestDescription_suite_%s_%s' % (suite['fullname'].replace('::','_'), tname),
  80. 'object' : 'testDescription_suite_%s_%s' % (suite['fullname'].replace('::','_'), tname),
  81. 'line' : lineno,
  82. }
  83. suite['tests'].append(test)
  84. suites.append(suite)
  85. if not _options.root:
  86. ntests = 0
  87. for suite in suites:
  88. ntests += len(suite['tests'])
  89. if ntests == 0:
  90. abort( 'No tests defined' )
  91. #
  92. return [_options, suites]