Extract a unique test name from a test file path. Naming rules: - fl/*.cpp files: prefix with "fl_" and include subdirectories (e.g., fl/algorithm.cpp -> fl_algorithm, fl/channels/spi.cpp -> fl_channels_spi) - fx/*.cpp files: prefix with "fx_" and include subdirectories
(test_file_path: str)
| 8 | |
| 9 | |
| 10 | def extract_test_name(test_file_path: str) -> str: |
| 11 | """ |
| 12 | Extract a unique test name from a test file path. |
| 13 | |
| 14 | Naming rules: |
| 15 | - fl/*.cpp files: prefix with "fl_" and include subdirectories |
| 16 | (e.g., fl/algorithm.cpp -> fl_algorithm, fl/channels/spi.cpp -> fl_channels_spi) |
| 17 | - fx/*.cpp files: prefix with "fx_" and include subdirectories |
| 18 | (e.g., fx/engine.cpp -> fx_engine) |
| 19 | - Other files: use basename without .cpp (e.g., noise/test_noise.cpp -> test_noise) |
| 20 | |
| 21 | Args: |
| 22 | test_file_path: Relative path to test file (POSIX format) |
| 23 | |
| 24 | Returns: |
| 25 | Test name to use as executable name |
| 26 | """ |
| 27 | # Remove .cpp extension |
| 28 | path_no_ext = test_file_path.replace(".cpp", "") |
| 29 | |
| 30 | # For fl/, fx/ subdirectories, convert path to name with underscores |
| 31 | # This ensures uniqueness for nested files (e.g., fl/channels/spi.cpp vs fl/spi.cpp) |
| 32 | if test_file_path.startswith("fl/"): |
| 33 | # Replace / with _ to create unique name: fl/channels/spi.cpp -> fl_channels_spi |
| 34 | return path_no_ext.replace("/", "_") |
| 35 | elif test_file_path.startswith("fx/"): |
| 36 | return path_no_ext.replace("/", "_") |
| 37 | else: |
| 38 | # For other files, just use basename |
| 39 | return path_no_ext.split("/")[-1] |
| 40 | |
| 41 | |
| 42 | def categorize_test(test_name: str, test_file_path: str) -> str: |