-
-
Notifications
You must be signed in to change notification settings - Fork 22k
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
Unit tests for Object creation and property getter/setter #45411
Conversation
Debugging on Windows gives me crash with the following backtrace:
You'll also want to run the binary with |
tests/test_object.h
Outdated
_MockScriptInstance script_instance; | ||
object.set_script_instance(&script_instance); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to resolve the crash above (in this particular test case):
_MockScriptInstance script_instance; | |
object.set_script_instance(&script_instance); | |
_MockScriptInstance *script_instance = memnew(_MockScriptInstance); | |
object.set_script_instance(script_instance); |
Script instance will be freed automatically by the object
's destructor, which actually caused the crash.
Generally, you'll also likely want to instantiate Object
with memnew
as well for consistency with the rest of the codebase (just like Node
s), but don't forget to memdelete
those objects if you do.
The same applies to other test cases.
tests/test_object.h
Outdated
CHECK(valid); | ||
Variant actual_value; | ||
CHECK_MESSAGE( | ||
script_instance.get("some_name", actual_value), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Once the above is done:
script_instance.get("some_name", actual_value), | |
script_instance->get("some_name", actual_value), |
Thanks @Xrayez! I will definitely fix these, a little busy ATM. |
Interesting, I am running the test on Windows 10 (project compiled with MSVC) and it finishes successfully. |
12f8e75
to
db0f3da
Compare
} | ||
|
||
TEST_CASE("[Object] Built-in property setter") { | ||
ClassDB::register_class<_TestDerivedObject>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to note that ClassDB
is used globally throughout tests, but as long as it doesn't affect other tests, this should be fine I think.
It depends on how you run tests, a Godot project may certainly display a backtrace upon crash (given debug symbols are enabled). If I run tests without debugger, then I see no apparent crash either. If you look at Linux Builds / Editor with sanitizers checks, then you'd see various memory leaks and access violations which a debugger might not catch as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be good to merge!
Thanks! |
More
Object
tests as was noted in #43440.