[Tests] Fix unit tests in template builds

This commit is contained in:
A Thousand Ships 2024-06-29 17:31:56 +02:00
parent 25de53e147
commit 17929a3443
No known key found for this signature in database
GPG key ID: 2033189A662F8BD7
6 changed files with 14 additions and 2 deletions

View file

@ -353,7 +353,6 @@ TEST_CASE("[Vector2] Plane methods") {
const Vector2 vector = Vector2(1.2, 3.4); const Vector2 vector = Vector2(1.2, 3.4);
const Vector2 vector_y = Vector2(0, 1); const Vector2 vector_y = Vector2(0, 1);
const Vector2 vector_normal = Vector2(0.95879811270838721622267, 0.2840883296913739899919); const Vector2 vector_normal = Vector2(0.95879811270838721622267, 0.2840883296913739899919);
const Vector2 vector_non_normal = Vector2(5.4, 1.6);
const real_t p_d = 99.1; const real_t p_d = 99.1;
CHECK_MESSAGE( CHECK_MESSAGE(
vector.bounce(vector_y) == Vector2(1.2, -3.4), vector.bounce(vector_y) == Vector2(1.2, -3.4),
@ -383,6 +382,8 @@ TEST_CASE("[Vector2] Plane methods") {
vector.slide(vector_normal).is_equal_approx(Vector2(-0.8292559899117276166456, 2.798738965952080706179)), vector.slide(vector_normal).is_equal_approx(Vector2(-0.8292559899117276166456, 2.798738965952080706179)),
"Vector2 slide with normal should return expected value."); "Vector2 slide with normal should return expected value.");
// There's probably a better way to test these ones? // There's probably a better way to test these ones?
#ifdef MATH_CHECKS
const Vector2 vector_non_normal = Vector2(5.4, 1.6);
ERR_PRINT_OFF; ERR_PRINT_OFF;
CHECK_MESSAGE( CHECK_MESSAGE(
vector.bounce(vector_non_normal).is_equal_approx(Vector2()), vector.bounce(vector_non_normal).is_equal_approx(Vector2()),
@ -394,6 +395,7 @@ TEST_CASE("[Vector2] Plane methods") {
vector.slide(vector_non_normal).is_equal_approx(Vector2()), vector.slide(vector_non_normal).is_equal_approx(Vector2()),
"Vector2 slide should return empty Vector2 with non-normalized input."); "Vector2 slide should return empty Vector2 with non-normalized input.");
ERR_PRINT_ON; ERR_PRINT_ON;
#endif // MATH_CHECKS
} }
TEST_CASE("[Vector2] Rounding methods") { TEST_CASE("[Vector2] Rounding methods") {

View file

@ -368,7 +368,6 @@ TEST_CASE("[Vector3] Plane methods") {
const Vector3 vector = Vector3(1.2, 3.4, 5.6); const Vector3 vector = Vector3(1.2, 3.4, 5.6);
const Vector3 vector_y = Vector3(0, 1, 0); const Vector3 vector_y = Vector3(0, 1, 0);
const Vector3 vector_normal = Vector3(0.88763458893247992491, 0.26300284116517923701, 0.37806658417494515320); const Vector3 vector_normal = Vector3(0.88763458893247992491, 0.26300284116517923701, 0.37806658417494515320);
const Vector3 vector_non_normal = Vector3(5.4, 1.6, 2.3);
CHECK_MESSAGE( CHECK_MESSAGE(
vector.bounce(vector_y) == Vector3(1.2, -3.4, 5.6), vector.bounce(vector_y) == Vector3(1.2, -3.4, 5.6),
"Vector3 bounce on a plane with normal of the Y axis should."); "Vector3 bounce on a plane with normal of the Y axis should.");
@ -394,6 +393,8 @@ TEST_CASE("[Vector3] Plane methods") {
vector.slide(vector_normal).is_equal_approx(Vector3(-2.41848149148878681437, 2.32785733585517427722237, 4.0587949202918130235)), vector.slide(vector_normal).is_equal_approx(Vector3(-2.41848149148878681437, 2.32785733585517427722237, 4.0587949202918130235)),
"Vector3 slide with normal should return expected value."); "Vector3 slide with normal should return expected value.");
// There's probably a better way to test these ones? // There's probably a better way to test these ones?
#ifdef MATH_CHECKS
const Vector3 vector_non_normal = Vector3(5.4, 1.6, 2.3);
ERR_PRINT_OFF; ERR_PRINT_OFF;
CHECK_MESSAGE( CHECK_MESSAGE(
vector.bounce(vector_non_normal).is_equal_approx(Vector3()), vector.bounce(vector_non_normal).is_equal_approx(Vector3()),
@ -405,6 +406,7 @@ TEST_CASE("[Vector3] Plane methods") {
vector.slide(vector_non_normal).is_equal_approx(Vector3()), vector.slide(vector_non_normal).is_equal_approx(Vector3()),
"Vector3 slide should return empty Vector3 with non-normalized input."); "Vector3 slide should return empty Vector3 with non-normalized input.");
ERR_PRINT_ON; ERR_PRINT_ON;
#endif // MATH_CHECKS
} }
TEST_CASE("[Vector3] Rounding methods") { TEST_CASE("[Vector3] Rounding methods") {

View file

@ -375,8 +375,10 @@ void validate_property(const Context &p_context, const ExposedClass &p_class, co
} }
void validate_argument(const Context &p_context, const ExposedClass &p_class, const String &p_owner_name, const String &p_owner_type, const ArgumentData &p_arg) { void validate_argument(const Context &p_context, const ExposedClass &p_class, const String &p_owner_name, const String &p_owner_type, const ArgumentData &p_arg) {
#ifdef DEBUG_METHODS_ENABLED
TEST_COND((p_arg.name.is_empty() || p_arg.name.begins_with("_unnamed_arg")), TEST_COND((p_arg.name.is_empty() || p_arg.name.begins_with("_unnamed_arg")),
vformat("Unnamed argument in position %d of %s '%s.%s'.", p_arg.position, p_owner_type, p_class.name, p_owner_name)); vformat("Unnamed argument in position %d of %s '%s.%s'.", p_arg.position, p_owner_type, p_class.name, p_owner_name));
#endif // DEBUG_METHODS_ENABLED
const ExposedClass *arg_class = p_context.find_exposed_class(p_arg.type); const ExposedClass *arg_class = p_context.find_exposed_class(p_arg.type);
if (arg_class) { if (arg_class) {

View file

@ -163,12 +163,14 @@ TEST_CASE("[OS] Processor count and memory information") {
CHECK_MESSAGE( CHECK_MESSAGE(
OS::get_singleton()->get_processor_count() >= 1, OS::get_singleton()->get_processor_count() >= 1,
"The returned processor count should be greater than zero."); "The returned processor count should be greater than zero.");
#ifdef DEBUG_ENABLED
CHECK_MESSAGE( CHECK_MESSAGE(
OS::get_singleton()->get_static_memory_usage() >= 1, OS::get_singleton()->get_static_memory_usage() >= 1,
"The returned static memory usage should be greater than zero."); "The returned static memory usage should be greater than zero.");
CHECK_MESSAGE( CHECK_MESSAGE(
OS::get_singleton()->get_static_memory_peak_usage() >= 1, OS::get_singleton()->get_static_memory_peak_usage() >= 1,
"The returned static memory peak usage should be greater than zero."); "The returned static memory peak usage should be greater than zero.");
#endif // DEBUG_ENABLED
} }
TEST_CASE("[OS] Execute") { TEST_CASE("[OS] Execute") {

View file

@ -333,6 +333,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instantiate from placeholder with ov
} }
} }
#ifdef TOOLS_ENABLED
TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an InstancePlaceholder with no overrides") { TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an InstancePlaceholder with no overrides") {
GDREGISTER_CLASS(_TestInstancePlaceholderNode); GDREGISTER_CLASS(_TestInstancePlaceholderNode);
@ -526,6 +527,7 @@ TEST_CASE("[SceneTree][InstancePlaceholder] Instance a PackedScene containing an
DirAccess::remove_file_or_error(internal_path); DirAccess::remove_file_or_error(internal_path);
DirAccess::remove_file_or_error(main_path); DirAccess::remove_file_or_error(main_path);
} }
#endif // TOOLS_ENABLED
} //namespace TestInstancePlaceholder } //namespace TestInstancePlaceholder

View file

@ -529,6 +529,7 @@ TEST_CASE("[SceneTree][Node]Exported node checks") {
memdelete(dup); memdelete(dup);
} }
#ifdef TOOLS_ENABLED
SUBCASE("Saving instance with exported nodes should not store the unchanged property") { SUBCASE("Saving instance with exported nodes should not store the unchanged property") {
Ref<PackedScene> ps; Ref<PackedScene> ps;
ps.instantiate(); ps.instantiate();
@ -602,6 +603,7 @@ TEST_CASE("[SceneTree][Node]Exported node checks") {
} }
CHECK_EQ(stored_properties, 2); CHECK_EQ(stored_properties, 2);
} }
#endif // TOOLS_ENABLED
memdelete(node); memdelete(node);
} }