-
Notifications
You must be signed in to change notification settings - Fork 105
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
Trying get filename for dynamic scripts #655
Comments
I think the problem is that you are not setting the resource path for the script you created. The path does not have to exist and should not be the same as an existing script. I can't remember if there was a problem if you created multiple dynamic scripts that had no
Using func test_get_obj_filename_from_dynamic_script() -> void:
var utils = load("res://addons/gut/strutils.gd").new()
# this method will dedent the script so you don't have to make your dynamic source
# left justified...which is the best.
var instance = GutUtils.create_script_from_source("""
extends RefCounted
func do_something() -> int:
return 42
""").new()
var filename = utils._get_obj_filename(instance)
assert_ne(filename, "")
I messed with this a little bit. I got stuck trying to get the new dynamic script to pass an This might not be important tough, since we are trying to test how the original thing used something else, and so we wouldn't be passing the new dynamic version to anything. Good luck and let me know if you have any other questions! |
@bitwes thanks for answer. I agree. Using But there's an issue of testability of external code here, when someone creates dynamic scripts in their project (or framework) and decides to write tests with So here I'm not quite sure how important this task is. |
I get it now. I saw you calling "private" methods on utils and was thinking you were just trying to get something working, not testing dynamic code. I agree, GUT should be able to handle a missing resource_path. FYI, don't try to |
My bad. I reduced all code to problematic place. In reality, it was something like this: var builder = Builder.new()
var instance = builder.build() # return instance from dynamic script
assert_not_null(instance)
Thank you for that. I'll keep that in mind. |
Versions
The Bug
I'm experimenting with dynamic scripts here, partly because of the suggestion about type hints in #649 . So I've encountered the following bug related to dynamically created scripts. When assert methods are used, they try to get the filename, assert crashes with an error:
The error concerns code in the
strutils.gd
file, 86 line:Gut/addons/gut/strutils.gd
Lines 85 to 87 in 26e0a80
Seems logical. Dynamic scripts don't have a file, so they can't have a file name.
Possible fixes
Instead of
inst_to_dict
, you can check the path of the script attached to the object and form the file name on this basis.But there's a problem here. Unfortunately, it doesn't work for inner classes. Such classes have empty resource path too.
Steps To Reproduce
utils._get_obj_filename
throw error.The text was updated successfully, but these errors were encountered: