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-579: Minimize warnings of testsuite resource loading #587

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions addons/gdUnit4/test/GdUnitTestResourceLoader.gd
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ static func load_cs_script(resource_path :String, debug_write := false) -> Scrip


static func load_gd_script(resource_path :String, debug_write := false) -> GDScript:
# grap current level
var unsafe_method_access: Variant = ProjectSettings.get_setting("debug/gdscript/warnings/unsafe_method_access")
# disable and load the script
ProjectSettings.set_setting("debug/gdscript/warnings/unsafe_method_access", 0)

var script := GDScript.new()
script.source_code = GdUnitFileAccess.resource_as_string(resource_path)
var script_resource_path := resource_path.replace(resource_path.get_extension(), "gd")
Expand All @@ -78,4 +83,6 @@ static func load_gd_script(resource_path :String, debug_write := false) -> GDScr
var error := script.reload()
if error != OK:
push_error("Errors on loading script %s. Error: %s" % [resource_path, error_string(error)])
ProjectSettings.set_setting("debug/gdscript/warnings/unsafe_method_access", unsafe_method_access)
return script
#@warning_ignore("unsafe_cast")
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
extends GdUnitTestSuite

func before() -> void:
@warning_ignore("unsafe_cast")
add_child(auto_free(Node.new()) as Node)

func test_case1() -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func after() -> void:
.is_equal(1)

for test_case :String in _metrics.keys():
var statistics := _metrics[test_case] as TestCaseStatistics
var statistics: TestCaseStatistics = _metrics[test_case]
assert_int(statistics._testcase_before_called)\
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._testcase_before_called, test_case])\
.is_equal(statistics._expected_calls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func after() -> void:
.is_equal(1)

for test_case :String in _metrics.keys():
var statistics := _metrics[test_case] as TestCaseStatistics
var statistics: TestCaseStatistics = _metrics[test_case]
assert_int(statistics._testcase_before_called)\
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._testcase_before_called, test_case])\
.is_equal(statistics._expected_calls)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func after() -> void:
.is_equal(1)

for test_case :String in _metrics.keys():
var statistics := _metrics[test_case] as TestCaseStatistics
var statistics: TestCaseStatistics = _metrics[test_case]
assert_int(statistics._testcase_before_called)\
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [statistics._expected_testcase_before, statistics._testcase_before_called, test_case])\
.is_equal(statistics._expected_testcase_before)
Expand Down