extracttests.py: added option to output test files

This commit is contained in:
Daniel Marjamäki 2011-11-28 22:17:06 +01:00
parent be0acad11f
commit 7624313808
1 changed files with 34 additions and 1 deletions

View File

@ -126,18 +126,21 @@ def writeHtmlFile(nodes, functionName, filename, errorsOnly):
if len(sys.argv) <= 1 or '--help' in sys.argv: if len(sys.argv) <= 1 or '--help' in sys.argv:
print 'Extract test cases from test file' print 'Extract test cases from test file'
print 'Syntax: extracttests.py [--html=folder] [--xml] path/testfile.cpp' print 'Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] path/testfile.cpp'
sys.exit(0) sys.exit(0)
# parse command line # parse command line
xml = False xml = False
filename = None filename = None
htmldir = None htmldir = None
codedir = None
for arg in sys.argv[1:]: for arg in sys.argv[1:]:
if arg == '--xml': if arg == '--xml':
xml = True xml = True
elif arg.startswith('--html='): elif arg.startswith('--html='):
htmldir = arg[7:] htmldir = arg[7:]
elif arg.startswith('--code='):
codedir = arg[7:]
elif arg.endswith('.cpp'): elif arg.endswith('.cpp'):
filename = arg filename = arg
else: else:
@ -224,6 +227,36 @@ if filename != None:
htmldir + 'all-' + functionName + '.htm', htmldir + 'all-' + functionName + '.htm',
False) False)
elif codedir:
testnum = 0
if not codedir.endswith('/'):
codedir = codedir + '/'
errors = open(codedir+'errors.txt', 'w')
for node in e.nodes:
testnum = testnum + 1
functionName = node['functionName']
code = node['code']
expected = node['expected']
filename = str(testnum) + '-'
filename += functionName + '.cpp'
# source code
fout = open(codedir+filename,'w')
fout.write(code)
fout.close()
# suppression
if expected.startswith('[test.cpp:'):
expected='['+filename+expected[10:]
elif expected.startswith('[test.c:'):
expected='['+filename+expected[8:]
if expected != '':
errors.write(expected+'\n')
errors.close()
else: else:
for node in e.nodes: for node in e.nodes:
print node['functionName'] print node['functionName']