@@ -30,64 +30,101 @@ def find_test_groups(self):
3030
3131 return list (c_test_groups ), list (cpp_test_groups )
3232
33- def generate_test_runner (self , c_test_groups , cpp_test_groups ):
34- # Prepare header content
33+ def generate_c_runner (self , c_test_groups ):
34+ # Prepare header content for C test runner
3535 header = """
36- // Generated Fossil Logic Test
36+ // Generated Fossil Logic Test (C)
3737#include <fossil/test/framework.h>
3838
3939// * * * * * * * * * * * * * * * * * * * * * * * *
40- // * Fossil Logic Test List
40+ // * Fossil Logic Test List (C)
4141// * * * * * * * * * * * * * * * * * * * * * * * *
4242"""
4343
4444 # Declare C test group externs within extern "C"
45- extern_c_pools = "extern \" C\" {\n " + "\n " .join (
46- [f" FOSSIL_TEST_EXPORT({ group } );" for group in c_test_groups ]
47- ) + "\n }\n "
48-
49- # Declare C++ test group externs without extern "C"
50- extern_cpp_pools = "\n " .join (
51- [f"FOSSIL_TEST_EXPORT({ group } );" for group in cpp_test_groups ]
45+ extern_c_pools = "\n " .join (
46+ [f"FOSSIL_TEST_EXPORT({ group } );" for group in c_test_groups ]
5247 )
5348
54- # Prepare runner content
55- runner = """
49+ # Prepare runner content for C
50+ runner = """\n
5651// * * * * * * * * * * * * * * * * * * * * * * * *
57- // * Fossil Logic Test Runner
52+ // * Fossil Logic Test Runner (C)
5853// * * * * * * * * * * * * * * * * * * * * * * * *
5954int main(int argc, char **argv) {
6055 FOSSIL_TEST_START(argc, argv);\n """
6156
62- # Import C and C++ test groups in the main function
57+ # Import C test groups in the main function
6358 import_c_pools = "\n " .join (
6459 [f" FOSSIL_TEST_IMPORT({ group } );" for group in c_test_groups ]
6560 )
61+
62+ # Complete with footer
63+ footer = """\n
64+ FOSSIL_TEST_RUN();
65+ FOSSIL_TEST_SUMMARY();
66+ FOSSIL_TEST_END();
67+ } // end of func
68+ """
69+
70+ # Write the generated C test runner to 'unit_runner_c.cpp'
71+ with open ("unit_runner.c" , "w" ) as file :
72+ 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
66103 import_cpp_pools = "\n " .join (
67104 [f" FOSSIL_TEST_IMPORT({ group } );" for group in cpp_test_groups ]
68105 )
69106
70107 # Complete with footer
71- footer = """
108+ footer = """\n
72109 FOSSIL_TEST_RUN();
73110 FOSSIL_TEST_SUMMARY();
74111 FOSSIL_TEST_END();
75112} // end of func
76113"""
77114
78- # Write the generated content to 'unit_runner .cpp'
115+ # Write the generated C++ test runner to 'unit_runner_cpp .cpp'
79116 with open ("unit_runner.cpp" , "w" ) as file :
80117 file .write (header )
81- file .write (extern_c_pools )
82118 file .write (extern_cpp_pools )
83119 file .write (runner )
84120 file .write (import_cpp_pools )
85- file .write ("\n " )
86- file .write (import_c_pools )
87121 file .write (footer )
88122
89123
90- # Instantiate the generator, find test groups, and generate the test runner
124+ # Instantiate the generator, find test groups, and generate the test runners
91125generator = TestRunnerGenerator ()
92126c_test_groups , cpp_test_groups = generator .find_test_groups ()
93- generator .generate_test_runner (c_test_groups , cpp_test_groups )
127+
128+ # Generate separate runners for C and C++
129+ generator .generate_c_runner (c_test_groups )
130+ generator .generate_cpp_runner (cpp_test_groups )
0 commit comments