2022-11-03 22:14:30 +01:00
|
|
|
#!/usr/bin/env python3
|
2013-01-10 11:10:45 +01:00
|
|
|
#
|
|
|
|
# Cppcheck - A tool for static C/C++ code analysis
|
2022-01-28 18:30:12 +01:00
|
|
|
# Copyright (C) 2007-2021 Cppcheck team.
|
2013-01-10 11:10:45 +01:00
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-27 08:06:11 +01:00
|
|
|
|
2011-12-02 18:33:17 +01:00
|
|
|
"""
|
|
|
|
Extract test cases information from Cppcheck test
|
|
|
|
file
|
|
|
|
"""
|
2011-11-27 11:35:01 +01:00
|
|
|
|
2011-12-04 21:46:56 +01:00
|
|
|
import os
|
2011-11-27 08:06:11 +01:00
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
2013-03-02 16:45:26 +01:00
|
|
|
|
2021-05-15 19:59:28 +02:00
|
|
|
def get_includes(code):
|
2021-05-13 20:21:02 +02:00
|
|
|
includes = (('alloca','alloca.h'),
|
|
|
|
('NULL','cstddef'),
|
|
|
|
('size_t','cstddef'),
|
|
|
|
('free','cstdlib'),
|
|
|
|
('malloc','cstdlib'),
|
|
|
|
('realloc','cstdlib'),
|
2021-05-13 20:50:24 +02:00
|
|
|
('memcpy','cstring'),
|
2021-05-13 20:21:02 +02:00
|
|
|
('stdin','cstdio'),
|
|
|
|
('strcat','cstring'),
|
|
|
|
('strchr','cstring'),
|
|
|
|
('strcpy','cstring'),
|
|
|
|
('strlen','cstring'),
|
|
|
|
('strncat','cstring'),
|
|
|
|
('strncpy','cstring'),
|
|
|
|
('std::cout','iostream'),
|
2021-05-13 20:50:24 +02:00
|
|
|
('std::pair','utility'),
|
2021-05-13 20:21:02 +02:00
|
|
|
('std::shared_ptr','memory'),
|
|
|
|
('std::string','string'),
|
2021-05-13 20:50:24 +02:00
|
|
|
('std::unique_ptr','memory'),
|
|
|
|
('std::vector','vector'))
|
2021-05-13 20:21:02 +02:00
|
|
|
|
2021-05-15 19:59:28 +02:00
|
|
|
ret = ''
|
|
|
|
|
2021-05-13 20:21:02 +02:00
|
|
|
for i in includes:
|
|
|
|
if i[0] in code:
|
2021-05-13 20:33:27 +02:00
|
|
|
include_header = '#include <%s>' % i[1]
|
2021-05-15 19:59:28 +02:00
|
|
|
if include_header not in ret:
|
|
|
|
ret += include_header + '\n'
|
2021-05-13 20:21:02 +02:00
|
|
|
|
2021-05-15 19:59:28 +02:00
|
|
|
return ret
|
2021-05-13 20:21:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
def tweak_expected(expected, start_code):
|
2021-05-15 19:59:28 +02:00
|
|
|
if start_code is None or start_code == '':
|
2021-05-13 20:21:02 +02:00
|
|
|
return expected
|
2021-05-15 19:59:28 +02:00
|
|
|
res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\](.*)', expected)
|
2021-05-13 20:21:02 +02:00
|
|
|
if res is None:
|
|
|
|
return expected
|
2021-05-16 08:40:04 +02:00
|
|
|
lines = len(start_code[:-1].split('\n'))
|
2021-05-13 20:21:02 +02:00
|
|
|
return '[%s:%i]%s' % (res.group(1), lines + int(res.group(2)), res.group(3))
|
|
|
|
|
2021-05-15 19:59:28 +02:00
|
|
|
|
2011-11-27 08:06:11 +01:00
|
|
|
class Extract:
|
2013-10-18 17:35:59 +02:00
|
|
|
|
2011-12-02 18:33:17 +01:00
|
|
|
"""
|
|
|
|
Read Cppcheck test file and create data
|
|
|
|
representation
|
|
|
|
"""
|
2011-11-27 11:35:01 +01:00
|
|
|
|
|
|
|
# array that stores all the test cases
|
2011-11-27 08:06:11 +01:00
|
|
|
nodes = []
|
|
|
|
|
2013-03-02 16:45:26 +01:00
|
|
|
def parseFile(self, filename):
|
2011-12-02 18:33:17 +01:00
|
|
|
"""
|
|
|
|
parse test file and add info to the nodes
|
|
|
|
variable
|
|
|
|
"""
|
2011-11-27 11:35:01 +01:00
|
|
|
|
2011-11-27 08:06:11 +01:00
|
|
|
name = '[0-9a-zA-Z_]+'
|
2013-03-02 16:45:26 +01:00
|
|
|
string = '\\"(.+)\\"'
|
2011-11-27 08:06:11 +01:00
|
|
|
|
|
|
|
testclass = None
|
|
|
|
functionName = None
|
2015-07-22 09:52:24 +02:00
|
|
|
code = None
|
2021-05-13 20:21:02 +02:00
|
|
|
start_code = None
|
|
|
|
disable = False
|
2011-11-27 08:06:11 +01:00
|
|
|
|
2023-12-17 20:04:17 +01:00
|
|
|
for line in open(filename, 'r'):
|
2011-11-27 08:06:11 +01:00
|
|
|
# testclass starts
|
2013-10-18 17:35:59 +02:00
|
|
|
res = re.match('class (' + name + ')', line)
|
2013-03-02 16:45:26 +01:00
|
|
|
if res is not None:
|
2011-11-27 08:06:11 +01:00
|
|
|
testclass = res.group(1)
|
|
|
|
|
2012-09-28 20:25:46 +02:00
|
|
|
# end of testclass
|
2013-03-02 16:45:26 +01:00
|
|
|
if re.match('};', line) is not None:
|
2011-11-27 08:06:11 +01:00
|
|
|
testclass = None
|
|
|
|
|
|
|
|
# function start
|
2013-10-18 17:35:59 +02:00
|
|
|
res = re.match('\\s+void (' + name + ')\\(\\)', line)
|
2013-03-02 16:45:26 +01:00
|
|
|
if res is not None:
|
2011-11-27 08:06:11 +01:00
|
|
|
functionName = res.group(1)
|
2021-05-13 20:21:02 +02:00
|
|
|
start_code = None
|
2011-11-27 08:06:11 +01:00
|
|
|
|
2013-03-02 16:45:26 +01:00
|
|
|
elif re.match('\\s+}', line) is not None:
|
2011-11-27 08:06:11 +01:00
|
|
|
functionName = None
|
|
|
|
|
2021-05-13 20:21:02 +02:00
|
|
|
# extracttests commands..
|
|
|
|
res = re.match(r'\s*//\s*extracttests.start:(.*)', line)
|
|
|
|
if res is not None:
|
2021-05-16 08:40:04 +02:00
|
|
|
start_code = res.group(1).replace('\\n', '\n') + '\n'
|
2021-05-13 20:21:02 +02:00
|
|
|
elif line.find('extracttests.disable') >= 0:
|
|
|
|
disable = True
|
|
|
|
elif line.find('extracttests.enable') >= 0:
|
|
|
|
disable = False
|
|
|
|
|
|
|
|
if functionName is None or disable:
|
2011-11-27 08:06:11 +01:00
|
|
|
continue
|
|
|
|
|
|
|
|
# check
|
2021-05-22 09:43:56 +02:00
|
|
|
for f in check_function:
|
|
|
|
res = re.match('\\s+' + f + '\\(' + string, line)
|
|
|
|
if res is not None:
|
|
|
|
code = res.group(1)
|
|
|
|
break
|
2011-11-27 08:06:11 +01:00
|
|
|
|
|
|
|
# code..
|
2015-07-22 09:52:24 +02:00
|
|
|
if code is not None:
|
|
|
|
res = re.match('\\s+' + string, line)
|
|
|
|
if res is not None:
|
2023-12-17 20:04:17 +01:00
|
|
|
if line.find('",') > line.find('"'):
|
|
|
|
code = None
|
|
|
|
continue
|
|
|
|
|
2015-07-22 09:52:24 +02:00
|
|
|
code = code + res.group(1)
|
2021-05-13 20:21:02 +02:00
|
|
|
if res.group(1).find('"') > 0:
|
|
|
|
code = None
|
2011-11-27 08:06:11 +01:00
|
|
|
|
|
|
|
# assert
|
2011-12-02 18:33:17 +01:00
|
|
|
res = re.match('\\s+ASSERT_EQUALS\\(\\"([^"]*)\\",', line)
|
2015-07-22 09:52:24 +02:00
|
|
|
if res is not None and code is not None:
|
2021-05-15 19:59:28 +02:00
|
|
|
if start_code:
|
|
|
|
includes = get_includes(start_code + code)
|
|
|
|
code = includes + start_code + code
|
|
|
|
expected = tweak_expected(res.group(1), includes + start_code)
|
|
|
|
else:
|
|
|
|
includes = get_includes(code)
|
|
|
|
code = includes + code
|
|
|
|
expected = tweak_expected(res.group(1), includes)
|
|
|
|
|
2013-03-02 16:45:26 +01:00
|
|
|
node = {'testclass': testclass,
|
|
|
|
'functionName': functionName,
|
2021-05-13 20:21:02 +02:00
|
|
|
'code': code.replace("\\\\", "\\"),
|
|
|
|
'expected': expected}
|
2011-11-27 08:06:11 +01:00
|
|
|
self.nodes.append(node)
|
2015-07-22 09:52:24 +02:00
|
|
|
code = None
|
2023-12-17 20:04:17 +01:00
|
|
|
elif re.match('\\s+[TOD_]*ASSERT', line) is not None:
|
|
|
|
code = None
|
2013-03-02 16:45:26 +01:00
|
|
|
|
2011-11-27 08:06:11 +01:00
|
|
|
def strtoxml(s):
|
2011-11-27 11:35:01 +01:00
|
|
|
"""Convert string to xml/html format"""
|
2013-03-02 16:45:26 +01:00
|
|
|
return s.replace('&', '&').replace('"', '"').replace('<', '<').replace('>', '>')
|
|
|
|
|
2011-11-27 08:06:11 +01:00
|
|
|
|
2011-11-27 08:32:07 +01:00
|
|
|
def trimname(name):
|
2011-11-27 11:35:01 +01:00
|
|
|
"""Trim test name. Trailing underscore and digits are removed"""
|
2011-11-27 08:32:07 +01:00
|
|
|
while name[-1].isdigit():
|
|
|
|
name = name[:-1]
|
|
|
|
if name[-1] == '_':
|
|
|
|
name = name[:-1]
|
|
|
|
return name
|
|
|
|
|
|
|
|
|
2011-11-27 10:26:35 +01:00
|
|
|
def writeHtmlFile(nodes, functionName, filename, errorsOnly):
|
2011-11-27 11:35:01 +01:00
|
|
|
"""Write html file for a function name"""
|
2011-11-27 10:26:35 +01:00
|
|
|
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')
|
2013-10-18 17:35:59 +02:00
|
|
|
fout.write(
|
|
|
|
' th { background-color: #A3C159; text-transform: uppercase }\n')
|
2011-11-27 10:26:35 +01:00
|
|
|
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')
|
|
|
|
|
2011-11-27 11:35:01 +01:00
|
|
|
fout.write('<a href="index.htm">Home</a> -- ')
|
|
|
|
if errorsOnly:
|
2013-10-18 17:35:59 +02:00
|
|
|
fout.write('<a href="all-' + functionName + '.htm">All test cases</a>')
|
2011-11-27 11:35:01 +01:00
|
|
|
else:
|
2013-10-18 17:35:59 +02:00
|
|
|
fout.write(
|
|
|
|
'<a href="errors-' + functionName + '.htm">Error test cases</a>')
|
2011-11-27 11:35:01 +01:00
|
|
|
fout.write('<br><br>')
|
|
|
|
|
2011-11-27 10:26:35 +01:00
|
|
|
testclass = None
|
|
|
|
num = 0
|
|
|
|
for node in nodes:
|
2013-03-02 16:45:26 +01:00
|
|
|
if errorsOnly and node['expected'] == '':
|
2011-11-27 10:26:35 +01:00
|
|
|
continue
|
|
|
|
if trimname(node['functionName']) == functionName:
|
|
|
|
num = num + 1
|
|
|
|
|
|
|
|
if not testclass:
|
|
|
|
testclass = node['testclass']
|
2013-10-18 17:35:59 +02:00
|
|
|
fout.write(
|
|
|
|
'<h1>' + node['testclass'] + '::' + functionName + '</h1>')
|
2011-11-27 10:26:35 +01:00
|
|
|
fout.write('<table border="0" cellspacing="0">\n')
|
2013-10-18 17:35:59 +02:00
|
|
|
fout.write(
|
|
|
|
' <tr><th>Nr</th><th>Code</th><th>Expected</th></tr>\n')
|
2011-11-27 10:26:35 +01:00
|
|
|
|
|
|
|
fout.write(' <tr><td>' + str(num) + '</td>')
|
2013-10-18 17:35:59 +02:00
|
|
|
fout.write('<td><pre>' + strtoxml(
|
|
|
|
node['code']).replace('\\n', '\n') + '</pre></td>')
|
|
|
|
fout.write(
|
|
|
|
'<td>' + strtoxml(node['expected']).replace('\\n', '<br>') + '</td>')
|
2011-11-27 10:26:35 +01:00
|
|
|
fout.write('</tr>\n')
|
|
|
|
|
2013-03-02 16:45:26 +01:00
|
|
|
if testclass is not None:
|
|
|
|
fout.write('</table>\n')
|
2011-11-27 10:26:35 +01:00
|
|
|
fout.write('</body></html>\n')
|
|
|
|
fout.close()
|
|
|
|
|
|
|
|
|
2011-11-27 15:24:13 +01:00
|
|
|
if len(sys.argv) <= 1 or '--help' in sys.argv:
|
2017-06-04 22:51:48 +02:00
|
|
|
print('Extract test cases from test file')
|
|
|
|
print(
|
2021-05-13 20:21:02 +02:00
|
|
|
'Syntax: extracttests.py [--html=folder] [--xml] [--code=folder] [--only-tp] [--check-function=check] path/testfile.cpp')
|
2011-11-27 14:11:15 +01:00
|
|
|
sys.exit(0)
|
2011-11-27 08:13:11 +01:00
|
|
|
|
2011-11-27 08:06:11 +01:00
|
|
|
# parse command line
|
|
|
|
xml = False
|
|
|
|
filename = None
|
|
|
|
htmldir = None
|
2011-11-28 22:17:06 +01:00
|
|
|
codedir = None
|
2017-09-22 23:23:36 +02:00
|
|
|
onlyTP = None
|
2021-05-22 09:43:56 +02:00
|
|
|
check_function = ['check[A-Za-z0-9_]*']
|
2011-11-27 15:24:13 +01:00
|
|
|
for arg in sys.argv[1:]:
|
|
|
|
if arg == '--xml':
|
2011-11-27 08:06:11 +01:00
|
|
|
xml = True
|
2021-05-13 20:21:02 +02:00
|
|
|
elif arg == '--only-tp':
|
2017-09-22 23:23:36 +02:00
|
|
|
onlyTP = True
|
2011-11-27 15:24:13 +01:00
|
|
|
elif arg.startswith('--html='):
|
2011-11-27 08:06:11 +01:00
|
|
|
htmldir = arg[7:]
|
2011-11-28 22:17:06 +01:00
|
|
|
elif arg.startswith('--code='):
|
|
|
|
codedir = arg[7:]
|
2011-11-27 17:11:38 +01:00
|
|
|
elif arg.endswith('.cpp'):
|
2011-11-27 15:24:13 +01:00
|
|
|
filename = arg
|
2021-05-13 20:21:02 +02:00
|
|
|
elif arg.startswith('--check-function='):
|
2021-05-22 09:43:56 +02:00
|
|
|
check_function.append(arg[17:])
|
2011-11-27 17:11:38 +01:00
|
|
|
else:
|
2017-06-04 22:51:48 +02:00
|
|
|
print('Invalid option: ' + arg)
|
2011-11-27 17:11:38 +01:00
|
|
|
sys.exit(1)
|
2011-11-27 15:24:13 +01:00
|
|
|
|
2011-11-27 08:06:11 +01:00
|
|
|
|
|
|
|
# extract test cases
|
2013-03-02 16:45:26 +01:00
|
|
|
if filename is not None:
|
2011-11-27 08:06:11 +01:00
|
|
|
# parse test file
|
|
|
|
e = Extract()
|
|
|
|
e.parseFile(filename)
|
|
|
|
|
|
|
|
# generate output
|
|
|
|
if xml:
|
2017-06-04 22:51:48 +02:00
|
|
|
print('<?xml version="1.0"?>')
|
|
|
|
print('<tree>')
|
2011-11-27 08:06:11 +01:00
|
|
|
count = 0
|
|
|
|
for node in e.nodes:
|
2013-10-18 17:35:59 +02:00
|
|
|
s = ' <node'
|
2011-11-27 08:06:11 +01:00
|
|
|
s += ' function="' + node['functionName'] + '"'
|
|
|
|
s += ' code="' + strtoxml(node['code']) + '"'
|
|
|
|
s += ' expected="' + strtoxml(node['expected']) + '"'
|
|
|
|
s += '/>'
|
2017-06-04 22:51:48 +02:00
|
|
|
print(s)
|
|
|
|
print('</tree>')
|
2013-03-02 16:45:26 +01:00
|
|
|
elif htmldir is not None:
|
2011-11-27 08:06:11 +01:00
|
|
|
if not htmldir.endswith('/'):
|
|
|
|
htmldir += '/'
|
2011-12-04 21:46:56 +01:00
|
|
|
if not os.path.exists(htmldir):
|
|
|
|
os.mkdir(htmldir)
|
2011-11-27 08:06:11 +01:00
|
|
|
findex = open(htmldir + 'index.htm', 'w')
|
|
|
|
findex.write('<html>\n')
|
|
|
|
findex.write('<head>\n')
|
|
|
|
findex.write(' <style type="text/css">\n')
|
|
|
|
findex.write(' table { font-size: 0.8em }\n')
|
2013-10-18 17:35:59 +02:00
|
|
|
findex.write(
|
|
|
|
' th { background-color: #A3C159; text-transform: uppercase }\n')
|
|
|
|
findex.write(
|
|
|
|
' td { background-color: #F0FFE0; vertical-align: text-top }\n')
|
2011-11-27 08:06:11 +01:00
|
|
|
findex.write(' A:link { text-decoration: none }\n')
|
|
|
|
findex.write(' A:visited { text-decoration: none }\n')
|
|
|
|
findex.write(' A:active { text-decoration: none }\n')
|
|
|
|
findex.write(' A:hover { text-decoration: underline; color: blue }\n')
|
|
|
|
findex.write(' </style>\n')
|
|
|
|
findex.write('</head>\n')
|
|
|
|
findex.write('<body>\n')
|
|
|
|
findex.write('<h1>' + filename + '</h1>\n')
|
|
|
|
|
|
|
|
functionNames = []
|
|
|
|
for node in e.nodes:
|
2011-11-27 08:32:07 +01:00
|
|
|
functionname = trimname(node['functionName'])
|
2014-12-22 14:26:57 +01:00
|
|
|
if functionname not in functionNames:
|
2011-11-27 08:06:11 +01:00
|
|
|
functionNames.append(functionname)
|
|
|
|
functionNames.sort()
|
|
|
|
|
|
|
|
findex.write('<table border="0" cellspacing="0">\n')
|
2011-11-27 10:26:35 +01:00
|
|
|
findex.write(' <tr><th>Name</th><th>Errors</th><th>All</th></tr>\n')
|
2011-11-27 08:06:11 +01:00
|
|
|
for functionname in functionNames:
|
2013-10-18 17:35:59 +02:00
|
|
|
findex.write(' <tr><td>' + functionname + '</td>')
|
2011-11-27 10:26:35 +01:00
|
|
|
numall = 0
|
|
|
|
numerr = 0
|
2011-11-27 08:06:11 +01:00
|
|
|
for node in e.nodes:
|
2011-11-27 08:32:07 +01:00
|
|
|
if trimname(node['functionName']) == functionname:
|
2011-11-27 10:26:35 +01:00
|
|
|
numall = numall + 1
|
|
|
|
if node['expected'] != '':
|
|
|
|
numerr = numerr + 1
|
|
|
|
if numerr == 0:
|
|
|
|
findex.write('<td><div align="right">0</div></td>')
|
|
|
|
else:
|
2013-10-18 17:35:59 +02:00
|
|
|
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>')
|
2011-11-27 10:26:35 +01:00
|
|
|
findex.write('</tr>\n')
|
2011-11-27 08:06:11 +01:00
|
|
|
|
|
|
|
findex.write('</table>\n')
|
|
|
|
|
|
|
|
findex.write('</body></html>')
|
|
|
|
findex.close()
|
|
|
|
|
|
|
|
# create files for each functionName
|
|
|
|
for functionName in functionNames:
|
2012-09-28 20:25:46 +02:00
|
|
|
writeHtmlFile(e.nodes,
|
|
|
|
functionName,
|
2011-11-27 13:49:20 +01:00
|
|
|
htmldir + 'errors-' + functionName + '.htm',
|
|
|
|
True)
|
|
|
|
writeHtmlFile(e.nodes,
|
|
|
|
functionName,
|
|
|
|
htmldir + 'all-' + functionName + '.htm',
|
|
|
|
False)
|
2011-11-27 10:26:35 +01:00
|
|
|
|
2011-11-28 22:17:06 +01:00
|
|
|
elif codedir:
|
|
|
|
testnum = 0
|
|
|
|
|
|
|
|
if not codedir.endswith('/'):
|
|
|
|
codedir = codedir + '/'
|
2011-12-04 21:46:56 +01:00
|
|
|
|
|
|
|
if not os.path.exists(codedir):
|
|
|
|
os.mkdir(codedir)
|
|
|
|
|
2021-10-30 22:13:58 +02:00
|
|
|
testfile = os.path.splitext(os.path.basename(filename))[0]
|
2021-05-13 20:21:02 +02:00
|
|
|
|
2011-11-28 22:17:06 +01:00
|
|
|
for node in e.nodes:
|
2017-09-22 23:23:36 +02:00
|
|
|
if onlyTP and node['expected'] == '':
|
|
|
|
continue
|
|
|
|
|
2011-11-28 22:17:06 +01:00
|
|
|
testnum = testnum + 1
|
|
|
|
|
|
|
|
functionName = node['functionName']
|
|
|
|
code = node['code']
|
2011-11-29 10:13:37 +01:00
|
|
|
code = code.replace('\\n', '\n')
|
|
|
|
code = code.replace('\\"', '"')
|
2011-11-28 22:17:06 +01:00
|
|
|
expected = node['expected']
|
2021-05-15 19:59:28 +02:00
|
|
|
if expected.endswith('\\n'):
|
|
|
|
expected = expected[:-2]
|
2011-11-28 22:17:06 +01:00
|
|
|
|
2021-05-13 20:21:02 +02:00
|
|
|
filename = '%s-%03i-%s.cpp' % (testfile, testnum, functionName)
|
2011-11-28 22:17:06 +01:00
|
|
|
|
2021-05-15 19:59:28 +02:00
|
|
|
# comment error
|
2021-05-16 08:40:04 +02:00
|
|
|
res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\]: \([a-z, ]+\) (.*)', expected)
|
2021-05-15 19:59:28 +02:00
|
|
|
if res:
|
|
|
|
line_number = int(res.group(2)) - 1
|
|
|
|
lines = code.split('\n')
|
|
|
|
if len(lines) > line_number:
|
|
|
|
lines[line_number] += ' // ' + res.group(3)
|
|
|
|
code = '\n'.join(lines)
|
|
|
|
else:
|
|
|
|
print('filename:%s expected:%s' % (filename, expected))
|
|
|
|
|
2011-11-28 22:17:06 +01:00
|
|
|
# source code
|
2021-05-13 20:21:02 +02:00
|
|
|
with open(codedir + filename, 'w') as fout:
|
2021-05-15 19:59:28 +02:00
|
|
|
fout.write(code + '\n')
|
2011-11-27 08:06:11 +01:00
|
|
|
else:
|
|
|
|
for node in e.nodes:
|
2017-06-04 22:51:48 +02:00
|
|
|
print(node['functionName'])
|