Skip to content

Commit

Permalink
GD-579: Minimize warnings of testsuite resource loading (#587)
Browse files Browse the repository at this point in the history
# Why
<!-- Enter a clean description why we need this changeset -->


# What
<!-- Describe exactly what you have changed and what the effects are -->
  • Loading branch information
MikeSchulze authored Oct 1, 2024
1 parent ee47055 commit 4f1aca2
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 3 deletions.
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

0 comments on commit 4f1aca2

Please sign in to comment.