diff --git a/code/logic/fossil/test/testing.h b/code/logic/fossil/test/testing.h index 302951d3..7f9633fd 100644 --- a/code/logic/fossil/test/testing.h +++ b/code/logic/fossil/test/testing.h @@ -362,8 +362,13 @@ void fossil_test_print_stack_trace(stack_frame_t *stack_trace); * * @param name The name of the test group. */ +#ifdef __cplusplus +#define _FOSSIL_TEST_GROUP(name) \ + extern "C" void name##_test_group(fossil_test_env_t *_env) +#else #define _FOSSIL_TEST_GROUP(name) \ void name##_test_group(fossil_test_env_t *_env) +#endif /** * @brief Macro to export a test group. diff --git a/code/tests/meson.build b/code/tests/meson.build index 33aae7d9..41da644b 100644 --- a/code/tests/meson.build +++ b/code/tests/meson.build @@ -2,19 +2,14 @@ if get_option('with_test').enabled() run_command(['python3', 'tools' / 'generate-runner.py'], check: true) test_c = ['unit_runner.c'] - test_cpp = ['unit_runner.cpp'] - test_cases = [ - 'sample', 'bdd', 'tdd', 'ddd', 'mark' - ] + test_cases = ['sample', 'bdd', 'tdd', 'ddd', 'mark'] foreach cases : test_cases test_c += ['cases' / 'test_' + cases + '.c'] - test_cpp += ['cases' / 'test_' + cases + '.cpp'] + test_c += ['cases' / 'test_' + cases + '.cpp'] endforeach - pizza_c = executable('testbed-c', test_c, include_directories: dir, dependencies: [fossil_test_dep]) - pizza_cpp = executable('testbed-cpp', test_cpp, include_directories: dir, dependencies: [fossil_test_dep]) + pizza_c = executable('testbed-c', test_c, include_directories: dir, dependencies: [fossil_test_dep]) - test('fossil testing C ', pizza_c ) - test('fossil testing Cpp', pizza_cpp) -endif + test('fossil testing C', pizza_c) +endif \ No newline at end of file diff --git a/code/tests/tools/generate-runner.py b/code/tests/tools/generate-runner.py index cda8be52..848b24e0 100644 --- a/code/tests/tools/generate-runner.py +++ b/code/tests/tools/generate-runner.py @@ -8,55 +8,48 @@ def __init__(self): self.directory = os.path.join(os.getcwd(), "cases") def find_test_groups(self): - c_test_groups = set() - cpp_test_groups = set() + test_groups = set() pattern = r"FOSSIL_TEST_GROUP\((\w+)\)" # Walk through files in the specified directory, 'cases' for root, _, files in os.walk(self.directory): for file in files: - # Search for C files - if file.startswith("test_") and file.endswith(".c"): + # Search for C and C++ files + if (file.startswith("test_") and file.endswith(".c")) or file.endswith(".cpp"): with open(os.path.join(root, file), "r") as f: content = f.read() matches = re.findall(pattern, content) - c_test_groups.update(matches) - # Search for C++ files - elif file.startswith("test_") and file.endswith(".cpp"): - with open(os.path.join(root, file), "r") as f: - content = f.read() - matches = re.findall(pattern, content) - cpp_test_groups.update(matches) + test_groups.update(matches) - return list(c_test_groups), list(cpp_test_groups) + return list(test_groups) - def generate_c_runner(self, c_test_groups): - # Prepare header content for C test runner + def generate_c_runner(self, test_groups): + # Prepare header content for the test runner header = """ -// Generated Fossil Logic Test (C) +// Generated Fossil Logic Test Runner #include // * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test List (C) +// * Fossil Logic Test List // * * * * * * * * * * * * * * * * * * * * * * * * """ - # Declare C test group externs within extern "C" - extern_c_pools = "\n".join( - [f"FOSSIL_TEST_EXPORT({group});" for group in c_test_groups] + # Declare test group externs + extern_test_groups = "\n".join( + [f"FOSSIL_TEST_EXPORT({group});" for group in test_groups] ) - # Prepare runner content for C + # Prepare runner content runner = """\n // * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Runner (C) +// * Fossil Logic Test Runner // * * * * * * * * * * * * * * * * * * * * * * * * int main(int argc, char **argv) { FOSSIL_TEST_START(argc, argv);\n""" - # Import C test groups in the main function - import_c_pools = "\n".join( - [f" FOSSIL_TEST_IMPORT({group});" for group in c_test_groups] + # Import test groups in the main function + import_test_groups = "\n".join( + [f" FOSSIL_TEST_IMPORT({group});" for group in test_groups] ) # Complete with footer @@ -64,67 +57,21 @@ def generate_c_runner(self, c_test_groups): FOSSIL_TEST_RUN(); FOSSIL_TEST_SUMMARY(); FOSSIL_TEST_END(); -} // end of func +} // end of main """ - # Write the generated C test runner to 'unit_runner_c.cpp' + # Write the generated test runner to 'unit_runner.c' with open("unit_runner.c", "w") as file: file.write(header) - file.write(extern_c_pools) - file.write(runner) - file.write(import_c_pools) - file.write(footer) - - def generate_cpp_runner(self, cpp_test_groups): - # Prepare header content for C++ test runner - header = """ -// Generated Fossil Logic Test (C++) -#include - -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test List (C++) -// * * * * * * * * * * * * * * * * * * * * * * * * -""" - - # Declare C++ test group externs - extern_cpp_pools = "\n".join( - [f"FOSSIL_TEST_EXPORT({group});" for group in cpp_test_groups] - ) - - # Prepare runner content for C++ - runner = """\n -// * * * * * * * * * * * * * * * * * * * * * * * * -// * Fossil Logic Test Runner (C++) -// * * * * * * * * * * * * * * * * * * * * * * * * -int main(int argc, char **argv) { - FOSSIL_TEST_START(argc, argv);\n""" - - # Import C++ test groups in the main function - import_cpp_pools = "\n".join( - [f" FOSSIL_TEST_IMPORT({group});" for group in cpp_test_groups] - ) - - # Complete with footer - footer = """\n - FOSSIL_TEST_RUN(); - FOSSIL_TEST_SUMMARY(); - FOSSIL_TEST_END(); -} // end of func -""" - - # Write the generated C++ test runner to 'unit_runner_cpp.cpp' - with open("unit_runner.cpp", "w") as file: - file.write(header) - file.write(extern_cpp_pools) + file.write(extern_test_groups) file.write(runner) - file.write(import_cpp_pools) + file.write(import_test_groups) file.write(footer) -# Instantiate the generator, find test groups, and generate the test runners +# Instantiate the generator, find test groups, and generate the test runner generator = TestRunnerGenerator() -c_test_groups, cpp_test_groups = generator.find_test_groups() +test_groups = generator.find_test_groups() -# Generate separate runners for C and C++ -generator.generate_c_runner(c_test_groups) -generator.generate_cpp_runner(cpp_test_groups) +# Generate the test runner for C and C++ tests +generator.generate_c_runner(test_groups)