extracttests.py: allow user to see 'error cases only'

This commit is contained in:
Daniel Marjamäki 2011-11-27 10:26:35 +01:00
parent 315ce1db40
commit db186b2c25
1 changed files with 54 additions and 29 deletions

View File

@ -63,6 +63,44 @@ def trimname(name):
return name
def writeHtmlFile(nodes, functionName, filename, errorsOnly):
fout = open(filename, 'w')
fout.write('<html>\n')
fout.write('<head>\n')
fout.write(' <style type="text/css">\n')
fout.write(' body { font-size: 0.8em }\n')
fout.write(' th { background-color: #A3C159; text-transform: uppercase }\n')
fout.write(' td { background-color: white; vertical-align: text-top }\n')
fout.write(' pre { background-color: #EEEEEE }\n')
fout.write(' </style>\n')
fout.write('</head>\n')
fout.write('<body>\n')
testclass = None
num = 0
for node in nodes:
if errorsOnly and node['expected']=='':
continue
if trimname(node['functionName']) == functionName:
num = num + 1
if not testclass:
testclass = node['testclass']
fout.write('<h1>' + node['testclass'] + '::' + functionName + '</h1>')
fout.write('<table border="0" cellspacing="0">\n')
fout.write(' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
fout.write(' <tr><td>' + str(num) + '</td>')
fout.write('<td><pre>' + strtoxml(node['code']).replace('\\n', '\n') + '</pre></td>')
fout.write('<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
fout.write('</tr>\n')
if testclass != None:
fout.write('</table>\n');
fout.write('</body></html>\n')
fout.close()
if len(sys.argv) == 1 or '--help' in sys.argv:
print 'Extract test cases from test file'
print 'Syntax: extracttests.py [--html=folder] [--xml] path/testfile.cpp'
@ -128,14 +166,22 @@ if filename != None:
functionNames.sort()
findex.write('<table border="0" cellspacing="0">\n')
findex.write(' <tr><th>Name</th><th>Number</th></tr>\n')
findex.write(' <tr><th>Name</th><th>Errors</th><th>All</th></tr>\n')
for functionname in functionNames:
findex.write(' <tr><td><a href="'+functionname+'.htm">'+functionname+'</a></td>')
num = 0
findex.write(' <tr><td>'+functionname+'</td>')
numall = 0
numerr = 0
for node in e.nodes:
if trimname(node['functionName']) == functionname:
num = num + 1
findex.write('<td><div align="right">' + str(num) + '</div></td></tr>\n')
numall = numall + 1
if node['expected'] != '':
numerr = numerr + 1
if numerr == 0:
findex.write('<td><div align="right">0</div></td>')
else:
findex.write('<td><a href="errors-'+functionname+'.htm"><div align="right">' + str(numerr) + '</div></a></td>')
findex.write('<td><a href="all-'+functionname+'.htm"><div align="right">' + str(numall) + '</div></a></td>')
findex.write('</tr>\n')
findex.write('</table>\n')
@ -144,30 +190,9 @@ if filename != None:
# create files for each functionName
for functionName in functionNames:
fout = open(htmldir + functionName + '.htm', 'w')
fout.write('<html>\n')
fout.write('<head>\n')
fout.write(' <style type="text/css">\n')
fout.write(' body { font-size: 0.8em }\n')
fout.write(' th { background-color: #A3C159; text-transform: uppercase }\n')
fout.write(' td { background-color: white; vertical-align: text-top }\n')
fout.write(' pre { background-color: #EEEEEE }\n')
fout.write(' </style>\n')
fout.write('</head>\n')
fout.write('<body>\n')
fout.write('<h1>' + node['testclass'] + '::' + functionName + '</h1>')
fout.write('<table border="0" cellspacing="0">\n')
fout.write(' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
num = 0
for node in e.nodes:
if trimname(node['functionName']) == functionName:
num = num + 1
fout.write(' <tr><td>' + str(num) + '</td>')
fout.write('<td><pre>' + strtoxml(node['code']).replace('\\n', '\n') + '</pre></td>')
fout.write('<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
fout.write('</tr>\n')
fout.write('</table></body></html>\n')
fout.close()
writeHtmlFile(e.nodes, functionName, htmldir + 'errors-' + functionName + '.htm', True)
writeHtmlFile(e.nodes, functionName, htmldir + 'all-' + functionName + '.htm', False)
else:
for node in e.nodes:
print node['functionName']