diff --git a/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd b/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd index 7ec2d348..21793343 100644 --- a/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd +++ b/addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd @@ -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): 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://"): if not p_hide_push_errors: push_error("GdUnitSceneRunner: The given resource: '%s'. is not a scene." % p_scene) return diff --git a/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd b/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd index f80969d7..5b5a42f0 100644 --- a/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd +++ b/addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd @@ -268,6 +268,40 @@ 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_invalid_uid_path() -> void: + # not existing scene + assert_object(scene_runner("uid://invalid_uid")._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_binary_resource_path() -> void: + var runner = scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.scn") + 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) diff --git a/addons/gdUnit4/test/core/resources/scenes/simple_scene.scn b/addons/gdUnit4/test/core/resources/scenes/simple_scene.scn new file mode 100644 index 00000000..740b1c90 Binary files /dev/null and b/addons/gdUnit4/test/core/resources/scenes/simple_scene.scn differ