From 2a778dca828f3a28952556cdd30af23bbd3b0ed0 Mon Sep 17 00:00:00 2001 From: Eren Dogan Date: Fri, 22 Jul 2022 18:22:40 +0300 Subject: [PATCH] Add whitespace check to code format test --- compiler/tests/00_code_format_check_test.py | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/compiler/tests/00_code_format_check_test.py b/compiler/tests/00_code_format_check_test.py index 7249ba7a..97ffda09 100755 --- a/compiler/tests/00_code_format_check_test.py +++ b/compiler/tests/00_code_format_check_test.py @@ -28,6 +28,7 @@ class code_format_test(openram_test): continue errors += check_file_format_tab(code) errors += check_file_format_carriage(code) + errors += check_file_format_whitespace(code) for code in source_codes: if re.search("gdsMill", code): @@ -99,6 +100,28 @@ def check_file_format_carriage(file_name): return len(key_positions) +def check_file_format_whitespace(file_name): + """ + Check if file contains a line with whitespace at the end + and return the number of these lines. + """ + + f = open(file_name, "r") + key_positions = [] + for num, line in enumerate(f.readlines()): + if re.match(r".*[ \t]$", line): + key_positions.append(num) + if len(key_positions) > 0: + if len(key_positions) > 10: + line_numbers = key_positions[:10] + [" ..."] + else: + line_numbers = key_positions + debug.info(0, "\nFound " + str(len(key_positions)) + " ending whitespace in " + + str(file_name) + " (lines " + ",".join(str(x) for x in line_numbers) + ")") + f.close() + return len(key_positions) + + def check_print_output(file_name): """Check if any files (except debug.py) call the _print_ function. We should use the debug output with verbosity instead!"""