|
1 | 1 | import os |
2 | 2 | import re |
| 3 | +import sys |
3 | 4 |
|
4 | 5 |
|
5 | 6 | class TestRunnerGenerator: |
6 | 7 | def __init__(self): |
7 | 8 | # Set the directory to a subdirectory named 'cases' within the current working directory |
8 | 9 | self.directory = os.path.join(os.getcwd(), "cases") |
| 10 | + # Detect if running on Apple (macOS) |
| 11 | + self.is_apple = sys.platform == "darwin" |
9 | 12 |
|
10 | 13 | def find_test_groups(self): |
11 | | - test_groups = set() |
| 14 | + c_cpp_groups = set() |
| 15 | + objc_groups = set() |
| 16 | + objcpp_groups = set() |
12 | 17 | pattern = r"FOSSIL_TEST_GROUP\((\w+)\)" |
13 | 18 |
|
14 | 19 | # Walk through files in the specified directory, 'cases' |
15 | 20 | for root, _, files in os.walk(self.directory): |
16 | 21 | for file in files: |
17 | | - # Search for C and C++ files |
18 | | - if (file.startswith("test_") and file.endswith(".c")) or file.endswith(".cpp"): |
19 | | - with open(os.path.join(root, file), "r") as f: |
| 22 | + if file.startswith("test_"): |
| 23 | + file_path = os.path.join(root, file) |
| 24 | + with open(file_path, "r") as f: |
20 | 25 | content = f.read() |
21 | 26 | matches = re.findall(pattern, content) |
22 | | - test_groups.update(matches) |
| 27 | + if file.endswith(".c") or file.endswith(".cpp"): |
| 28 | + c_cpp_groups.update(matches) |
| 29 | + elif self.is_apple and file.endswith(".m"): |
| 30 | + objc_groups.update(matches) |
| 31 | + elif self.is_apple and file.endswith(".mm"): |
| 32 | + objcpp_groups.update(matches) |
23 | 33 |
|
24 | | - return list(test_groups) |
| 34 | + return list(c_cpp_groups), list(objc_groups), list(objcpp_groups) |
25 | 35 |
|
26 | 36 | def generate_c_runner(self, test_groups): |
27 | 37 | # Prepare header content for the test runner |
@@ -71,7 +81,12 @@ def generate_c_runner(self, test_groups): |
71 | 81 |
|
72 | 82 | # Instantiate the generator, find test groups, and generate the test runner |
73 | 83 | generator = TestRunnerGenerator() |
74 | | -test_groups = generator.find_test_groups() |
| 84 | +c_cpp_groups, objc_groups, objcpp_groups = generator.find_test_groups() |
75 | 85 |
|
76 | | -# Generate the test runner for C and C++ tests |
| 86 | +# Only include Objective-C/Objective-C++ groups if on Apple |
| 87 | +test_groups = c_cpp_groups |
| 88 | +if generator.is_apple: |
| 89 | + test_groups += objc_groups + objcpp_groups |
| 90 | + |
| 91 | +# Generate the test runner for C and C++ (and Objective-C/Objective-C++ on Apple) tests |
77 | 92 | generator.generate_c_runner(test_groups) |
0 commit comments