ci: check for incorrect assert usage in C++ files (#2461)

This commit is contained in:
Tyler Wilding
2023-04-08 15:19:37 -05:00
committed by GitHub
parent 59e0c5e264
commit 3dbbbd37d4
2 changed files with 29 additions and 0 deletions
+3
View File
@@ -35,3 +35,6 @@ jobs:
- name: Check for Unresolved Conflicts
run: python ./scripts/gsrc/check-for-conflicts.py
- name: Check for Incorrect Asserts
run: python ./scripts/ci/check-for-asserts.py
+26
View File
@@ -0,0 +1,26 @@
import glob
import re
folders_to_check = ["common", "decompiler", "game", "goalc", "test", "tools", "lsp"]
flagged_instances = []
for folder in folders_to_check:
files_to_check = glob.glob("./{}/**/*.cpp".format(folder), recursive=True)
files_to_check += glob.glob("./{}/**/*.h".format(folder), recursive=True)
for filename in files_to_check:
# Get the file contents
with open(filename, "r", encoding="utf-8") as f:
lines = f.readlines()
for i, line in enumerate(lines):
results = re.findall(r"\bassert\(", line)
if len(results) > 0:
flagged_instances.append(filename + ":" + str(i + 1))
if len(flagged_instances) == 0:
exit(0)
print("Found asserts in the following files:")
for file in flagged_instances:
print(file)
exit(1)