From 18f7028a0e84bcc6c091d3494e5291efdcd83198 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 30 Nov 2022 16:38:49 +0100 Subject: [PATCH] Preserve line breaks from continued line comments The commit "Preserve line breaks in comments before test functions" only handled block comments. This commit handles line comments. Signed-off-by: Gilles Peskine --- tests/scripts/generate_test_code.py | 6 +++++- tests/scripts/test_generate_test_code.py | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/scripts/generate_test_code.py b/tests/scripts/generate_test_code.py index b7c8e28543..f19d30b61e 100755 --- a/tests/scripts/generate_test_code.py +++ b/tests/scripts/generate_test_code.py @@ -537,11 +537,15 @@ def skip_comments(line, stream): break if line[opening.start(0) + 1] == '/': # //... continuation = line + # Count the number of line breaks, to keep line numbers aligned + # in the output. + line_count = 1 while continuation.endswith('\\\n'): # This errors out if the file ends with an unfinished line # comment. That's acceptable to not complicate the code further. continuation = next(stream) - return line[:opening.start(0)].rstrip() + '\n' + line_count += 1 + return line[:opening.start(0)].rstrip() + '\n' * line_count # Parsing /*...*/, looking for the end closing = line.find('*/', opening.end(0)) while closing == -1: diff --git a/tests/scripts/test_generate_test_code.py b/tests/scripts/test_generate_test_code.py index 8b2bf78d8a..d23d742193 100755 --- a/tests/scripts/test_generate_test_code.py +++ b/tests/scripts/test_generate_test_code.py @@ -767,6 +767,8 @@ exit: + + void test_func() { ba ba black sheep @@ -813,6 +815,7 @@ exit: expected = '''#line 1 "test_suite_ut.function" void test_func( int x, + int y ) { ba ba black sheep