diff --git a/tools/extracttests.py b/tools/extracttests.py
new file mode 100644
index 000000000..2a7be3385
--- /dev/null
+++ b/tools/extracttests.py
@@ -0,0 +1,176 @@
+#!/usr/bin/python
+
+import sys
+import re
+
+class Extract:
+ nodes = []
+
+ def parseFile(self,filename):
+ name = '[0-9a-zA-Z_]+'
+ str = '\\"(.+)\\"'
+
+ testclass = None
+ functionName = None
+
+ fin = open(filename, 'r')
+ for line in fin:
+ # testclass starts
+ res = re.match('class ('+name+')', line)
+ if res != None:
+ testclass = res.group(1)
+
+ # end of testclass
+ if re.match('};', line) != None:
+ testclass = None
+
+ # function start
+ res = re.match('\\s+void ('+name+')\\(\\)', line)
+ if res != None:
+ functionName = res.group(1)
+
+ elif re.match('\\s+}', line) != None:
+ functionName = None
+
+ if functionName == None:
+ continue
+
+ # check
+ res = re.match('\s+check\('+str, line)
+ if res != None:
+ code = res.group(1)
+
+ # code..
+ res = re.match('\\s+'+str, line)
+ if res != None:
+ code = code + res.group(1)
+
+ # assert
+ res = re.match('\\s+ASSERT_EQUALS\\(\\"(.*)\\"', line)
+ if res != None and len(code) > 10:
+ node = { 'testclass':testclass, 'functionName':functionName, 'code':code, 'expected':res.group(1) }
+ self.nodes.append(node)
+ code = ''
+
+def strtoxml(s):
+ return s.replace('&','&').replace('"', '"').replace('<','<').replace('>','>')
+
+# parse command line
+xml = False
+filename = None
+htmldir = None
+i = 1
+while i < len(sys.argv):
+ if sys.argv[i] == '--xml':
+ xml = True
+ elif sys.argv[i].startswith('--html='):
+ arg = sys.argv[i]
+ htmldir = arg[7:]
+ else:
+ filename = sys.argv[i]
+ i = i + 1
+
+# extract test cases
+if filename != None:
+ # parse test file
+ e = Extract()
+ e.parseFile(filename)
+
+ # generate output
+ if xml:
+ print ''
+ print '
Name | Number |
---|---|
'+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: + num = num + 1 + findex.write('' + str(num) + ' |
Nr | Code | Expected |
---|---|---|
' + str(num) + ' | ') + fout.write('' + strtoxml(node['code']).replace('\\n', '\n') + ' | ')
+ fout.write('' + strtoxml(node['expected']).replace('\\n', ' ') + ' | ')
+ fout.write('