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

GD-421: Add uid:// path support to Scene Runner #422

Merged
merged 4 commits into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ func _init(p_scene, p_verbose :bool, p_hide_push_errors = false):
set_time_factor(1)
# handle scene loading by resource path
if typeof(p_scene) == TYPE_STRING:
if !FileAccess.file_exists(p_scene):
if !ResourceLoader.exists(p_scene):
MikeSchulze marked this conversation as resolved.
Show resolved Hide resolved
if not p_hide_push_errors:
push_error("GdUnitSceneRunner: Can't load scene by given resource path: '%s'. The resource not exists." % p_scene)
push_error("GdUnitSceneRunner: Can't load scene by given resource path: '%s'. The resource does not exists." % p_scene)
return
if !str(p_scene).ends_with("tscn"):
if !str(p_scene).ends_with(".tscn") and !str(p_scene).ends_with(".scn") and !str(p_scene).begins_with("uid://"):
MikeSchulze marked this conversation as resolved.
Show resolved Hide resolved
if not p_hide_push_errors:
push_error("GdUnitSceneRunner: The given resource: '%s'. is not a scene." % p_scene)
return
Expand Down
15 changes: 15 additions & 0 deletions addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,21 @@ func test_runner_by_invalid_resource_path() -> void:
assert_object(scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.gd")._current_scene).is_null()


func test_runner_by_uid_path() -> void:
# uid is for res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn
var runner = scene_runner("uid://cn8ucy2rheu0f")
assert_object(runner.scene()).is_instanceof(Node2D)

# verify the scene is freed when the runner is freed
var scene = runner.scene()
assert_bool(is_instance_valid(scene)).is_true()
runner._notification(NOTIFICATION_PREDELETE)
# give engine time to free the resources
await await_idle_frame()
# verify runner and scene is freed
assert_bool(is_instance_valid(scene)).is_false()


func test_runner_by_resource_path() -> void:
var runner = scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn")
assert_object(runner.scene()).is_instanceof(Node2D)
Expand Down