From 60f53140b85748f6ce61c353facc15f45fd7ae4a Mon Sep 17 00:00:00 2001 From: "Andrii Doroshenko (Xrayez)" Date: Sun, 26 Jul 2020 14:46:44 +0300 Subject: [PATCH] Enable support for C++ modules tests Modules-specific tests can be written under respective module folders. Each module should have "tests" folder created with the tests implemented as `doctest` headers, so they can be collected by the buildsystem and included directly in `tests/test_main.cpp` to be compiled. --- modules/SCsub | 13 +++++++++++-- modules/modules_builders.py | 11 +++++++++++ tests/test_main.cpp | 2 ++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/modules/SCsub b/modules/SCsub index 9155a53eafd..2d774306e45 100644 --- a/modules/SCsub +++ b/modules/SCsub @@ -1,10 +1,10 @@ #!/usr/bin/env python -Import("env") - import modules_builders import os +Import("env") + env_modules = env.Clone() Export("env_modules") @@ -12,6 +12,15 @@ Export("env_modules") # Header with MODULE_*_ENABLED defines. env.CommandNoCache("modules_enabled.gen.h", Value(env.module_list), modules_builders.generate_modules_enabled) +# Header to be included in `tests/test_main.cpp` to run module-specific tests. +if env["tests"]: + env.CommandNoCache( + "modules_tests.gen.h", + Value(env.module_list), + Action(modules_builders.generate_modules_tests, "Generating modules tests header."), + ) + env.AlwaysBuild("modules_tests.gen.h") + vs_sources = [] # libmodule_.a for each active module. for name, path in env.module_list.items(): diff --git a/modules/modules_builders.py b/modules/modules_builders.py index e7be6380d1d..22431625559 100644 --- a/modules/modules_builders.py +++ b/modules/modules_builders.py @@ -12,5 +12,16 @@ def generate_modules_enabled(target, source, env): f.write("#define %s\n" % ("MODULE_" + module.upper() + "_ENABLED")) +def generate_modules_tests(target, source, env): + import os + import glob + + with open(target[0].path, "w") as f: + for name, path in env.module_list.items(): + headers = glob.glob(os.path.join(path, "tests", "*.h")) + for h in headers: + f.write('#include "%s"\n' % (os.path.normpath(h))) + + if __name__ == "__main__": subprocess_main(globals()) diff --git a/tests/test_main.cpp b/tests/test_main.cpp index 91eff28f86f..0fb9f2fcda0 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -49,6 +49,8 @@ #include "test_string.h" #include "test_validate_testing.h" +#include "modules/modules_tests.gen.h" + #include "thirdparty/doctest/doctest.h" const char **tests_get_names() {