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

[Tests] Ensure all default method arguments can be encoded #93134

Merged
merged 1 commit into from
Aug 26, 2024
Merged
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
40 changes: 40 additions & 0 deletions tests/core/object/test_class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,38 @@ bool arg_default_value_is_assignable_to_type(const Context &p_context, const Var
return false;
}

bool arg_default_value_is_valid_data(const Variant &p_val, String *r_err_msg = nullptr) {
switch (p_val.get_type()) {
case Variant::RID:
case Variant::ARRAY:
case Variant::DICTIONARY:
case Variant::PACKED_BYTE_ARRAY:
case Variant::PACKED_INT32_ARRAY:
case Variant::PACKED_INT64_ARRAY:
case Variant::PACKED_FLOAT32_ARRAY:
case Variant::PACKED_FLOAT64_ARRAY:
case Variant::PACKED_STRING_ARRAY:
case Variant::PACKED_VECTOR2_ARRAY:
case Variant::PACKED_VECTOR3_ARRAY:
case Variant::PACKED_COLOR_ARRAY:
case Variant::PACKED_VECTOR4_ARRAY:
case Variant::CALLABLE:
case Variant::SIGNAL:
case Variant::OBJECT:
if (p_val.is_zero()) {
return true;
}
if (r_err_msg) {
*r_err_msg = "Must be zero.";
}
break;
AThousandShips marked this conversation as resolved.
Show resolved Hide resolved
default:
return true;
}

return false;
}

void validate_property(const Context &p_context, const ExposedClass &p_class, const PropertyData &p_prop) {
const MethodData *setter = p_class.find_method_by_name(p_prop.setter);

Expand Down Expand Up @@ -411,6 +443,14 @@ void validate_argument(const Context &p_context, const ExposedClass &p_class, co
}

TEST_COND(!arg_defval_assignable_to_type, err_msg);

bool arg_defval_valid_data = arg_default_value_is_valid_data(p_arg.defval, &type_error_msg);

if (!type_error_msg.is_empty()) {
err_msg += " " + type_error_msg;
}

TEST_COND(!arg_defval_valid_data, err_msg);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not relevant for this PR, but at some point we need to discuss whether we want to keep these macro aliases or not. I think they are exclusively used for the ClassDB tests - everywhere else the doctest ones are used directly.

}
}

Expand Down
Loading