Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SCons: Add tests option to enable or disable unit tests #40696

Merged
merged 1 commit into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/linux_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
env:
SCONS_CACHE: ${{github.workspace}}/.scons_cache/
run: |
scons -j2 verbose=yes warnings=all werror=yes platform=linuxbsd tools=yes target=release_debug module_mono_enabled=yes mono_glue=no
scons -j2 verbose=yes warnings=all werror=yes platform=linuxbsd tools=yes tests=yes target=release_debug module_mono_enabled=yes mono_glue=no

# Execute unit tests for the editor
- name: Unit Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/macos_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
env:
SCONS_CACHE: ${{github.workspace}}/.scons_cache/
run: |
scons -j2 verbose=yes warnings=all werror=yes platform=osx tools=yes target=release_debug
scons -j2 verbose=yes warnings=all werror=yes platform=osx tools=yes tests=yes target=release_debug

# Execute unit tests for the editor
- name: Unit Tests
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/windows_builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
env:
SCONS_CACHE: /.scons_cache/
run: |
scons -j2 verbose=yes warnings=all werror=yes platform=windows tools=yes target=release_debug
scons -j2 verbose=yes warnings=all werror=yes platform=windows tools=yes tests=yes target=release_debug

# Execute unit tests for the editor
- name: Unit Tests
Expand Down
14 changes: 12 additions & 2 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ opts.Add(EnumVariable("target", "Compilation target", "debug", ("debug", "releas
opts.Add(EnumVariable("optimize", "Optimization type", "speed", ("speed", "size")))

opts.Add(BoolVariable("tools", "Build the tools (a.k.a. the Godot editor)", True))
opts.Add(BoolVariable("tests", "Build the unit tests", False))
opts.Add(BoolVariable("use_lto", "Use link-time optimization", False))
opts.Add(BoolVariable("use_precise_math_checks", "Math checks use very precise epsilon (debug option)", False))

Expand Down Expand Up @@ -249,6 +250,10 @@ if env_base["target"] == "debug":
# http://scons.org/doc/production/HTML/scons-user/ch06s04.html
env_base.SetOption("implicit_cache", 1)

if not env_base["tools"]:
# Export templates can't run unit test tool.
env_base["tests"] = False

if env_base["no_editor_splash"]:
env_base.Append(CPPDEFINES=["NO_EDITOR_SPLASH"])

Expand Down Expand Up @@ -312,6 +317,8 @@ if selected_platform in platform_list:
env["verbose"] = True
env["warnings"] = "extra"
env["werror"] = True
if env["tools"]:
env["tests"] = True

if env["vsproj"]:
env.vs_incs = []
Expand Down Expand Up @@ -586,6 +593,8 @@ if selected_platform in platform_list:
env.Append(CPPDEFINES=["PTRCALL_ENABLED"])
if env["tools"]:
env.Append(CPPDEFINES=["TOOLS_ENABLED"])
if env["tests"]:
env.Append(CPPDEFINES=["TESTS_ENABLED"])
if env["disable_3d"]:
if env["tools"]:
print(
Expand Down Expand Up @@ -641,8 +650,9 @@ if selected_platform in platform_list:
}
)

# enable test framework globally and inform it of configuration method
env.Append(CPPDEFINES=["DOCTEST_CONFIG_IMPLEMENT"])
# Enable test framework globally and inform it of configuration method.
if env["tests"]:
env.Append(CPPDEFINES=["DOCTEST_CONFIG_IMPLEMENT"])

scons_cache_path = os.environ.get("SCONS_CACHE")
if scons_cache_path != None:
Expand Down
2 changes: 1 addition & 1 deletion main/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ env.CommandNoCache(
env.Depends("#main/app_icon.gen.h", "#main/app_icon.png")
env.CommandNoCache("#main/app_icon.gen.h", "#main/app_icon.png", run_in_subprocess(main_builders.make_app_icon))

if env["tools"]:
if env["tests"]:
SConscript("tests/SCsub")

lib = env.add_library("main", env.main_sources)
Expand Down
10 changes: 8 additions & 2 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
#include "main/performance.h"
#include "main/splash.gen.h"
#include "main/splash_editor.gen.h"
#include "main/tests/test_main.h"
#include "modules/modules_enabled.gen.h"
#include "modules/register_module_types.h"
#include "platform/register_platform_apis.h"
Expand All @@ -75,6 +74,10 @@
#include "servers/rendering/rendering_server_wrap_mt.h"
#include "servers/xr_server.h"

#ifdef TESTS_ENABLED
#include "main/tests/test_main.h"
#endif

#ifdef TOOLS_ENABLED

#include "editor/doc_data.h"
Expand Down Expand Up @@ -383,6 +386,7 @@ void Main::print_help(const char *p_binary) {
OS::get_singleton()->print(
" --gdnative-generate-json-api Generate JSON dump of the Godot API for GDNative bindings.\n");
#endif
#ifdef TESTS_ENABLED
OS::get_singleton()->print(" --test <test> Run a unit test [");
const char **test_names = tests_get_names();
const char *comma = "";
Expand All @@ -392,11 +396,13 @@ void Main::print_help(const char *p_binary) {
comma = ", ";
}
OS::get_singleton()->print("].\n");
#endif
OS::get_singleton()->print("\n");
#endif
}

int Main::test_entrypoint(int argc, char *argv[], bool &tests_need_run) {
#ifdef TOOLS_ENABLED // templates can't run unit test tool
#ifdef TESTS_ENABLED
for (int x = 0; x < argc; x++) {
if (strncmp(argv[x], "--test", 6) == 0) {
tests_need_run = true;
Expand Down