From 315ce1db40b3c14684d707b728c56844e589d075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 27 Nov 2011 08:32:07 +0100 Subject: [PATCH] extracttests.py: added function 'trimname' --- tools/extracttests.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/tools/extracttests.py b/tools/extracttests.py index cafdce43b..5469e5c0c 100755 --- a/tools/extracttests.py +++ b/tools/extracttests.py @@ -55,6 +55,14 @@ class Extract: def strtoxml(s): return s.replace('&','&').replace('"', '"').replace('<','<').replace('>','>') +def trimname(name): + while name[-1].isdigit(): + name = name[:-1] + if name[-1] == '_': + name = name[:-1] + return name + + 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' @@ -114,11 +122,7 @@ if filename != None: functionNames = [] for node in e.nodes: - functionname = node['functionName'] - while functionname[-1].isdigit(): - functionname = functionname[:-1] - if functionname[-1] == '_': - functionname = functionname[:-1] + functionname = trimname(node['functionName']) if not functionname in functionNames: functionNames.append(functionname) functionNames.sort() @@ -129,12 +133,7 @@ if filename != None: findex.write(' '+functionname+'') num = 0 for node in e.nodes: - name = node['functionName'] - while name[-1].isdigit(): - name = name[:-1] - if name[-1] == '_': - name = name[:-1] - if name == functionname: + if trimname(node['functionName']) == functionname: num = num + 1 findex.write('
' + str(num) + '
\n') @@ -161,12 +160,7 @@ if filename != None: fout.write(' NrCodeExpected\n') num = 0 for node in e.nodes: - name = node['functionName'] - while name[-1].isdigit(): - name = name[:-1] - if name[-1] == '_': - name = name[:-1] - if name == functionName: + if trimname(node['functionName']) == functionName: num = num + 1 fout.write(' ' + str(num) + '') fout.write('
' + strtoxml(node['code']).replace('\\n', '\n') + '
')