Check if a header file has #pragma once directive or if a cpp file incorrectly has it.
(self, file_path: str)
| 23 | |
| 24 | class TestMissingPragmaOnce(unittest.TestCase): |
| 25 | def check_file(self, file_path: str) -> list[str]: |
| 26 | """Check if a header file has #pragma once directive or if a cpp file incorrectly has it.""" |
| 27 | failings: list[str] = [] |
| 28 | |
| 29 | with open(file_path, "r", encoding="utf-8", errors="ignore") as f: |
| 30 | content = f.read() |
| 31 | |
| 32 | if file_path.endswith(".h"): |
| 33 | # For header files, check if #pragma once is missing |
| 34 | if "#pragma once" not in content: |
| 35 | failings.append(f"Missing #pragma once in {file_path}") |
| 36 | elif file_path.endswith(".cpp"): |
| 37 | # For cpp files, check if #pragma once is incorrectly present |
| 38 | if "#pragma once" in content: |
| 39 | failings.append(f"Incorrect #pragma once in cpp file: {file_path}") |
| 40 | |
| 41 | return failings |
| 42 | |
| 43 | def test_pragma_once_usage(self) -> None: |
| 44 | """ |