Checker that ensures test .cpp and .hpp files use FL_TEST_FILE(FL_FILEPATH) { ... }.
| 50 | |
| 51 | |
| 52 | class TestFileWrapperChecker(FileContentChecker): |
| 53 | """Checker that ensures test .cpp and .hpp files use FL_TEST_FILE(FL_FILEPATH) { ... }.""" |
| 54 | |
| 55 | def __init__(self) -> None: |
| 56 | self.violations: dict[str, list[tuple[int, str]]] = {} |
| 57 | |
| 58 | def should_process_file(self, file_path: str) -> bool: |
| 59 | if not file_path.startswith(str(TESTS_ROOT)): |
| 60 | return False |
| 61 | |
| 62 | if not file_path.endswith((".cpp", ".hpp")): |
| 63 | return False |
| 64 | |
| 65 | # Skip .cpp.hpp utility files (e.g., server_thread.cpp.hpp) |
| 66 | if file_path.endswith(".cpp.hpp"): |
| 67 | return False |
| 68 | |
| 69 | path = Path(file_path) |
| 70 | |
| 71 | # Skip exempt filenames |
| 72 | if path.name in EXEMPT_FILES: |
| 73 | return False |
| 74 | |
| 75 | # Skip files matching exempt patterns |
| 76 | file_name = path.name |
| 77 | for pattern in EXEMPT_PATTERNS: |
| 78 | if pattern in file_name: |
| 79 | return False |
| 80 | |
| 81 | # Skip directories containing exempt patterns |
| 82 | path_str = str(path).replace("\\", "/") |
| 83 | for pattern in EXEMPT_PATTERNS: |
| 84 | if f"/{pattern}/" in path_str or pattern in path.parts: |
| 85 | return False |
| 86 | |
| 87 | # Skip exempt directories |
| 88 | for exempt_dir in EXEMPT_DIRS: |
| 89 | try: |
| 90 | path.relative_to(exempt_dir) |
| 91 | return False |
| 92 | except ValueError: |
| 93 | continue |
| 94 | |
| 95 | return True |
| 96 | |
| 97 | def check_file_content(self, file_content: FileContent) -> list[str]: |
| 98 | violations: list[tuple[int, str]] = [] |
| 99 | |
| 100 | has_fl_test_file = False |
| 101 | has_fl_test_case = False |
| 102 | fl_test_file_line = -1 |
| 103 | closing_brace_line = -1 |
| 104 | last_include_line = -1 |
| 105 | first_ifdef_line = -1 |
| 106 | |
| 107 | for i, line in enumerate(file_content.lines): |
| 108 | # Track last include |
| 109 | if line.strip().startswith("#include"): |