From db186b2c254d42b6392b7a27951231a086851a9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 27 Nov 2011 10:26:35 +0100 Subject: [PATCH] extracttests.py: allow user to see 'error cases only' --- tools/extracttests.py | 83 ++++++++++++++++++++++++++++--------------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/tools/extracttests.py b/tools/extracttests.py index 5469e5c0c..16f63cb3b 100755 --- a/tools/extracttests.py +++ b/tools/extracttests.py @@ -63,6 +63,44 @@ def trimname(name): return name +def writeHtmlFile(nodes, functionName, filename, errorsOnly): + fout = open(filename, 'w') + fout.write('\n') + fout.write('\n') + fout.write(' \n') + fout.write('\n') + fout.write('\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('

' + node['testclass'] + '::' + functionName + '

') + fout.write('\n') + fout.write(' \n') + + fout.write(' ') + fout.write('') + fout.write('') + fout.write('\n') + + if testclass != None: + fout.write('
NrCodeExpected
' + str(num) + '
' + strtoxml(node['code']).replace('\\n', '\n') + '
' + strtoxml(node['expected']).replace('\\n', '
') + '
\n'); + fout.write('\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('\n') - findex.write(' \n') + findex.write(' \n') for functionname in functionNames: - findex.write(' ') - num = 0 + findex.write(' ') + numall = 0 + numerr = 0 for node in e.nodes: if trimname(node['functionName']) == functionname: - num = num + 1 - findex.write('\n') + numall = numall + 1 + if node['expected'] != '': + numerr = numerr + 1 + if numerr == 0: + findex.write('') + else: + findex.write('') + findex.write('') + findex.write('\n') findex.write('
NameNumber
NameErrorsAll
'+functionname+'
'+functionname+'
' + str(num) + '
0
' + str(numerr) + '
' + str(numall) + '
\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('\n') - fout.write('\n') - fout.write(' \n') - fout.write('\n') - fout.write('\n') - fout.write('

' + node['testclass'] + '::' + functionName + '

') - fout.write('\n') - fout.write(' \n') - num = 0 - for node in e.nodes: - if trimname(node['functionName']) == functionName: - num = num + 1 - fout.write(' ') - fout.write('') - fout.write('') - fout.write('\n') - fout.write('
NrCodeExpected
' + str(num) + '
' + strtoxml(node['code']).replace('\\n', '\n') + '
' + strtoxml(node['expected']).replace('\\n', '
') + '
\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']