فهرست منبع

Merge pull request #88759 from AThousandShips/template_test_4_2

[4.2] Fix running tests in template builds
Rémi Verschelde 1 سال پیش
والد
کامیت
c44ae1fdd4

+ 3 - 0
modules/gdscript/tests/gdscript_test_runner_suite.h

@@ -37,6 +37,8 @@
 
 namespace GDScriptTests {
 
+// TODO: Handle some cases failing on release builds. See: https://github.com/godotengine/godot/pull/88452
+#ifdef TOOLS_ENABLED
 TEST_SUITE("[Modules][GDScript]") {
 	// GDScript 2.0 is still under heavy construction.
 	// Allow the tests to fail, but do not ignore errors during development.
@@ -70,6 +72,7 @@ func _init():
 	ref_counted->set_script(gdscript);
 	CHECK_MESSAGE(int(ref_counted->get_meta("result")) == 42, "The script should assign object metadata successfully.");
 }
+#endif // TOOLS_ENABLED
 
 TEST_CASE("[Modules][GDScript] Validate built-in API") {
 	GDScriptLanguage *lang = GDScriptLanguage::get_singleton();

+ 1 - 1
scene/main/viewport.cpp

@@ -4686,10 +4686,10 @@ void Viewport::_bind_methods() {
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scaling_3d_scale", PROPERTY_HINT_RANGE, "0.25,2.0,0.01"), "set_scaling_3d_scale", "get_scaling_3d_scale");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "texture_mipmap_bias", PROPERTY_HINT_RANGE, "-2,2,0.001"), "set_texture_mipmap_bias", "get_texture_mipmap_bias");
 	ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "fsr_sharpness", PROPERTY_HINT_RANGE, "0,2,0.1"), "set_fsr_sharpness", "get_fsr_sharpness");
-#endif
 	ADD_GROUP("Variable Rate Shading", "vrs_");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "vrs_mode", PROPERTY_HINT_ENUM, "Disabled,Texture,Depth buffer,XR"), "set_vrs_mode", "get_vrs_mode");
 	ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "vrs_texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_vrs_texture", "get_vrs_texture");
+#endif // _3D_DISABLED
 	ADD_GROUP("Canvas Items", "canvas_item_");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), "set_default_canvas_item_texture_filter", "get_default_canvas_item_texture_filter");
 	ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirror"), "set_default_canvas_item_texture_repeat", "get_default_canvas_item_texture_repeat");

+ 11 - 12
scene/register_scene_types.cpp

@@ -146,24 +146,18 @@
 #include "scene/resources/audio_stream_wav.h"
 #include "scene/resources/bit_map.h"
 #include "scene/resources/bone_map.h"
-#include "scene/resources/box_shape_3d.h"
 #include "scene/resources/camera_attributes.h"
 #include "scene/resources/camera_texture.h"
 #include "scene/resources/capsule_shape_2d.h"
-#include "scene/resources/capsule_shape_3d.h"
 #include "scene/resources/circle_shape_2d.h"
 #include "scene/resources/compressed_texture.h"
 #include "scene/resources/concave_polygon_shape_2d.h"
-#include "scene/resources/concave_polygon_shape_3d.h"
 #include "scene/resources/convex_polygon_shape_2d.h"
-#include "scene/resources/convex_polygon_shape_3d.h"
 #include "scene/resources/curve_texture.h"
-#include "scene/resources/cylinder_shape_3d.h"
 #include "scene/resources/environment.h"
 #include "scene/resources/font.h"
 #include "scene/resources/gradient.h"
 #include "scene/resources/gradient_texture.h"
-#include "scene/resources/height_map_shape_3d.h"
 #include "scene/resources/image_texture.h"
 #include "scene/resources/immediate_mesh.h"
 #include "scene/resources/label_settings.h"
@@ -181,12 +175,10 @@
 #include "scene/resources/placeholder_textures.h"
 #include "scene/resources/polygon_path_finder.h"
 #include "scene/resources/portable_compressed_texture.h"
-#include "scene/resources/primitive_meshes.h"
 #include "scene/resources/rectangle_shape_2d.h"
 #include "scene/resources/resource_format_text.h"
 #include "scene/resources/segment_shape_2d.h"
 #include "scene/resources/separation_ray_shape_2d.h"
-#include "scene/resources/separation_ray_shape_3d.h"
 #include "scene/resources/shader_include.h"
 #include "scene/resources/skeleton_modification_2d.h"
 #include "scene/resources/skeleton_modification_2d_ccdik.h"
@@ -199,8 +191,6 @@
 #include "scene/resources/skeleton_modification_stack_2d.h"
 #include "scene/resources/skeleton_profile.h"
 #include "scene/resources/sky.h"
-#include "scene/resources/sky_material.h"
-#include "scene/resources/sphere_shape_3d.h"
 #include "scene/resources/style_box.h"
 #include "scene/resources/style_box_flat.h"
 #include "scene/resources/style_box_line.h"
@@ -222,7 +212,6 @@
 #include "scene/resources/world_2d.h"
 #include "scene/resources/world_3d.h"
 #include "scene/resources/world_boundary_shape_2d.h"
-#include "scene/resources/world_boundary_shape_3d.h"
 #include "scene/scene_string_names.h"
 #include "scene/theme/theme_db.h"
 
@@ -273,10 +262,20 @@
 #include "scene/3d/world_environment.h"
 #include "scene/3d/xr_nodes.h"
 #include "scene/animation/root_motion_view.h"
-#include "scene/resources/environment.h"
+#include "scene/resources/box_shape_3d.h"
+#include "scene/resources/capsule_shape_3d.h"
+#include "scene/resources/concave_polygon_shape_3d.h"
+#include "scene/resources/convex_polygon_shape_3d.h"
+#include "scene/resources/cylinder_shape_3d.h"
 #include "scene/resources/fog_material.h"
+#include "scene/resources/height_map_shape_3d.h"
 #include "scene/resources/importer_mesh.h"
 #include "scene/resources/mesh_library.h"
+#include "scene/resources/primitive_meshes.h"
+#include "scene/resources/separation_ray_shape_3d.h"
+#include "scene/resources/sky_material.h"
+#include "scene/resources/sphere_shape_3d.h"
+#include "scene/resources/world_boundary_shape_3d.h"
 #endif // _3D_DISABLED
 
 static Ref<ResourceFormatSaverText> resource_saver_text;

+ 2 - 0
scene/resources/mesh.cpp

@@ -2276,8 +2276,10 @@ void ArrayMesh::_bind_methods() {
 	ClassDB::bind_method(D_METHOD("surface_find_by_name", "name"), &ArrayMesh::surface_find_by_name);
 	ClassDB::bind_method(D_METHOD("surface_set_name", "surf_idx", "name"), &ArrayMesh::surface_set_name);
 	ClassDB::bind_method(D_METHOD("surface_get_name", "surf_idx"), &ArrayMesh::surface_get_name);
+#ifndef _3D_DISABLED
 	ClassDB::bind_method(D_METHOD("create_trimesh_shape"), &ArrayMesh::create_trimesh_shape);
 	ClassDB::bind_method(D_METHOD("create_convex_shape", "clean", "simplify"), &ArrayMesh::create_convex_shape, DEFVAL(true), DEFVAL(false));
+#endif // _3D_DISABLED
 	ClassDB::bind_method(D_METHOD("create_outline", "margin"), &ArrayMesh::create_outline);
 	ClassDB::bind_method(D_METHOD("regen_normal_maps"), &ArrayMesh::regen_normal_maps);
 	ClassDB::set_method_flags(get_class_static(), _scs_create("regen_normal_maps"), METHOD_FLAGS_DEFAULT | METHOD_FLAG_EDITOR);

+ 3 - 0
tests/core/config/test_project_settings.h

@@ -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"));

+ 7 - 0
tests/core/io/test_image.h

@@ -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.");
 }
 

+ 24 - 0
tests/core/os/test_os.h

@@ -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") {

+ 1 - 1
tests/core/string/test_translation.h

@@ -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);
 

+ 15 - 5
tests/test_main.cpp

@@ -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();