Skip to content

Commit 5965ca9

Browse files
Enhance test runner to support Objective-C groups
1 parent d1d9dfd commit 5965ca9

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

code/tests/tools/generate-runner.py renamed to code/tests/tools/runner.py

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import os
22
import re
3+
import sys
34

45

56
class TestRunnerGenerator:
67
def __init__(self):
78
# Set the directory to a subdirectory named 'cases' within the current working directory
89
self.directory = os.path.join(os.getcwd(), "cases")
10+
# Detect if running on Apple (macOS)
11+
self.is_apple = sys.platform == "darwin"
912

1013
def find_test_groups(self):
11-
test_groups = set()
14+
c_cpp_groups = set()
15+
objc_groups = set()
16+
objcpp_groups = set()
1217
pattern = r"FOSSIL_TEST_GROUP\((\w+)\)"
1318

1419
# Walk through files in the specified directory, 'cases'
1520
for root, _, files in os.walk(self.directory):
1621
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:
2025
content = f.read()
2126
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)
2333

24-
return list(test_groups)
34+
return list(c_cpp_groups), list(objc_groups), list(objcpp_groups)
2535

2636
def generate_c_runner(self, test_groups):
2737
# Prepare header content for the test runner
@@ -71,7 +81,12 @@ def generate_c_runner(self, test_groups):
7181

7282
# Instantiate the generator, find test groups, and generate the test runner
7383
generator = TestRunnerGenerator()
74-
test_groups = generator.find_test_groups()
84+
c_cpp_groups, objc_groups, objcpp_groups = generator.find_test_groups()
7585

76-
# Generate the test runner for C and C++ tests
77-
generator.generate_c_runner(test_groups)
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
92+
generator.generate_c_runner(test_groups)

0 commit comments

Comments
 (0)