From 2c10e0747ad5a63de8a1e91ec14c283392892789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 16 May 2021 08:40:04 +0200 Subject: [PATCH] extracttests: ensure error comment is written on proper line --- test/testbufferoverrun.cpp | 8 ++++---- tools/extracttests.py | 8 +++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/test/testbufferoverrun.cpp b/test/testbufferoverrun.cpp index ce4eebd6f..6aec94bcc 100644 --- a/test/testbufferoverrun.cpp +++ b/test/testbufferoverrun.cpp @@ -1895,7 +1895,7 @@ private: " int x;\n" " for (x = 0; x < 10 && y; x++) {\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()); @@ -1904,7 +1904,7 @@ private: " int x;\n" " for (x = 0; x < 10 || y; x++) {\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()); @@ -1913,7 +1913,7 @@ private: " int x;\n" " for (x = 0; x <= 10 && y; x++) {\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()); @@ -1922,7 +1922,7 @@ private: " int x;\n" " for (x = 0; y && x <= 10; x++) {\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()); } diff --git a/tools/extracttests.py b/tools/extracttests.py index 2006e07fe..e71caf00d 100755 --- a/tools/extracttests.py +++ b/tools/extracttests.py @@ -65,9 +65,7 @@ def tweak_expected(expected, start_code): res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\](.*)', expected) if res is None: return expected - if start_code[-1] == '\n': - start_code = start_code[:-1] - lines = len(start_code.split('\n')) + lines = len(start_code[:-1].split('\n')) return '[%s:%i]%s' % (res.group(1), lines + int(res.group(2)), res.group(3)) @@ -119,7 +117,7 @@ class Extract: # extracttests commands.. res = re.match(r'\s*//\s*extracttests.start:(.*)', line) 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: disable = True elif line.find('extracttests.enable') >= 0: @@ -377,7 +375,7 @@ if filename is not None: filename = '%s-%03i-%s.cpp' % (testfile, testnum, functionName) # comment error - res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\]: \([a-z]+\) (.*)', expected) + res = re.match(r'[^(]*\[([^:\]]+):([0-9]+)\]: \([a-z, ]+\) (.*)', expected) if res: line_number = int(res.group(2)) - 1 lines = code.split('\n')