@@ -8,123 +8,70 @@ def __init__(self):
88 self .directory = os .path .join (os .getcwd (), "cases" )
99
1010 def find_test_groups (self ):
11- c_test_groups = set ()
12- cpp_test_groups = set ()
11+ test_groups = set ()
1312 pattern = r"FOSSIL_TEST_GROUP\((\w+)\)"
1413
1514 # Walk through files in the specified directory, 'cases'
1615 for root , _ , files in os .walk (self .directory ):
1716 for file in files :
18- # Search for C files
19- if file .startswith ("test_" ) and file .endswith (".c" ):
17+ # Search for C and C++ files
18+ if ( file .startswith ("test_" ) and file .endswith (".c" )) or file . endswith ( ".cpp " ):
2019 with open (os .path .join (root , file ), "r" ) as f :
2120 content = f .read ()
2221 matches = re .findall (pattern , content )
23- c_test_groups .update (matches )
24- # Search for C++ files
25- elif file .startswith ("test_" ) and file .endswith (".cpp" ):
26- with open (os .path .join (root , file ), "r" ) as f :
27- content = f .read ()
28- matches = re .findall (pattern , content )
29- cpp_test_groups .update (matches )
22+ test_groups .update (matches )
3023
31- return list (c_test_groups ), list ( cpp_test_groups )
24+ return list (test_groups )
3225
33- def generate_c_runner (self , c_test_groups ):
34- # Prepare header content for C test runner
26+ def generate_c_runner (self , test_groups ):
27+ # Prepare header content for the test runner
3528 header = """
36- // Generated Fossil Logic Test (C)
29+ // Generated Fossil Logic Test Runner
3730#include <fossil/test/framework.h>
3831
3932// * * * * * * * * * * * * * * * * * * * * * * * *
40- // * Fossil Logic Test List (C)
33+ // * Fossil Logic Test List
4134// * * * * * * * * * * * * * * * * * * * * * * * *
4235"""
4336
44- # Declare C test group externs within extern "C"
45- extern_c_pools = "\n " .join (
46- [f"FOSSIL_TEST_EXPORT({ group } );" for group in c_test_groups ]
37+ # Declare test group externs
38+ extern_test_groups = "\n " .join (
39+ [f"FOSSIL_TEST_EXPORT({ group } );" for group in test_groups ]
4740 )
4841
49- # Prepare runner content for C
42+ # Prepare runner content
5043 runner = """\n
5144// * * * * * * * * * * * * * * * * * * * * * * * *
52- // * Fossil Logic Test Runner (C)
45+ // * Fossil Logic Test Runner
5346// * * * * * * * * * * * * * * * * * * * * * * * *
5447int main(int argc, char **argv) {
5548 FOSSIL_TEST_START(argc, argv);\n """
5649
57- # Import C test groups in the main function
58- import_c_pools = "\n " .join (
59- [f" FOSSIL_TEST_IMPORT({ group } );" for group in c_test_groups ]
50+ # Import test groups in the main function
51+ import_test_groups = "\n " .join (
52+ [f" FOSSIL_TEST_IMPORT({ group } );" for group in test_groups ]
6053 )
6154
6255 # Complete with footer
6356 footer = """\n
6457 FOSSIL_TEST_RUN();
6558 FOSSIL_TEST_SUMMARY();
6659 FOSSIL_TEST_END();
67- } // end of func
60+ } // end of main
6861"""
6962
70- # Write the generated C test runner to 'unit_runner_c.cpp '
63+ # Write the generated test runner to 'unit_runner.c '
7164 with open ("unit_runner.c" , "w" ) as file :
7265 file .write (header )
73- file .write (extern_c_pools )
74- file .write (runner )
75- file .write (import_c_pools )
76- file .write (footer )
77-
78- def generate_cpp_runner (self , cpp_test_groups ):
79- # Prepare header content for C++ test runner
80- header = """
81- // Generated Fossil Logic Test (C++)
82- #include <fossil/test/framework.h>
83-
84- // * * * * * * * * * * * * * * * * * * * * * * * *
85- // * Fossil Logic Test List (C++)
86- // * * * * * * * * * * * * * * * * * * * * * * * *
87- """
88-
89- # Declare C++ test group externs
90- extern_cpp_pools = "\n " .join (
91- [f"FOSSIL_TEST_EXPORT({ group } );" for group in cpp_test_groups ]
92- )
93-
94- # Prepare runner content for C++
95- runner = """\n
96- // * * * * * * * * * * * * * * * * * * * * * * * *
97- // * Fossil Logic Test Runner (C++)
98- // * * * * * * * * * * * * * * * * * * * * * * * *
99- int main(int argc, char **argv) {
100- FOSSIL_TEST_START(argc, argv);\n """
101-
102- # Import C++ test groups in the main function
103- import_cpp_pools = "\n " .join (
104- [f" FOSSIL_TEST_IMPORT({ group } );" for group in cpp_test_groups ]
105- )
106-
107- # Complete with footer
108- footer = """\n
109- FOSSIL_TEST_RUN();
110- FOSSIL_TEST_SUMMARY();
111- FOSSIL_TEST_END();
112- } // end of func
113- """
114-
115- # Write the generated C++ test runner to 'unit_runner_cpp.cpp'
116- with open ("unit_runner.cpp" , "w" ) as file :
117- file .write (header )
118- file .write (extern_cpp_pools )
66+ file .write (extern_test_groups )
11967 file .write (runner )
120- file .write (import_cpp_pools )
68+ file .write (import_test_groups )
12169 file .write (footer )
12270
12371
124- # Instantiate the generator, find test groups, and generate the test runners
72+ # Instantiate the generator, find test groups, and generate the test runner
12573generator = TestRunnerGenerator ()
126- c_test_groups , cpp_test_groups = generator .find_test_groups ()
74+ test_groups = generator .find_test_groups ()
12775
128- # Generate separate runners for C and C++
129- generator .generate_c_runner (c_test_groups )
130- generator .generate_cpp_runner (cpp_test_groups )
76+ # Generate the test runner for C and C++ tests
77+ generator .generate_c_runner (test_groups )
0 commit comments