From d8c08038216ffee6012a3ef88d9a2a9545120f6c Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Tue, 29 Nov 2022 22:03:32 +0100 Subject: [PATCH] Preserve line breaks in comments before test functions This way line numbers match better in error messages. Signed-off-by: Gilles Peskine --- tests/scripts/generate_test_code.py | 10 ++++------ tests/scripts/test_generate_test_code.py | 1 + 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/tests/scripts/generate_test_code.py b/tests/scripts/generate_test_code.py index c1d1c1cbf..b7c8e2854 100755 --- a/tests/scripts/generate_test_code.py +++ b/tests/scripts/generate_test_code.py @@ -552,14 +552,12 @@ def skip_comments(line, stream): pos = closing + 2 # Replace inner comment by spaces. There needs to be at least one space # for things like 'int/*ihatespaces*/foo'. Go further and preserve the - # width of the comment, this way column positions in error messages - # remain correct. - # TODO: It would be better to preserve line breaks, to get accurate - # line numbers if there's something interesting after a comment on - # the same line. + # width of the comment and line breaks, this way positions in error + # messages remain correct. line = (line[:opening.start(0)] + - ' ' * (pos - opening.start(0)) + + re.sub(r'.', r' ', line[opening.start(0):pos]) + line[pos:]) + # Strip whitespace at the end of lines (it's irrelevant to error messages). return re.sub(r' +(\n|\Z)', r'\1', line) def parse_function_code(funcs_f, dependencies, suite_dependencies): diff --git a/tests/scripts/test_generate_test_code.py b/tests/scripts/test_generate_test_code.py index d8b8cf979..8b2bf78d8 100755 --- a/tests/scripts/test_generate_test_code.py +++ b/tests/scripts/test_generate_test_code.py @@ -766,6 +766,7 @@ exit: + void test_func() { ba ba black sheep