Skip to content

Commit 6627755

Browse files
change runner experament to do both seperatly
1 parent e345518 commit 6627755

File tree

2 files changed

+70
-28
lines changed

2 files changed

+70
-28
lines changed

code/tests/meson.build

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
if get_option('with_test').enabled()
22
run_command(['python3', 'tools' / 'generate-runner.py'], check: true)
33

4-
test_src = ['unit_runner.cpp']
5-
test_cubes = [
4+
test_c = ['unit_runner.c']
5+
test_cpp = ['unit_runner.cpp']
6+
test_cases = [
67
'sample', 'bdd', 'tdd',
78
]
89

9-
foreach cube : test_cubes
10-
test_src += ['cases' / 'test_' + cube + '.c', 'cases' / 'test_' + cube + '.cpp']
10+
foreach cases : test_cases
11+
test_c += ['cases' / 'test_' + cases + '.c']
12+
test_cpp += ['cases' / 'test_' + cases + '.cpp']
1113
endforeach
1214

13-
pizza = executable('testbed', test_src, include_directories: dir, dependencies: [fossil_test_dep])
14-
test('fossil_tests', pizza) # Renamed the test target for clarity
15+
pizza_c = executable('testbed-c', test_c, include_directories: dir, dependencies: [fossil_test_dep])
16+
pizza_cpp = executable('testbed-cpp', test_cpp, include_directories: dir, dependencies: [fossil_test_dep])
17+
18+
test('fossil testing C ', pizza_c )
19+
test('fossil testing Cpp', pizza_cpp)
1520
endif

code/tests/tools/generate-runner.py

Lines changed: 59 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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
// * * * * * * * * * * * * * * * * * * * * * * * *
5954
int 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
91125
generator = TestRunnerGenerator()
92126
c_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

Comments
 (0)