Fix running tests in template builds

Also fixes some errors with 3D disabled
This commit is contained in:
A Thousand Ships
2024-02-23 15:53:37 +01:00
parent d8cbaa3a8b
commit c17688fa6c
9 changed files with 67 additions and 19 deletions

View File

@@ -45,6 +45,8 @@ public:
namespace TestProjectSettings {
// TODO: Handle some cases failing on release builds. See: https://github.com/godotengine/godot/pull/88452
#ifdef TOOLS_ENABLED
TEST_CASE("[ProjectSettings] Get existing setting") {
CHECK(ProjectSettings::get_singleton()->has_setting("application/config/name"));
@@ -64,6 +66,7 @@ TEST_CASE("[ProjectSettings] Default value is ignored if setting exists") {
String name = variant;
CHECK_EQ(name, "GDScript Integration Test Suite");
}
#endif // TOOLS_ENABLED
TEST_CASE("[ProjectSettings] Non existing setting is null") {
CHECK_FALSE(ProjectSettings::get_singleton()->has_setting("not_existing_setting"));

View File

@@ -88,11 +88,14 @@ TEST_CASE("[Image] Saving and loading") {
err == OK,
"The image should be saved successfully as a .png file.");
// Only available on editor builds.
#ifdef TOOLS_ENABLED
// Save EXR
err = image->save_exr(save_path_exr, false);
CHECK_MESSAGE(
err == OK,
"The image should be saved successfully as an .exr file.");
#endif // TOOLS_ENABLED
// Load using load()
Ref<Image> image_load = memnew(Image());
@@ -417,12 +420,16 @@ TEST_CASE("[Image] Convert image") {
Ref<Image> image = memnew(Image(4, 4, false, Image::FORMAT_RGBA8));
PackedByteArray image_data = image->get_data();
ERR_PRINT_OFF;
image->convert((Image::Format)-1);
ERR_PRINT_ON;
CHECK_MESSAGE(image->get_data() == image_data, "Image conversion to invalid type (-1) should not alter image.");
Ref<Image> image2 = memnew(Image(4, 4, false, Image::FORMAT_RGBA8));
image_data = image2->get_data();
ERR_PRINT_OFF;
image2->convert((Image::Format)(Image::FORMAT_MAX + 1));
ERR_PRINT_ON;
CHECK_MESSAGE(image2->get_data() == image_data, "Image conversion to invalid type (Image::FORMAT_MAX + 1) should not alter image.");
}

View File

@@ -93,6 +93,7 @@ TEST_CASE("[OS] Ticks") {
}
TEST_CASE("[OS] Feature tags") {
#ifdef TOOLS_ENABLED
CHECK_MESSAGE(
OS::get_singleton()->has_feature("editor"),
"The binary has the \"editor\" feature tag.");
@@ -105,6 +106,29 @@ TEST_CASE("[OS] Feature tags") {
CHECK_MESSAGE(
!OS::get_singleton()->has_feature("template_release"),
"The binary does not have the \"template_release\" feature tag.");
#else
CHECK_MESSAGE(
!OS::get_singleton()->has_feature("editor"),
"The binary does not have the \"editor\" feature tag.");
CHECK_MESSAGE(
OS::get_singleton()->has_feature("template"),
"The binary has the \"template\" feature tag.");
#ifdef DEBUG_ENABLED
CHECK_MESSAGE(
OS::get_singleton()->has_feature("template_debug"),
"The binary has the \"template_debug\" feature tag.");
CHECK_MESSAGE(
!OS::get_singleton()->has_feature("template_release"),
"The binary does not have the \"template_release\" feature tag.");
#else
CHECK_MESSAGE(
!OS::get_singleton()->has_feature("template_debug"),
"The binary does not have the \"template_debug\" feature tag.");
CHECK_MESSAGE(
OS::get_singleton()->has_feature("template_release"),
"The binary has the \"template_release\" feature tag.");
#endif // DEBUG_ENABLED
#endif // TOOLS_ENABLED
}
TEST_CASE("[OS] Process ID") {

View File

@@ -129,6 +129,7 @@ TEST_CASE("[TranslationPO] Plural messages") {
CHECK(vformat(translation->get_plural_message("There are %d apples", "", 2), 2) == "Il y a 2 pommes");
}
#ifdef TOOLS_ENABLED
TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages") {
Ref<Translation> translation = memnew(Translation);
translation->set_locale("fr");
@@ -150,7 +151,6 @@ TEST_CASE("[OptimizedTranslation] Generate from Translation and read messages")
CHECK(messages.size() == 0);
}
#ifdef TOOLS_ENABLED
TEST_CASE("[TranslationCSV] CSV import") {
Ref<ResourceImporterCSVTranslation> import_csv_translation = memnew(ResourceImporterCSVTranslation);

View File

@@ -101,14 +101,10 @@
#include "tests/scene/test_curve_2d.h"
#include "tests/scene/test_curve_3d.h"
#include "tests/scene/test_gradient.h"
#include "tests/scene/test_navigation_agent_2d.h"
#include "tests/scene/test_navigation_obstacle_2d.h"
#include "tests/scene/test_navigation_region_2d.h"
#include "tests/scene/test_node.h"
#include "tests/scene/test_node_2d.h"
#include "tests/scene/test_packed_scene.h"
#include "tests/scene/test_path_2d.h"
#include "tests/scene/test_primitives.h"
#include "tests/scene/test_sprite_frames.h"
#include "tests/scene/test_text_edit.h"
#include "tests/scene/test_theme.h"
@@ -116,15 +112,19 @@
#include "tests/scene/test_visual_shader.h"
#include "tests/scene/test_window.h"
#include "tests/servers/rendering/test_shader_preprocessor.h"
#include "tests/servers/test_navigation_server_2d.h"
#include "tests/servers/test_text_server.h"
#include "tests/test_validate_testing.h"
#ifndef _3D_DISABLED
#include "tests/scene/test_navigation_agent_2d.h"
#include "tests/scene/test_navigation_agent_3d.h"
#include "tests/scene/test_navigation_obstacle_2d.h"
#include "tests/scene/test_navigation_obstacle_3d.h"
#include "tests/scene/test_navigation_region_2d.h"
#include "tests/scene/test_navigation_region_3d.h"
#include "tests/scene/test_path_3d.h"
#include "tests/scene/test_primitives.h"
#include "tests/servers/test_navigation_server_2d.h"
#include "tests/servers/test_navigation_server_3d.h"
#endif // _3D_DISABLED
@@ -134,8 +134,10 @@
#include "tests/test_macros.h"
#include "scene/theme/theme_db.h"
#ifndef _3D_DISABLED
#include "servers/navigation_server_2d.h"
#include "servers/navigation_server_3d.h"
#endif // _3D_DISABLED
#include "servers/physics_server_2d.h"
#include "servers/physics_server_3d.h"
#include "servers/rendering/rendering_server_default.h"
@@ -214,8 +216,10 @@ struct GodotTestCaseListener : public doctest::IReporter {
PhysicsServer3D *physics_server_3d = nullptr;
PhysicsServer2D *physics_server_2d = nullptr;
#ifndef _3D_DISABLED
NavigationServer3D *navigation_server_3d = nullptr;
NavigationServer2D *navigation_server_2d = nullptr;
#endif // _3D_DISABLED
void test_case_start(const doctest::TestCaseData &p_in) override {
reinitialize();
@@ -253,10 +257,12 @@ struct GodotTestCaseListener : public doctest::IReporter {
physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server();
physics_server_2d->init();
#ifndef _3D_DISABLED
ERR_PRINT_OFF;
navigation_server_3d = NavigationServer3DManager::new_default_server();
navigation_server_2d = NavigationServer2DManager::new_default_server();
ERR_PRINT_ON;
#endif // _3D_DISABLED
memnew(InputMap);
InputMap::get_singleton()->load_default();
@@ -278,6 +284,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
return;
}
#ifndef _3D_DISABLED
if (suite_name.find("[Navigation]") != -1 && navigation_server_2d == nullptr && navigation_server_3d == nullptr) {
ERR_PRINT_OFF;
navigation_server_3d = NavigationServer3DManager::new_default_server();
@@ -285,6 +292,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
ERR_PRINT_ON;
return;
}
#endif // _3D_DISABLED
}
void test_case_end(const doctest::CurrentTestCaseStats &) override {
@@ -300,6 +308,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
memdelete(SceneTree::get_singleton());
}
#ifndef _3D_DISABLED
if (navigation_server_3d) {
memdelete(navigation_server_3d);
navigation_server_3d = nullptr;
@@ -309,6 +318,7 @@ struct GodotTestCaseListener : public doctest::IReporter {
memdelete(navigation_server_2d);
navigation_server_2d = nullptr;
}
#endif // _3D_DISABLED
if (physics_server_3d) {
physics_server_3d->finish();