PageRenderTime 51ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/python/python3/cxxtest/cxxtest_fog.py

https://github.com/kindkaktus/cxxtest
Python | 99 lines | 68 code | 8 blank | 23 comment | 16 complexity | a9e57d191d53236c455c4795b28e8d12 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. import sys
  14. import re
  15. from .cxxtest_misc import abort
  16. from . import cxx_parser
  17. import re
  18. def cstr( str ):
  19. '''Convert a string to its C representation'''
  20. return '"' + re.sub('\\\\', '\\\\\\\\', str ) + '"'
  21. def scanInputFiles(files, _options):
  22. '''Scan all input files for test suites'''
  23. suites=[]
  24. for file in files:
  25. try:
  26. print("Parsing file "+file, end=' ')
  27. sys.stdout.flush()
  28. parse_info = cxx_parser.parse_cpp(filename=file,optimize=1)
  29. except IOError as err:
  30. print(" error.")
  31. print(str(err))
  32. continue
  33. print("done.")
  34. sys.stdout.flush()
  35. #
  36. # WEH: see if it really makes sense to use parse information to
  37. # initialize this data. I don't think so...
  38. #
  39. _options.haveStandardLibrary=1
  40. if not parse_info.noExceptionLogic:
  41. _options.haveExceptionHandling=1
  42. #
  43. keys = list(parse_info.index.keys())
  44. tpat = re.compile("[Tt][Ee][Ss][Tt]")
  45. for key in keys:
  46. if parse_info.index[key].scope_t == "class" and parse_info.is_baseclass(key,"CxxTest::TestSuite"):
  47. name=parse_info.index[key].name
  48. if key.startswith('::'):
  49. fullname = key[2:]
  50. else:
  51. fullname = key
  52. suite = {
  53. 'fullname' : fullname,
  54. 'name' : name,
  55. 'file' : file,
  56. 'cfile' : cstr(file),
  57. 'line' : str(parse_info.index[key].lineno),
  58. 'generated' : 0,
  59. 'object' : 'suite_%s' % fullname.replace('::','_'),
  60. 'dobject' : 'suiteDescription_%s' % fullname.replace('::','_'),
  61. 'tlist' : 'Tests_%s' % fullname.replace('::','_'),
  62. 'tests' : [],
  63. 'lines' : [] }
  64. for fn in parse_info.get_functions(key,quiet=True):
  65. tname = fn[0]
  66. lineno = str(fn[1])
  67. if tname.startswith('createSuite'):
  68. # Indicate that we're using a dynamically generated test suite
  69. suite['create'] = str(lineno) # (unknown line)
  70. if tname.startswith('destroySuite'):
  71. # Indicate that we're using a dynamically generated test suite
  72. suite['destroy'] = str(lineno) # (unknown line)
  73. if not tpat.match(tname):
  74. # Skip non-test methods
  75. continue
  76. test = { 'name' : tname,
  77. 'suite' : suite,
  78. 'class' : 'TestDescription_suite_%s_%s' % (suite['fullname'].replace('::','_'), tname),
  79. 'object' : 'testDescription_suite_%s_%s' % (suite['fullname'].replace('::','_'), tname),
  80. 'line' : lineno,
  81. }
  82. suite['tests'].append(test)
  83. suites.append(suite)
  84. if not _options.root:
  85. ntests = 0
  86. for suite in suites:
  87. ntests += len(suite['tests'])
  88. if ntests == 0:
  89. abort( 'No tests defined' )
  90. #
  91. return [_options, suites]