extracttests: write expected warning as comment in testfile
This commit is contained in:
parent
26e9525683
commit
db050d0796
|
@ -26,7 +26,7 @@ import sys
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
def add_includes(code):
|
def get_includes(code):
|
||||||
includes = (('alloca','alloca.h'),
|
includes = (('alloca','alloca.h'),
|
||||||
('NULL','cstddef'),
|
('NULL','cstddef'),
|
||||||
('size_t','cstddef'),
|
('size_t','cstddef'),
|
||||||
|
@ -48,24 +48,29 @@ def add_includes(code):
|
||||||
('std::unique_ptr','memory'),
|
('std::unique_ptr','memory'),
|
||||||
('std::vector','vector'))
|
('std::vector','vector'))
|
||||||
|
|
||||||
|
ret = ''
|
||||||
|
|
||||||
for i in includes:
|
for i in includes:
|
||||||
if i[0] in code:
|
if i[0] in code:
|
||||||
include_header = '#include <%s>' % i[1]
|
include_header = '#include <%s>' % i[1]
|
||||||
if include_header not in code:
|
if include_header not in ret:
|
||||||
code = include_header + '\n' + code
|
ret += include_header + '\n'
|
||||||
|
|
||||||
return code
|
return ret
|
||||||
|
|
||||||
|
|
||||||
def tweak_expected(expected, start_code):
|
def tweak_expected(expected, start_code):
|
||||||
if start_code is None:
|
if start_code is None or start_code == '':
|
||||||
return expected
|
return expected
|
||||||
res = re.match(r'\[([^:\]]+):([0-9]+)\](.*)', expected)
|
res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\](.*)', expected)
|
||||||
if res is None:
|
if res is None:
|
||||||
return expected
|
return expected
|
||||||
|
if start_code[-1] == '\n':
|
||||||
|
start_code = start_code[:-1]
|
||||||
lines = len(start_code.split('\n'))
|
lines = len(start_code.split('\n'))
|
||||||
return '[%s:%i]%s' % (res.group(1), lines + int(res.group(2)), res.group(3))
|
return '[%s:%i]%s' % (res.group(1), lines + int(res.group(2)), res.group(3))
|
||||||
|
|
||||||
|
|
||||||
class Extract:
|
class Extract:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -127,8 +132,6 @@ class Extract:
|
||||||
res = re.match('\\s+' + check_function + '\\(' + string, line)
|
res = re.match('\\s+' + check_function + '\\(' + string, line)
|
||||||
if res is not None:
|
if res is not None:
|
||||||
code = res.group(1)
|
code = res.group(1)
|
||||||
if start_code:
|
|
||||||
code = start_code + '\n' + code
|
|
||||||
|
|
||||||
# code..
|
# code..
|
||||||
if code is not None:
|
if code is not None:
|
||||||
|
@ -141,8 +144,15 @@ class Extract:
|
||||||
# assert
|
# assert
|
||||||
res = re.match('\\s+ASSERT_EQUALS\\(\\"([^"]*)\\",', line)
|
res = re.match('\\s+ASSERT_EQUALS\\(\\"([^"]*)\\",', line)
|
||||||
if res is not None and code is not None:
|
if res is not None and code is not None:
|
||||||
code = add_includes(code)
|
if start_code:
|
||||||
expected = tweak_expected(res.group(1), 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)
|
||||||
|
|
||||||
node = {'testclass': testclass,
|
node = {'testclass': testclass,
|
||||||
'functionName': functionName,
|
'functionName': functionName,
|
||||||
'code': code.replace("\\\\", "\\"),
|
'code': code.replace("\\\\", "\\"),
|
||||||
|
@ -345,8 +355,6 @@ if filename is not None:
|
||||||
if not os.path.exists(codedir):
|
if not os.path.exists(codedir):
|
||||||
os.mkdir(codedir)
|
os.mkdir(codedir)
|
||||||
|
|
||||||
errors = open(codedir + 'errors.txt', 'w')
|
|
||||||
|
|
||||||
testfile = filename
|
testfile = filename
|
||||||
if testfile.find('/'):
|
if testfile.find('/'):
|
||||||
testfile = testfile[testfile.rfind('/'):]
|
testfile = testfile[testfile.rfind('/'):]
|
||||||
|
@ -363,21 +371,25 @@ if filename is not None:
|
||||||
code = code.replace('\\n', '\n')
|
code = code.replace('\\n', '\n')
|
||||||
code = code.replace('\\"', '"')
|
code = code.replace('\\"', '"')
|
||||||
expected = node['expected']
|
expected = node['expected']
|
||||||
|
if expected.endswith('\\n'):
|
||||||
|
expected = expected[:-2]
|
||||||
|
|
||||||
filename = '%s-%03i-%s.cpp' % (testfile, testnum, functionName)
|
filename = '%s-%03i-%s.cpp' % (testfile, testnum, functionName)
|
||||||
|
|
||||||
|
# comment error
|
||||||
|
res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\]: \([a-z]+\) (.*)', expected)
|
||||||
|
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))
|
||||||
|
|
||||||
# source code
|
# source code
|
||||||
with open(codedir + filename, 'w') as fout:
|
with open(codedir + filename, 'w') as fout:
|
||||||
fout.write(code)
|
fout.write(code + '\n')
|
||||||
|
|
||||||
# write 'expected' to errors.txt
|
|
||||||
if expected != '':
|
|
||||||
expected = expected.replace('\\n', '\n')
|
|
||||||
expected = expected.replace('\\"', '"')
|
|
||||||
expected = re.sub(
|
|
||||||
'\\[test.cp?p?:', '[' + filename + ':', expected)
|
|
||||||
errors.write(expected)
|
|
||||||
errors.close()
|
|
||||||
else:
|
else:
|
||||||
for node in e.nodes:
|
for node in e.nodes:
|
||||||
print(node['functionName'])
|
print(node['functionName'])
|
||||||
|
|
Loading…
Reference in New Issue