extracttests: ensure error comment is written on proper line

This commit is contained in:
Daniel Marjamäki 2021-05-16 08:40:04 +02:00
parent 8476900a62
commit 2c10e0747a
2 changed files with 7 additions and 9 deletions

View File

@ -1895,7 +1895,7 @@ private:
" int x;\n" " int x;\n"
" for (x = 0; x < 10 && y; x++) {\n" " for (x = 0; x < 10 && y; x++) {\n"
" data[x] = 0;\n" " data[x] = 0;\n"
" }" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout.str());
@ -1904,7 +1904,7 @@ private:
" int x;\n" " int x;\n"
" for (x = 0; x < 10 || y; x++) {\n" " for (x = 0; x < 10 || y; x++) {\n"
" data[x] = 0;\n" " data[x] = 0;\n"
" }" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 9, which is out of bounds.\n", errout.str());
@ -1913,7 +1913,7 @@ private:
" int x;\n" " int x;\n"
" for (x = 0; x <= 10 && y; x++) {\n" " for (x = 0; x <= 10 && y; x++) {\n"
" data[x] = 0;\n" " data[x] = 0;\n"
" }" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str());
@ -1922,7 +1922,7 @@ private:
" int x;\n" " int x;\n"
" for (x = 0; y && x <= 10; x++) {\n" " for (x = 0; y && x <= 10; x++) {\n"
" data[x] = 0;\n" " data[x] = 0;\n"
" }" " }\n"
"}"); "}");
ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str()); ASSERT_EQUALS("[test.cpp:5]: (error) Array 'data[2]' accessed at index 10, which is out of bounds.\n", errout.str());
} }

View File

@ -65,9 +65,7 @@ def tweak_expected(expected, start_code):
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': lines = len(start_code[:-1].split('\n'))
start_code = start_code[:-1]
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))
@ -119,7 +117,7 @@ class Extract:
# extracttests commands.. # extracttests commands..
res = re.match(r'\s*//\s*extracttests.start:(.*)', line) res = re.match(r'\s*//\s*extracttests.start:(.*)', line)
if res is not None: if res is not None:
start_code = res.group(1).replace('\\n', '\n') start_code = res.group(1).replace('\\n', '\n') + '\n'
elif line.find('extracttests.disable') >= 0: elif line.find('extracttests.disable') >= 0:
disable = True disable = True
elif line.find('extracttests.enable') >= 0: elif line.find('extracttests.enable') >= 0:
@ -377,7 +375,7 @@ if filename is not None:
filename = '%s-%03i-%s.cpp' % (testfile, testnum, functionName) filename = '%s-%03i-%s.cpp' % (testfile, testnum, functionName)
# comment error # comment error
res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\]: \([a-z]+\) (.*)', expected) res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\]: \([a-z, ]+\) (.*)', expected)
if res: if res:
line_number = int(res.group(2)) - 1 line_number = int(res.group(2)) - 1
lines = code.split('\n') lines = code.split('\n')