Adding log.gd

This commit is contained in:
Dan Baker 2024-05-02 09:36:31 +01:00
parent eb32d6614e
commit 4522259397
547 changed files with 46844 additions and 0 deletions

View file

@ -0,0 +1,86 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdUnitAwaiterTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/GdUnitAwaiter.gd'
signal test_signal_a()
signal test_signal_b()
signal test_signal_c(value)
signal test_signal_d(value_a, value_b)
func after_test():
for node in get_children():
if node is Timer:
remove_child(node)
node.stop()
node.free()
func install_signal_emitter(signal_name :String, signal_args: Array = [], time_out : float = 0.020):
var timer := Timer.new()
add_child(timer)
timer.timeout.connect(Callable(self, "emit_test_signal").bind(signal_name, signal_args))
timer.one_shot = true
timer.start(time_out)
func emit_test_signal(signal_name :String, signal_args: Array):
match signal_args.size():
0: emit_signal(signal_name)
1: emit_signal(signal_name, signal_args[0])
2: emit_signal(signal_name, signal_args[0], signal_args[1])
3: emit_signal(signal_name, signal_args[0], signal_args[1], signal_args[2])
func test_await_signal_on() -> void:
install_signal_emitter("test_signal_a")
await await_signal_on(self, "test_signal_a", [], 100)
install_signal_emitter("test_signal_b")
await await_signal_on(self, "test_signal_b", [], 100)
install_signal_emitter("test_signal_c", [])
await await_signal_on(self, "test_signal_c", [], 100)
install_signal_emitter("test_signal_c", ["abc"])
await await_signal_on(self, "test_signal_c", ["abc"], 100)
install_signal_emitter("test_signal_c", ["abc", "eee"])
await await_signal_on(self, "test_signal_c", ["abc", "eee"], 100)
func test_await_signal_on_manysignals_emitted() -> void:
# emits many different signals
install_signal_emitter("test_signal_a")
install_signal_emitter("test_signal_a")
install_signal_emitter("test_signal_a")
install_signal_emitter("test_signal_c", ["xxx"])
# the signal we want to wait for
install_signal_emitter("test_signal_c", ["abc"], .200)
install_signal_emitter("test_signal_c", ["yyy"], .100)
# we only wait for 'test_signal_c("abc")' is emitted
await await_signal_on(self, "test_signal_c", ["abc"], 300)
func test_await_signal_on_never_emitted_timedout() -> void:
(
# we wait for 'test_signal_c("yyy")' which is never emitted
await assert_failure_await(func x(): await await_signal_on(self, "test_signal_c", ["yyy"], 200))
).has_line(73)\
.has_message("await_signal_on(test_signal_c, [\"yyy\"]) timed out after 200ms")
func test_await_signal_on_invalid_source_timedout() -> void:
(
# we wait for a signal on a already freed instance
await assert_failure_await(func x(): await await_signal_on(invalid_node(), "tree_entered", [], 300))
).has_line(81).has_message(GdAssertMessages.error_await_signal_on_invalid_instance(null, "tree_entered", []))
func invalid_node() -> Node:
return null

View file

@ -0,0 +1,13 @@
extends GdUnitTestSuite
func test_load_performance() -> void:
var time = LocalTime.now()
prints("Scan for test suites.")
var test_suites := GdUnitTestSuiteScanner.new().scan("res://addons/gdUnit4/test/")
assert_int(time.elapsed_since_ms())\
.override_failure_message("Expecting the loading time overall is less than 10s")\
.is_less(10*1000)
prints("Scanning of %d test suites took" % test_suites.size(), time.elapsed_since())
for ts in test_suites:
ts.free()

View file

@ -0,0 +1,29 @@
# This test verifys only the scanner functionallity
# to find all given tests by pattern 'func test_<testname>():'
extends GdUnitTestSuite
func test_example():
assert_that("This is a example message").has_length(25)
assert_that("This is a example message").starts_with("This is a ex")
func test_b():
pass
# test name starts with same name e.g. test_b vs test_b2
func test_b2():
pass
# test scanning success with invalid formatting
func test_b21 ( ) :
pass
# finally verify all tests are found
func after():
assert_array(get_children())\
.extract("get_name")\
.contains_exactly(["test_example", "test_b", "test_b2", "test_b21"])

View file

@ -0,0 +1,17 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdUnitScriptTypeTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitScriptType.gd'
func test_type_of() -> void:
assert_str(GdUnitScriptType.type_of(null)).is_equal(GdUnitScriptType.UNKNOWN)
assert_str(GdUnitScriptType.type_of(ClassDB.instantiate("GDScript"))).is_equal(GdUnitScriptType.GD)
#if GdUnit4CSharpApiLoader.is_mono_supported():
# assert_str(GdUnitScriptType.type_of(ClassDB.instantiate("CSharpScript"))).is_equal(GdUnitScriptType.CS)
#assert_str(GdUnitScriptType.type_of(ClassDB.instantiate("VisualScript"))).is_equal(GdUnitScriptType.VS)
#assert_str(GdUnitScriptType.type_of(ClassDB.instantiate("NativeScript"))).is_equal(GdUnitScriptType.NATIVE)

View file

@ -0,0 +1,125 @@
# this test suite simulates long running test cases
extends GdUnitTestSuite
const SECOND :int = 1000
const MINUTE :int = SECOND*60
var _before_arg
var _test_arg
func before():
# use some variables to test clone test suite works as expected
_before_arg = "---before---"
func before_test():
# set failing test to success if failed by timeout
discard_error_interupted_by_timeout()
_test_arg = "abc"
# without custom timeout should execute the complete test
func test_timeout_after_test_completes():
assert_str(_before_arg).is_equal("---before---")
var counter := 0
await await_millis(1000)
prints("A","1s")
counter += 1
await await_millis(1000)
prints("A","2s")
counter += 1
await await_millis(1000)
prints("A","3s")
counter += 1
await await_millis(1000)
prints("A","5s")
counter += 2
prints("A","end test test_timeout_after_test_completes")
assert_int(counter).is_equal(5)
# set test timeout to 2s
@warning_ignore("unused_parameter")
func test_timeout_2s(timeout=2000):
assert_str(_before_arg).is_equal("---before---")
prints("B", "0s")
await await_millis(1000)
prints("B", "1s")
await await_millis(1000)
prints("B", "2s")
await await_millis(1000)
# this line should not reach if timeout aborts the test case after 2s
fail("The test case must be interupted by a timeout after 2s")
prints("B", "3s")
prints("B", "end")
# set test timeout to 4s
@warning_ignore("unused_parameter")
func test_timeout_4s(timeout=4000):
assert_str(_before_arg).is_equal("---before---")
prints("C", "0s")
await await_millis(1000)
prints("C", "1s")
await await_millis(1000)
prints("C", "2s")
await await_millis(1000)
prints("C", "3s")
await await_millis(4000)
# this line should not reach if timeout aborts the test case after 4s
fail("The test case must be interupted by a timeout after 4s")
prints("C", "7s")
prints("C", "end")
@warning_ignore("unused_parameter")
func test_timeout_single_yield_wait(timeout=3000):
assert_str(_before_arg).is_equal("---before---")
prints("D", "0s")
await await_millis(6000)
prints("D", "6s")
# this line should not reach if timeout aborts the test case after 3s
fail("The test case must be interupted by a timeout after 3s")
prints("D", "end test test_timeout")
@warning_ignore("unused_parameter")
func test_timeout_long_running_test_abort(timeout=4000):
assert_str(_before_arg).is_equal("---before---")
prints("E", "0s")
var start_time := Time.get_ticks_msec()
var sec_start_time := Time.get_ticks_msec()
# simulate long running function
while true:
var elapsed_time := Time.get_ticks_msec() - start_time
var sec_time = Time.get_ticks_msec() - sec_start_time
if sec_time > 1000:
sec_start_time = Time.get_ticks_msec()
prints("E", LocalTime.elapsed(elapsed_time))
# give system time to check for timeout
await await_millis(200)
# exit while after 4500ms inclusive 500ms offset
if elapsed_time > 4500:
break
# this line should not reach if timeout aborts the test case after 4s
fail("The test case must be abort interupted by a timeout 4s")
prints("F", "end test test_timeout")
@warning_ignore("unused_parameter", "unused_variable")
func test_timeout_fuzzer(fuzzer := Fuzzers.rangei(-23, 22), timeout=2000):
discard_error_interupted_by_timeout()
var value = fuzzer.next_value()
# wait each iteration 200ms
await await_millis(200)
# we expects the test is interupped after 10 iterations because each test takes 200ms
# and the test should not longer run than 2000ms
assert_int(fuzzer.iteration_index())\
.override_failure_message("The test must be interupted after around 10 iterations")\
.is_less_equal(10)

View file

@ -0,0 +1,96 @@
# this test suite simulates long running test cases
extends GdUnitTestSuite
var _iteration_timer_start = 0
var _test_values_current :Dictionary
var _test_values_expected :Dictionary
const SECOND:int = 1000
const MINUTE:int = SECOND*60
class TestCaseStatistics:
var _test_before_calls :int
var _test_after_calls :int
func _init(before_calls := 0, after_calls := 0):
_test_before_calls = before_calls
_test_after_calls = after_calls
func before():
_test_values_current = {
"test_2s" : TestCaseStatistics.new(),
"test_multi_yielding" : TestCaseStatistics.new(),
"test_multi_yielding_with_fuzzer" : TestCaseStatistics.new()
}
_test_values_expected = {
"test_2s" : TestCaseStatistics.new(1, 1),
"test_multi_yielding" : TestCaseStatistics.new(1, 1),
"test_multi_yielding_with_fuzzer" : TestCaseStatistics.new(5 , 5)
}
func after():
for test_case in _test_values_expected.keys():
var current := _test_values_current[test_case] as TestCaseStatistics
var expected := _test_values_expected[test_case] as TestCaseStatistics
assert_int(current._test_before_calls)\
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [expected._test_before_calls, current._test_before_calls, test_case])\
.is_equal(expected._test_before_calls)
assert_int(current._test_after_calls)\
.override_failure_message("Expect after_test called %s times but is %s for test case %s" % [expected._test_before_calls, current._test_before_calls, test_case])\
.is_equal(expected._test_after_calls)
func before_test():
var current = _test_values_current[__active_test_case] as TestCaseStatistics
current._test_before_calls +=1
func after_test():
var current = _test_values_current[__active_test_case] as TestCaseStatistics
current._test_after_calls +=1
func test_2s():
var timer_start := Time.get_ticks_msec()
await await_millis(2000)
# subtract an offset of 100ms because the time is not accurate
assert_int(Time.get_ticks_msec()-timer_start).is_between(2*SECOND-100, 2*SECOND+100)
func test_multi_yielding():
var timer_start := Time.get_ticks_msec()
prints("test_yielding")
await get_tree().process_frame
prints("4")
await get_tree().create_timer(1.0).timeout
prints("3")
await get_tree().create_timer(1.0).timeout
prints("2")
await get_tree().create_timer(1.0).timeout
prints("1")
await get_tree().create_timer(1.0).timeout
prints("Go")
assert_int(Time.get_ticks_msec()-timer_start).is_greater_equal(4*(SECOND-50))
func test_multi_yielding_with_fuzzer(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 5):
if fuzzer.iteration_index() > 5:
fail("Should only called 5 times")
if fuzzer.iteration_index() == 1:
_iteration_timer_start = Time.get_ticks_msec()
prints("test iteration %d" % fuzzer.iteration_index())
prints("4")
await get_tree().create_timer(1.0).timeout
prints("3")
await get_tree().create_timer(1.0).timeout
prints("2")
await get_tree().create_timer(1.0).timeout
prints("1")
await get_tree().create_timer(1.0).timeout
prints("Go")
if fuzzer.iteration_index() == 5:
# elapsed time must be fuzzer_iterations times * 4s = 40s (using 3,9s because of inaccurate timings)
assert_int(Time.get_ticks_msec()-_iteration_timer_start).is_greater_equal(3900*fuzzer_iterations)

View file

@ -0,0 +1,77 @@
class_name GdUnitTestResourceLoader
extends RefCounted
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
enum {
GD_SUITE,
CS_SUITE
}
static func load_test_suite(resource_path :String, script_type = GD_SUITE) -> Node:
match script_type:
GD_SUITE:
return load_test_suite_gd(resource_path)
CS_SUITE:
return load_test_suite_cs(resource_path)
assert("type '%s' is not implemented" % script_type)
return null
static func load_test_suite_gd(resource_path :String) -> GdUnitTestSuite:
var script := load_gd_script(resource_path)
var test_suite :GdUnitTestSuite = script.new()
test_suite.set_name(resource_path.get_file().replace(".resource", "").replace(".gd", ""))
# complete test suite wiht parsed test cases
var suite_scanner := GdUnitTestSuiteScanner.new()
var test_case_names := suite_scanner._extract_test_case_names(script)
# add test cases to test suite and parse test case line nummber
suite_scanner._parse_and_add_test_cases(test_suite, script, test_case_names)
return test_suite
static func load_test_suite_cs(resource_path :String) -> Node:
if not GdUnit4CSharpApiLoader.is_mono_supported():
return null
var script = ClassDB.instantiate("CSharpScript")
script.source_code = GdUnitFileAccess.resource_as_string(resource_path)
script.resource_path = resource_path
script.reload()
return null
static func load_cs_script(resource_path :String, debug_write := false) -> Script:
if not GdUnit4CSharpApiLoader.is_mono_supported():
return null
var script = ClassDB.instantiate("CSharpScript")
script.source_code = GdUnitFileAccess.resource_as_string(resource_path)
script.resource_path = GdUnitFileAccess.create_temp_dir("test") + "/%s" % resource_path.get_file().replace(".resource", ".cs")
if debug_write:
print_debug("save resource:", script.resource_path)
DirAccess.remove_absolute(script.resource_path)
var err := ResourceSaver.save(script, script.resource_path)
if err != OK:
print_debug("Can't save debug resource", script.resource_path, "Error:", error_string(err))
script.take_over_path(script.resource_path)
else:
script.take_over_path(resource_path)
script.reload()
return script
static func load_gd_script(resource_path :String, debug_write := false) -> GDScript:
var script := GDScript.new()
script.source_code = GdUnitFileAccess.resource_as_string(resource_path)
script.resource_path = GdUnitFileAccess.create_temp_dir("test") + "/%s" % resource_path.get_file().replace(".resource", ".gd")
if debug_write:
print_debug("save resource:", script.resource_path)
DirAccess.remove_absolute(script.resource_path)
var err := ResourceSaver.save(script, script.resource_path)
if err != OK:
print_debug("Can't save debug resource", script.resource_path, "Error:", error_string(err))
script.take_over_path(script.resource_path)
else:
script.take_over_path(resource_path)
script.reload()
return script

View file

@ -0,0 +1,16 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdUnitTestResourceLoaderTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/test/GdUnitTestResourceLoader.gd'
func test_load_test_suite_gd() -> void:
var resource_path = "res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource"
var test_suite := GdUnitTestResourceLoader.load_test_suite_gd(resource_path)
assert_that(test_suite).is_not_null()
assert_object(test_suite).is_instanceof(GdUnitTestSuite)
test_suite.free()

View file

@ -0,0 +1,13 @@
extends GdUnitTestSuite
func test_testsuite_loading_performance():
var time := LocalTime.now()
var reload_counter := 100
for i in range(1, reload_counter):
ResourceLoader.load("res://addons/gdUnit4/src/GdUnitTestSuite.gd", "GDScript", ResourceLoader.CACHE_MODE_IGNORE)
var error_message := "Expecting the loading time of test-suite is less than 50ms\n But was %s" % (time.elapsed_since_ms() / reload_counter)
assert_int(time.elapsed_since_ms()/ reload_counter)\
.override_failure_message(error_message)\
.is_less(50)
prints("loading takes %d ms" % (time.elapsed_since_ms() / reload_counter))

View file

@ -0,0 +1,48 @@
# GdUnit generated TestSuite
class_name GdUnitTestSuiteTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/GdUnitTestSuite.gd'
const GdUnitAssertImpl = preload("res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd")
var _events :Array[GdUnitEvent] = []
func collect_report(event :GdUnitEvent):
_events.push_back(event)
func before():
# register to receive test reports
GdUnitSignals.instance().gdunit_event.connect(collect_report)
func after():
# verify the test case `test_unknown_argument_in_test_case` was skipped
assert_array(_events).extractv(extr("type"), extr("is_skipped"), extr("test_name"))\
.contains([tuple(GdUnitEvent.TESTCASE_AFTER, true, "test_unknown_argument_in_test_case")])
GdUnitSignals.instance().gdunit_event.disconnect(collect_report)
func test_assert_that_types() -> void:
assert_object(assert_that(true)).is_instanceof(GdUnitBoolAssert)
assert_object(assert_that(1)).is_instanceof(GdUnitIntAssert)
assert_object(assert_that(3.12)).is_instanceof(GdUnitFloatAssert)
assert_object(assert_that("abc")).is_instanceof(GdUnitStringAssert)
assert_object(assert_that(Vector2.ONE)).is_instanceof(GdUnitVectorAssert)
assert_object(assert_that(Vector2i.ONE)).is_instanceof(GdUnitVectorAssert)
assert_object(assert_that(Vector3.ONE)).is_instanceof(GdUnitVectorAssert)
assert_object(assert_that(Vector3i.ONE)).is_instanceof(GdUnitVectorAssert)
assert_object(assert_that(Vector4.ONE)).is_instanceof(GdUnitVectorAssert)
assert_object(assert_that(Vector4i.ONE)).is_instanceof(GdUnitVectorAssert)
assert_object(assert_that([])).is_instanceof(GdUnitArrayAssert)
assert_object(assert_that({})).is_instanceof(GdUnitDictionaryAssert)
assert_object(assert_that(GdUnitResult.new())).is_instanceof(GdUnitObjectAssert)
# all not a built-in types mapped to default GdUnitAssert
assert_object(assert_that(Color.RED)).is_instanceof(GdUnitAssertImpl)
assert_object(assert_that(Plane.PLANE_XY)).is_instanceof(GdUnitAssertImpl)
func test_unknown_argument_in_test_case(_invalid_arg) -> void:
fail("This test case should be not executed, it must be skipped.")

View file

@ -0,0 +1,23 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name CallBackValueProviderTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/CallBackValueProvider.gd'
func next_value() -> String:
return "a value"
func test_get_value() -> void:
var vp := CallBackValueProvider.new(self, "next_value")
assert_str(await vp.get_value()).is_equal("a value")
func test_construct_invalid() -> void:
var vp := CallBackValueProvider.new(self, "invalid_func", Array(), false)
# will return null because of invalid function name
assert_str(await vp.get_value()).is_null()

View file

@ -0,0 +1,777 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd'
var _saved_report_assert_warnings
func before():
_saved_report_assert_warnings = ProjectSettings.get_setting(GdUnitSettings.REPORT_ASSERT_WARNINGS)
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_WARNINGS, false)
func after():
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_WARNINGS, _saved_report_assert_warnings)
func test_is_null() -> void:
assert_array(null).is_null()
assert_failure(func(): assert_array([]).is_null()) \
.is_failed() \
.has_message("Expecting: '<null>' but was '<empty>'")
func test_is_not_null() -> void:
assert_array([]).is_not_null()
assert_failure(func(): assert_array(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_equal():
assert_array([1, 2, 3, 4, 2, 5]).is_equal([1, 2, 3, 4, 2, 5])
# should fail because the array not contains same elements and has diff size
assert_failure(func(): assert_array([1, 2, 4, 5]).is_equal([1, 2, 3, 4, 2, 5])) \
.is_failed()
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).is_equal([1, 2, 3, 4])) \
.is_failed()
# current array is bigger than expected
assert_failure(func(): assert_array([1, 2222, 3, 4, 5, 6]).is_equal([1, 2, 3, 4])) \
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3, 4]'
but was
'[1, 2222, 3, 4, 5, 6]'
Differences found:
Index Current Expected 1 2222 2 4 5 <N/A> 5 6 <N/A> """
.dedent().trim_prefix("\n"))
# expected array is bigger than current
assert_failure(func(): assert_array([1, 222, 3, 4]).is_equal([1, 2, 3, 4, 5, 6])) \
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3, 4, 5, 6]'
but was
'[1, 222, 3, 4]'
Differences found:
Index Current Expected 1 222 2 4 <N/A> 5 5 <N/A> 6 """
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array(null).is_equal([1, 2, 3])) \
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3]'
but was
'<null>'"""
.dedent().trim_prefix("\n"))
func test_is_equal_big_arrays():
var expeted := Array()
expeted.resize(1000)
for i in 1000:
expeted[i] = i
var current := expeted.duplicate()
current[10] = "invalid"
current[40] = "invalid"
current[100] = "invalid"
current[888] = "invalid"
assert_failure(func(): assert_array(current).is_equal(expeted)) \
.is_failed() \
.has_message("""
Expecting:
'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ...]'
but was
'[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, invalid, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, ...]'
Differences found:
Index Current Expected 10 invalid 10 40 invalid 40 100 invalid 100 888 invalid 888 """
.dedent().trim_prefix("\n"))
func test_is_equal_ignoring_case():
assert_array(["this", "is", "a", "message"]).is_equal_ignoring_case(["This", "is", "a", "Message"])
# should fail because the array not contains same elements
assert_failure(func(): assert_array(["this", "is", "a", "message"]).is_equal_ignoring_case(["This", "is", "an", "Message"])) \
.is_failed()
assert_failure(func(): assert_array(null).is_equal_ignoring_case(["This", "is"])) \
.is_failed() \
.has_message("""
Expecting:
'["This", "is"]'
but was
'<null>'"""
.dedent().trim_prefix("\n"))
func test_is_not_equal():
assert_array(null).is_not_equal([1, 2, 3])
assert_array([1, 2, 3, 4, 5]).is_not_equal([1, 2, 3, 4, 5, 6])
# should fail because the array contains same elements
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).is_not_equal([1, 2, 3, 4, 5])) \
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3, 4, 5]'
not equal to
'[1, 2, 3, 4, 5]'"""
.dedent().trim_prefix("\n"))
func test_is_not_equal_ignoring_case():
assert_array(null).is_not_equal_ignoring_case(["This", "is", "an", "Message"])
assert_array(["this", "is", "a", "message"]).is_not_equal_ignoring_case(["This", "is", "an", "Message"])
# should fail because the array contains same elements ignoring case sensitive
assert_failure(func(): assert_array(["this", "is", "a", "message"]).is_not_equal_ignoring_case(["This", "is", "a", "Message"])) \
.is_failed() \
.has_message("""
Expecting:
'["This", "is", "a", "Message"]'
not equal to (case insensitiv)
'["this", "is", "a", "message"]'"""
.dedent().trim_prefix("\n"))
func test_is_empty():
assert_array([]).is_empty()
assert_failure(func(): assert_array([1, 2, 3]).is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'[1, 2, 3]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array(null).is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'<null>'"""
.dedent().trim_prefix("\n"))
func test_is_not_empty():
assert_array(null).is_not_empty()
assert_array([1]).is_not_empty()
assert_failure(func(): assert_array([]).is_not_empty()) \
.is_failed() \
.has_message("Expecting:\n must not be empty")
func test_is_same() -> void:
var value := [0]
assert_array(value).is_same(value)
assert_failure(func(): assert_array(value).is_same(value.duplicate()))\
.is_failed()\
.has_message("Expecting:\n '[0]'\n to refer to the same object\n '[0]'")
func test_is_not_same() -> void:
assert_array([0]).is_not_same([0])
var value := [0]
assert_failure(func(): assert_array(value).is_not_same(value))\
.is_failed()\
.has_message("Expecting not same:\n '[0]'")
func test_has_size():
assert_array([1, 2, 3, 4, 5]).has_size(5)
assert_array(["a", "b", "c", "d", "e", "f"]).has_size(6)
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).has_size(4)) \
.is_failed() \
.has_message("""
Expecting size:
'4'
but was
'5'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array(null).has_size(4)) \
.is_failed() \
.has_message("""
Expecting size:
'4'
but was
'<null>'"""
.dedent().trim_prefix("\n"))
func test_contains():
assert_array([1, 2, 3, 4, 5]).contains([])
assert_array([1, 2, 3, 4, 5]).contains([5, 2])
assert_array([1, 2, 3, 4, 5]).contains([5, 4, 3, 2, 1])
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).contains([TestObj.new("A", 0)])
# should fail because the array not contains 7 and 6
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).contains([2, 7, 6])) \
.is_failed() \
.has_message("""
Expecting contains elements:
'[1, 2, 3, 4, 5]'
do contains (in any order)
'[2, 7, 6]'
but could not find elements:
'[7, 6]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array(null).contains([2, 7, 6])) \
.is_failed() \
.has_message("""
Expecting contains elements:
'<null>'
do contains (in any order)
'[2, 7, 6]'
but could not find elements:
'[2, 7, 6]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array([valueA, valueB]).contains([TestObj.new("C", 0)])) \
.is_failed() \
.has_message("""
Expecting contains elements:
'[class:A, class:B]'
do contains (in any order)
'[class:C]'
but could not find elements:
'[class:C]'"""
.dedent().trim_prefix("\n"))
func test_contains_exactly():
assert_array([1, 2, 3, 4, 5]).contains_exactly([1, 2, 3, 4, 5])
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).contains_exactly([TestObj.new("A", 0), valueB])
# should fail because the array contains the same elements but in a different order
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).contains_exactly([1, 4, 3, 2, 5])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[1, 2, 3, 4, 5]'
do contains (in same order)
'[1, 4, 3, 2, 5]'
but has different order at position '1'
'2' vs '4'"""
.dedent().trim_prefix("\n"))
# should fail because the array contains more elements and in a different order
assert_failure(func(): assert_array([1, 2, 3, 4, 5, 6, 7]).contains_exactly([1, 4, 3, 2, 5])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[1, 2, 3, 4, 5, 6, 7]'
do contains (in same order)
'[1, 4, 3, 2, 5]'
but some elements where not expected:
'[6, 7]'"""
.dedent().trim_prefix("\n"))
# should fail because the array contains less elements and in a different order
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).contains_exactly([1, 4, 3, 2, 5, 6, 7])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[1, 2, 3, 4, 5]'
do contains (in same order)
'[1, 4, 3, 2, 5, 6, 7]'
but could not find elements:
'[6, 7]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array(null).contains_exactly([1, 4, 3])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'<null>'
do contains (in same order)
'[1, 4, 3]'
but could not find elements:
'[1, 4, 3]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array([valueA, valueB]).contains_exactly([valueB, TestObj.new("A", 0)])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[class:A, class:B]'
do contains (in same order)
'[class:B, class:A]'
but has different order at position '0'
'class:A' vs 'class:B'"""
.dedent().trim_prefix("\n"))
func test_contains_exactly_in_any_order():
assert_array([1, 2, 3, 4, 5]).contains_exactly_in_any_order([1, 2, 3, 4, 5])
assert_array([1, 2, 3, 4, 5]).contains_exactly_in_any_order([5, 3, 2, 4, 1])
assert_array([1, 2, 3, 4, 5]).contains_exactly_in_any_order([5, 1, 2, 4, 3])
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).contains_exactly_in_any_order([valueB, TestObj.new("A", 0)])
# should fail because the array contains not exactly the same elements in any order
assert_failure(func(): assert_array([1, 2, 6, 4, 5]).contains_exactly_in_any_order([5, 3, 2, 4, 1, 9, 10])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[1, 2, 6, 4, 5]'
do contains exactly (in any order)
'[5, 3, 2, 4, 1, 9, 10]'
but some elements where not expected:
'[6]'
and could not find elements:
'[3, 9, 10]'"""
.dedent().trim_prefix("\n"))
#should fail because the array contains the same elements but in a different order
assert_failure(func(): assert_array([1, 2, 6, 9, 10, 4, 5]).contains_exactly_in_any_order([5, 3, 2, 4, 1])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[1, 2, 6, 9, 10, 4, 5]'
do contains exactly (in any order)
'[5, 3, 2, 4, 1]'
but some elements where not expected:
'[6, 9, 10]'
and could not find elements:
'[3]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array(null).contains_exactly_in_any_order([1, 4, 3])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'<null>'
do contains exactly (in any order)
'[1, 4, 3]'
but could not find elements:
'[1, 4, 3]'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array([valueA, valueB]).contains_exactly_in_any_order([valueB, TestObj.new("C", 0)])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'[class:A, class:B]'
do contains exactly (in any order)
'[class:B, class:C]'
but some elements where not expected:
'[class:A]'
and could not find elements:
'[class:C]'"""
.dedent().trim_prefix("\n"))
func test_contains_same():
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).contains_same([valueA])
assert_failure(func(): assert_array([valueA, valueB]).contains_same([TestObj.new("A", 0)])) \
.is_failed() \
.has_message("""
Expecting contains SAME elements:
'[class:A, class:B]'
do contains (in any order)
'[class:A]'
but could not find elements:
'[class:A]'"""
.dedent().trim_prefix("\n"))
func test_contains_same_exactly():
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).contains_same_exactly([valueA, valueB])
assert_failure(func(): assert_array([valueA, valueB]).contains_same_exactly([valueB, valueA])) \
.is_failed() \
.has_message("""
Expecting contains SAME exactly elements:
'[class:A, class:B]'
do contains (in same order)
'[class:B, class:A]'
but has different order at position '0'
'class:A' vs 'class:B'"""
.dedent().trim_prefix("\n"))
assert_failure(func(): assert_array([valueA, valueB]).contains_same_exactly([TestObj.new("A", 0), valueB])) \
.is_failed() \
.has_message("""
Expecting contains SAME exactly elements:
'[class:A, class:B]'
do contains (in same order)
'[class:A, class:B]'
but some elements where not expected:
'[class:A]'
and could not find elements:
'[class:A]'"""
.dedent().trim_prefix("\n"))
func test_contains_same_exactly_in_any_order():
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).contains_same_exactly_in_any_order([valueB, valueA])
assert_failure(func(): assert_array([valueA, valueB]).contains_same_exactly_in_any_order([valueB, TestObj.new("A", 0)])) \
.is_failed() \
.has_message("""
Expecting contains SAME exactly elements:
'[class:A, class:B]'
do contains exactly (in any order)
'[class:B, class:A]'
but some elements where not expected:
'[class:A]'
and could not find elements:
'[class:A]'"""
.dedent().trim_prefix("\n"))
func test_not_contains():
assert_array([]).not_contains([0])
assert_array([1, 2, 3, 4, 5]).not_contains([0])
assert_array([1, 2, 3, 4, 5]).not_contains([0, 6])
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
assert_array([valueA, valueB]).not_contains([TestObj.new("C", 0)])
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).not_contains([5]))\
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3, 4, 5]'
do not contains
'[5]'
but found elements:
'[5]'"""
.dedent().trim_prefix("\n")
)
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).not_contains([1, 4, 6])) \
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3, 4, 5]'
do not contains
'[1, 4, 6]'
but found elements:
'[1, 4]'"""
.dedent().trim_prefix("\n")
)
assert_failure(func(): assert_array([1, 2, 3, 4, 5]).not_contains([6, 4, 1])) \
.is_failed() \
.has_message("""
Expecting:
'[1, 2, 3, 4, 5]'
do not contains
'[6, 4, 1]'
but found elements:
'[4, 1]'"""
.dedent().trim_prefix("\n")
)
assert_failure(func(): assert_array([valueA, valueB]).not_contains([TestObj.new("A", 0)])) \
.is_failed() \
.has_message("""
Expecting:
'[class:A, class:B]'
do not contains
'[class:A]'
but found elements:
'[class:A]'"""
.dedent().trim_prefix("\n")
)
func test_not_contains_same():
var valueA := TestObj.new("A", 0)
var valueB := TestObj.new("B", 0)
var valueC := TestObj.new("B", 0)
assert_array([valueA, valueB]).not_contains_same([valueC])
assert_failure(func(): assert_array([valueA, valueB]).not_contains_same([valueB])) \
.is_failed() \
.has_message("""
Expecting SAME:
'[class:A, class:B]'
do not contains
'[class:B]'
but found elements:
'[class:B]'"""
.dedent().trim_prefix("\n")
)
func test_fluent():
assert_array([])\
.has_size(0)\
.is_empty()\
.is_not_null()\
.contains([])\
.contains_exactly([])
func test_must_fail_has_invlalid_type():
assert_failure(func(): assert_array(1)) \
.is_failed() \
.has_message("GdUnitArrayAssert inital error, unexpected type <int>")
assert_failure(func(): assert_array(1.3)) \
.is_failed() \
.has_message("GdUnitArrayAssert inital error, unexpected type <float>")
assert_failure(func(): assert_array(true)) \
.is_failed() \
.has_message("GdUnitArrayAssert inital error, unexpected type <bool>")
assert_failure(func(): assert_array(Resource.new())) \
.is_failed() \
.has_message("GdUnitArrayAssert inital error, unexpected type <Object>")
func test_extract() -> void:
# try to extract checked base types
assert_array([1, false, 3.14, null, Color.ALICE_BLUE]).extract("get_class") \
.contains_exactly(["n.a.", "n.a.", "n.a.", null, "n.a."])
# extracting by a func without arguments
assert_array([RefCounted.new(), 2, AStar3D.new(), auto_free(Node.new())]).extract("get_class") \
.contains_exactly(["RefCounted", "n.a.", "AStar3D", "Node"])
# extracting by a func with arguments
assert_array([RefCounted.new(), 2, AStar3D.new(), auto_free(Node.new())]).extract("has_signal", ["tree_entered"]) \
.contains_exactly([false, "n.a.", false, true])
# try extract checked object via a func that not exists
assert_array([RefCounted.new(), 2, AStar3D.new(), auto_free(Node.new())]).extract("invalid_func") \
.contains_exactly(["n.a.", "n.a.", "n.a.", "n.a."])
# try extract checked object via a func that has no return value
assert_array([RefCounted.new(), 2, AStar3D.new(), auto_free(Node.new())]).extract("remove_meta", [""]) \
.contains_exactly([null, "n.a.", null, null])
assert_failure(func(): assert_array(null).extract("get_class").contains_exactly(["AStar3D", "Node"])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'<null>'
do contains (in same order)
'["AStar3D", "Node"]'
but could not find elements:
'["AStar3D", "Node"]'"""
.dedent().trim_prefix("\n"))
class TestObj:
var _name :String
var _value
var _x
func _init(name :String, value, x = null):
_name = name
_value = value
_x = x
func get_name() -> String:
return _name
func get_value():
return _value
func get_x():
return _x
func get_x1() -> String:
return "x1"
func get_x2() -> String:
return "x2"
func get_x3() -> String:
return "x3"
func get_x4() -> String:
return "x4"
func get_x5() -> String:
return "x5"
func get_x6() -> String:
return "x6"
func get_x7() -> String:
return "x7"
func get_x8() -> String:
return "x8"
func get_x9() -> String:
return "x9"
func _to_string() -> String:
return "class:" + _name
func test_extractv() -> void:
# single extract
assert_array([1, false, 3.14, null, Color.ALICE_BLUE])\
.extractv(extr("get_class"))\
.contains_exactly(["n.a.", "n.a.", "n.a.", null, "n.a."])
# tuple of two
assert_array([TestObj.new("A", 10), TestObj.new("B", "foo"), Color.ALICE_BLUE, TestObj.new("C", 11)])\
.extractv(extr("get_name"), extr("get_value"))\
.contains_exactly([tuple("A", 10), tuple("B", "foo"), tuple("n.a.", "n.a."), tuple("C", 11)])
# tuple of three
assert_array([TestObj.new("A", 10), TestObj.new("B", "foo", "bar"), TestObj.new("C", 11, 42)])\
.extractv(extr("get_name"), extr("get_value"), extr("get_x"))\
.contains_exactly([tuple("A", 10, null), tuple("B", "foo", "bar"), tuple("C", 11, 42)])
assert_failure(func():
assert_array(null) \
.extractv(extr("get_name"), extr("get_value"), extr("get_x")) \
.contains_exactly([tuple("A", 10, null), tuple("B", "foo", "bar"), tuple("C", 11, 42)])) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'<null>'
do contains (in same order)
'[tuple(["A", 10, <null>]), tuple(["B", "foo", "bar"]), tuple(["C", 11, 42])]'
but could not find elements:
'[tuple(["A", 10, <null>]), tuple(["B", "foo", "bar"]), tuple(["C", 11, 42])]'"""
.dedent().trim_prefix("\n"))
func test_extractv_chained_func() -> void:
var root_a = TestObj.new("root_a", null)
var obj_a = TestObj.new("A", root_a)
var obj_b = TestObj.new("B", root_a)
var obj_c = TestObj.new("C", root_a)
var root_b = TestObj.new("root_b", root_a)
var obj_x = TestObj.new("X", root_b)
var obj_y = TestObj.new("Y", root_b)
assert_array([obj_a, obj_b, obj_c, obj_x, obj_y])\
.extractv(extr("get_name"), extr("get_value.get_name"))\
.contains_exactly([
tuple("A", "root_a"),
tuple("B", "root_a"),
tuple("C", "root_a"),
tuple("X", "root_b"),
tuple("Y", "root_b")
])
func test_extract_chained_func() -> void:
var root_a = TestObj.new("root_a", null)
var obj_a = TestObj.new("A", root_a)
var obj_b = TestObj.new("B", root_a)
var obj_c = TestObj.new("C", root_a)
var root_b = TestObj.new("root_b", root_a)
var obj_x = TestObj.new("X", root_b)
var obj_y = TestObj.new("Y", root_b)
assert_array([obj_a, obj_b, obj_c, obj_x, obj_y])\
.extract("get_value.get_name")\
.contains_exactly([
"root_a",
"root_a",
"root_a",
"root_b",
"root_b",
])
func test_extractv_max_args() -> void:
assert_array([TestObj.new("A", 10), TestObj.new("B", "foo", "bar"), TestObj.new("C", 11, 42)])\
.extractv(\
extr("get_name"),
extr("get_x1"),
extr("get_x2"),
extr("get_x3"),
extr("get_x4"),
extr("get_x5"),
extr("get_x6"),
extr("get_x7"),
extr("get_x8"),
extr("get_x9"))\
.contains_exactly([
tuple("A", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9"),
tuple("B", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9"),
tuple("C", "x1", "x2", "x3", "x4", "x5", "x6", "x7", "x8", "x9")])
func test_override_failure_message() -> void:
assert_failure(func(): assert_array([]) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_array([]).is_empty()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_array([]).is_not_empty()) \
.is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_array([]).is_empty()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()
# should abort here because we had an failing assert
if is_failure():
return
assert_bool(true).override_failure_message("This line shold never be called").is_false()
class ExampleTestClass extends RefCounted:
var _childs := Array()
var _parent = null
func add_child(child :ExampleTestClass) -> ExampleTestClass:
_childs.append(child)
child._parent = self
return self
func dispose():
_parent = null
_childs.clear()
func test_contains_exactly_stuck() -> void:
var example_a := ExampleTestClass.new()\
.add_child(ExampleTestClass.new())\
.add_child(ExampleTestClass.new())
var example_b := ExampleTestClass.new()\
.add_child(ExampleTestClass.new())\
.add_child(ExampleTestClass.new())
# this test was stuck and ends after a while into an aborted test case
# https://github.com/MikeSchulze/gdUnit3/issues/244
assert_failure(func(): assert_array([example_a, example_b]).contains_exactly([example_a, example_b, example_a]))\
.is_failed()
# manual free because of cross references
example_a.dispose()
example_b.dispose()

View file

@ -0,0 +1,118 @@
# GdUnit generated TestSuite
class_name GdUnitAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitAssertImpl.gd'
func before():
assert_int(GdUnitAssertions.get_line_number()).is_equal(10)
assert_failure(func(): assert_int(10).is_equal(42)) \
.is_failed() \
.has_line(11) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func after():
assert_failure(func(): assert_int(10).is_equal(42)) \
.is_failed() \
.has_line(18) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func before_test():
assert_failure(func(): assert_int(10).is_equal(42)) \
.is_failed() \
.has_line(25) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func after_test():
assert_failure(func(): assert_int(10).is_equal(42)) \
.is_failed() \
.has_line(32) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func test_get_line_number():
# test to return the current line number for an failure
assert_failure(func(): assert_int(10).is_equal(42)) \
.is_failed() \
.has_line(40) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func test_get_line_number_yielded():
# test to return the current line number after using yield
await get_tree().create_timer(0.100).timeout
assert_failure(func(): assert_int(10).is_equal(42)) \
.is_failed() \
.has_line(49) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func test_get_line_number_multiline():
# test to return the current line number for an failure
# https://github.com/godotengine/godot/issues/43326
assert_failure(func(): assert_int(10)\
.is_not_negative()\
.is_equal(42)) \
.is_failed() \
.has_line(58) \
.has_message("Expecting:\n '42'\n but was\n '10'")
func test_get_line_number_verify():
var obj = mock(RefCounted)
assert_failure(func(): verify(obj, 1).get_reference_count()) \
.is_failed() \
.has_line(68) \
.has_message("Expecting interaction on:\n 'get_reference_count()' 1 time's\nBut found interactions on:\n")
func test_is_null():
assert_that(null).is_null()
assert_failure(func(): assert_that(Color.RED).is_null()) \
.is_failed() \
.has_line(77) \
.starts_with_message("Expecting: '<null>' but was 'Color(1, 0, 0, 1)'")
func test_is_not_null():
assert_that(Color.RED).is_not_null()
assert_failure(func(): assert_that(null).is_not_null()) \
.is_failed() \
.has_line(86) \
.has_message("Expecting: not to be '<null>'")
func test_is_equal():
assert_that(Color.RED).is_equal(Color.RED)
assert_that(Plane.PLANE_XY).is_equal(Plane.PLANE_XY)
assert_failure(func(): assert_that(Color.RED).is_equal(Color.GREEN)) \
.is_failed() \
.has_line(96) \
.has_message("Expecting:\n 'Color(0, 1, 0, 1)'\n but was\n 'Color(1, 0, 0, 1)'")
func test_is_not_equal():
assert_that(Color.RED).is_not_equal(Color.GREEN)
assert_that(Plane.PLANE_XY).is_not_equal(Plane.PLANE_XZ)
assert_failure(func(): assert_that(Color.RED).is_not_equal(Color.RED)) \
.is_failed() \
.has_line(106) \
.has_message("Expecting:\n 'Color(1, 0, 0, 1)'\n not equal to\n 'Color(1, 0, 0, 1)'")
func test_override_failure_message() -> void:
assert_failure(func(): assert_that(Color.RED) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_line(113) \
.has_message("Custom failure message")

View file

@ -0,0 +1,117 @@
# GdUnit generated TestSuite
class_name GdUnitBoolAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitBoolAssertImpl.gd'
func test_is_true():
assert_bool(true).is_true()
assert_failure(func(): assert_bool(false).is_true())\
.is_failed() \
.has_message("Expecting: 'true' but is 'false'")
assert_failure(func(): assert_bool(null).is_true()) \
.is_failed() \
.has_message("Expecting: 'true' but is '<null>'")
func test_isFalse():
assert_bool(false).is_false()
assert_failure(func(): assert_bool(true).is_false()) \
.is_failed() \
.has_message("Expecting: 'false' but is 'true'")
assert_failure(func(): assert_bool(null).is_false()) \
.is_failed() \
.has_message("Expecting: 'false' but is '<null>'")
func test_is_null():
assert_bool(null).is_null()
# should fail because the current is not null
assert_failure(func(): assert_bool(true).is_null())\
.is_failed() \
.starts_with_message("Expecting: '<null>' but was 'true'")
func test_is_not_null():
assert_bool(true).is_not_null()
# should fail because the current is null
assert_failure(func(): assert_bool(null).is_not_null())\
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_equal():
assert_bool(true).is_equal(true)
assert_bool(false).is_equal(false)
assert_failure(func(): assert_bool(true).is_equal(false)) \
.is_failed() \
.has_message("Expecting:\n 'false'\n but was\n 'true'")
assert_failure(func(): assert_bool(null).is_equal(false)) \
.is_failed() \
.has_message("Expecting:\n 'false'\n but was\n '<null>'")
func test_is_not_equal():
assert_bool(null).is_not_equal(false)
assert_bool(true).is_not_equal(false)
assert_bool(false).is_not_equal(true)
assert_failure(func(): assert_bool(true).is_not_equal(true)) \
.is_failed() \
.has_message("Expecting:\n 'true'\n not equal to\n 'true'")
func test_fluent():
assert_bool(true).is_true().is_equal(true).is_not_equal(false)
func test_must_fail_has_invlalid_type():
assert_failure(func(): assert_bool(1)) \
.is_failed() \
.has_message("GdUnitBoolAssert inital error, unexpected type <int>")
assert_failure(func(): assert_bool(3.13)) \
.is_failed() \
.has_message("GdUnitBoolAssert inital error, unexpected type <float>")
assert_failure(func(): assert_bool("foo")) \
.is_failed() \
.has_message("GdUnitBoolAssert inital error, unexpected type <String>")
assert_failure(func(): assert_bool(Resource.new())) \
.is_failed() \
.has_message("GdUnitBoolAssert inital error, unexpected type <Object>")
func test_override_failure_message() -> void:
assert_failure(func(): assert_bool(true) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_bool(true).is_true()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_bool(true).is_false()).is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_bool(true).is_true()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()
# should abort here because we had an failing assert
if is_failure():
return
assert_bool(true).override_failure_message("This line shold never be called").is_false()

View file

@ -0,0 +1,470 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitDictionaryAssertImpl.gd'
func test_must_fail_has_invlalid_type() -> void:
assert_failure(func(): assert_dict(1)) \
.is_failed() \
.has_message("GdUnitDictionaryAssert inital error, unexpected type <int>")
assert_failure(func(): assert_dict(1.3)) \
.is_failed() \
.has_message("GdUnitDictionaryAssert inital error, unexpected type <float>")
assert_failure(func(): assert_dict(true)) \
.is_failed() \
.has_message("GdUnitDictionaryAssert inital error, unexpected type <bool>")
assert_failure(func(): assert_dict("abc")) \
.is_failed() \
.has_message("GdUnitDictionaryAssert inital error, unexpected type <String>")
assert_failure(func(): assert_dict([])) \
.is_failed() \
.has_message("GdUnitDictionaryAssert inital error, unexpected type <Array>")
assert_failure(func(): assert_dict(Resource.new())) \
.is_failed() \
.has_message("GdUnitDictionaryAssert inital error, unexpected type <Object>")
func test_is_null() -> void:
assert_dict(null).is_null()
assert_failure(func(): assert_dict({}).is_null()) \
.is_failed() \
.has_message("Expecting: '<null>' but was '{ }'")
func test_is_not_null() -> void:
assert_dict({}).is_not_null()
assert_failure(func(): assert_dict(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_equal() -> void:
assert_dict({}).is_equal({})
assert_dict({1:1}).is_equal({1:1})
assert_dict({1:1, "key_a": "value_a"}).is_equal({1:1, "key_a": "value_a" })
# different order is also equals
assert_dict({"key_a": "value_a", 1:1}).is_equal({1:1, "key_a": "value_a" })
# should fail
assert_failure(func(): assert_dict(null).is_equal({1:1})) \
.is_failed() \
.has_message("""
Expecting:
'{
1: 1
}'
but was
'<null>'"""
.dedent()
.trim_prefix("\n")
)
assert_failure(func(): assert_dict({}).is_equal({1:1})).is_failed()
assert_failure(func(): assert_dict({1:1}).is_equal({})).is_failed()
assert_failure(func(): assert_dict({1:1}).is_equal({1:2})).is_failed()
assert_failure(func(): assert_dict({1:2}).is_equal({1:1})).is_failed()
assert_failure(func(): assert_dict({1:1}).is_equal({1:1, "key_a": "value_a"})).is_failed()
assert_failure(func(): assert_dict({1:1, "key_a": "value_a"}).is_equal({1:1})).is_failed()
assert_failure(func(): assert_dict({1:1, "key_a": "value_a"}).is_equal({1:1, "key_b": "value_b"})).is_failed()
assert_failure(func(): assert_dict({1:1, "key_b": "value_b"}).is_equal({1:1, "key_a": "value_a"})).is_failed()
assert_failure(func(): assert_dict({"key_a": "value_a", 1:1}).is_equal({1:1, "key_b": "value_b"})).is_failed()
assert_failure(func(): assert_dict({1:1, "key_b": "value_b"}).is_equal({"key_a": "value_a", 1:1})) \
.is_failed() \
.has_message("""
Expecting:
'{
1: 1,
"key_a": "value_a"
}'
but was
'{
1: 1,
"key_ab": "value_ab"
}'"""
.dedent()
.trim_prefix("\n")
)
func test_is_not_equal() -> void:
assert_dict(null).is_not_equal({})
assert_dict({}).is_not_equal(null)
assert_dict({}).is_not_equal({1:1})
assert_dict({1:1}).is_not_equal({})
assert_dict({1:1}).is_not_equal({1:2})
assert_dict({2:1}).is_not_equal({1:1})
assert_dict({1:1}).is_not_equal({1:1, "key_a": "value_a"})
assert_dict({1:1, "key_a": "value_a"}).is_not_equal({1:1})
assert_dict({1:1, "key_a": "value_a"}).is_not_equal({1:1, "key_b": "value_b"})
# should fail
assert_failure(func(): assert_dict({}).is_not_equal({})).is_failed()
assert_failure(func(): assert_dict({1:1}).is_not_equal({1:1})).is_failed()
assert_failure(func(): assert_dict({1:1, "key_a": "value_a"}).is_not_equal({1:1, "key_a": "value_a"})).is_failed()
assert_failure(func(): assert_dict({"key_a": "value_a", 1:1}).is_not_equal({1:1, "key_a": "value_a"})) \
.is_failed() \
.has_message("""
Expecting:
'{
1: 1,
"key_a": "value_a"
}'
not equal to
'{
1: 1,
"key_a": "value_a"
}'"""
.dedent()
.trim_prefix("\n")
)
func test_is_same() -> void:
var dict_a := {}
var dict_b := {"key"="value", "key2"="value"}
var dict_c := {1:1, "key_a": "value_a"}
var dict_d := {"key_a": "value_a", 1:1}
assert_dict(dict_a).is_same(dict_a)
assert_dict(dict_b).is_same(dict_b)
assert_dict(dict_c).is_same(dict_c)
assert_dict(dict_d).is_same(dict_d)
assert_failure( func(): assert_dict({}).is_same({})) \
.is_failed()\
.has_message("""
Expecting:
'{ }'
to refer to the same object
'{ }'"""
.dedent()
.trim_prefix("\n")
)
assert_failure( func(): assert_dict({1:1, "key_a": "value_a"}).is_same({1:1, "key_a": "value_a" })) \
.is_failed()\
.has_message("""
Expecting:
'{
1: 1,
"key_a": "value_a"
}'
to refer to the same object
'{
1: 1,
"key_a": "value_a"
}'"""
.dedent()
.trim_prefix("\n")
)
func test_is_not_same() -> void:
var dict_a := {}
var dict_b := {}
var dict_c := {1:1, "key_a": "value_a"}
var dict_d := {1:1, "key_a": "value_a"}
assert_dict(dict_a).is_not_same(dict_b).is_not_same(dict_c).is_not_same(dict_d)
assert_dict(dict_b).is_not_same(dict_a).is_not_same(dict_c).is_not_same(dict_d)
assert_dict(dict_c).is_not_same(dict_a).is_not_same(dict_b).is_not_same(dict_d)
assert_dict(dict_d).is_not_same(dict_a).is_not_same(dict_b).is_not_same(dict_c)
assert_failure( func(): assert_dict(dict_a).is_not_same(dict_a)) \
.is_failed()\
.has_message("""
Expecting not same:
'{ }'"""
.dedent()
.trim_prefix("\n")
)
assert_failure( func(): assert_dict(dict_c).is_not_same(dict_c)) \
.is_failed()\
.has_message("""
Expecting not same:
'{
1: 1,
"key_a": "value_a"
}'"""
.dedent()
.trim_prefix("\n")
)
func test_is_empty() -> void:
assert_dict({}).is_empty()
assert_failure(func(): assert_dict(null).is_empty()) \
.is_failed() \
.has_message("Expecting:\n"
+ " must be empty but was\n"
+ " '<null>'")
assert_failure(func(): assert_dict({1:1}).is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'{
1: 1
}'"""
.dedent()
.trim_prefix("\n")
)
func test_is_not_empty() -> void:
assert_dict({1:1}).is_not_empty()
assert_dict({1:1, "key_a": "value_a"}).is_not_empty()
assert_failure(func(): assert_dict(null).is_not_empty()) \
.is_failed() \
.has_message("Expecting:\n"
+ " must not be empty")
assert_failure(func(): assert_dict({}).is_not_empty()).is_failed()
func test_has_size() -> void:
assert_dict({}).has_size(0)
assert_dict({1:1}).has_size(1)
assert_dict({1:1, 2:1}).has_size(2)
assert_dict({1:1, 2:1, 3:1}).has_size(3)
assert_failure(func(): assert_dict(null).has_size(0))\
.is_failed() \
.has_message("Expecting: not to be '<null>'")
assert_failure(func(): assert_dict(null).has_size(1)).is_failed()
assert_failure(func(): assert_dict({}).has_size(1)).is_failed()
assert_failure(func(): assert_dict({1:1}).has_size(0)).is_failed()
assert_failure(func(): assert_dict({1:1}).has_size(2)) \
.is_failed() \
.has_message("""
Expecting size:
'2'
but was
'1'"""
.dedent()
.trim_prefix("\n")
)
class TestObj:
var _name :String
var _value :int
func _init(name :String = "Foo", value :int = 0):
_name = name
_value = value
func _to_string() -> String:
return "class:%s:%d" % [_name, _value]
func test_contains_keys() -> void:
var key_a := TestObj.new()
var key_b := TestObj.new()
var key_c := TestObj.new()
var key_d := TestObj.new("D")
assert_dict({1:1, 2:2, 3:3}).contains_keys([2])
assert_dict({1:1, 2:2, "key_a": "value_a"}).contains_keys([2, "key_a"])
assert_dict({key_a:1, key_b:2, key_c:3}).contains_keys([key_a, key_b])
assert_dict({key_a:1, key_c:3 }).contains_keys([key_b])
assert_dict({key_a:1, 3:3}).contains_keys([key_a, key_b])
assert_failure(func(): assert_dict({1:1, 3:3}).contains_keys([2])) \
.is_failed() \
.has_message("""
Expecting contains keys:
'[1, 3]'
to contains:
'[2]'
but can't find key's:
'[2]'"""
.dedent()
.trim_prefix("\n")
)
assert_failure(func(): assert_dict({1:1, 3:3}).contains_keys([1, 4])) \
.is_failed() \
.has_message("""
Expecting contains keys:
'[1, 3]'
to contains:
'[1, 4]'
but can't find key's:
'[4]'"""
.dedent()
.trim_prefix("\n")
)
assert_failure(func(): assert_dict(null).contains_keys([1, 4])) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
assert_failure(func(): assert_dict({key_a:1, 3:3}).contains_keys([key_a, key_d])) \
.is_failed() \
.has_message("""
Expecting contains keys:
'[class:Foo:0, 3]'
to contains:
'[class:Foo:0, class:D:0]'
but can't find key's:
'[class:D:0]'"""
.dedent().trim_prefix("\n"))
func test_contains_key_value() -> void:
assert_dict({1:1}).contains_key_value(1, 1)
assert_dict({1:1, 2:2, 3:3}).contains_key_value(3, 3).contains_key_value(1, 1)
assert_failure(func(): assert_dict({1:1}).contains_key_value(1, 2)) \
.is_failed() \
.has_message("""
Expecting contains key and value:
'1' : '2'
but contains
'1' : '1'"""
.dedent()
.trim_prefix("\n")
)
assert_failure(func(): assert_dict(null).contains_key_value(1, 2)) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_not_contains_keys() -> void:
assert_dict({}).not_contains_keys([2])
assert_dict({1:1, 3:3}).not_contains_keys([2])
assert_dict({1:1, 3:3}).not_contains_keys([2, 4])
assert_failure(func(): assert_dict({1:1, 2:2, 3:3}).not_contains_keys([2, 4])) \
.is_failed() \
.has_message("""
Expecting NOT contains keys:
'[1, 2, 3]'
do not contains:
'[2, 4]'
but contains key's:
'[2]'"""
.dedent()
.trim_prefix("\n")
)
assert_failure(func(): assert_dict({1:1, 2:2, 3:3}).not_contains_keys([1, 2, 3, 4])) \
.is_failed() \
.has_message("""
Expecting NOT contains keys:
'[1, 2, 3]'
do not contains:
'[1, 2, 3, 4]'
but contains key's:
'[1, 2, 3]'"""
.dedent()
.trim_prefix("\n")
)
assert_failure(func(): assert_dict(null).not_contains_keys([1, 4])) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_contains_same_keys() -> void:
var key_a := TestObj.new()
var key_b := TestObj.new()
var key_c := TestObj.new()
assert_dict({1:1, 2:2, 3:3}).contains_same_keys([2])
assert_dict({1:1, 2:2, "key_a": "value_a"}).contains_same_keys([2, "key_a"])
assert_dict({key_a:1, key_b:2, 3:3}).contains_same_keys([key_b])
assert_dict({key_a:1, key_b:2, 3:3}).contains_same_keys([key_a, key_b])
assert_failure(func(): assert_dict({key_a:1, key_c:3 }).contains_same_keys([key_a, key_b])) \
.is_failed() \
.has_message("""
Expecting contains SAME keys:
'[class:Foo:0, class:Foo:0]'
to contains:
'[class:Foo:0, class:Foo:0]'
but can't find key's:
'[class:Foo:0]'"""
.dedent().trim_prefix("\n")
)
func test_contains_same_key_value() -> void:
var key_a := TestObj.new("A")
var key_b := TestObj.new("B")
var key_c := TestObj.new("C")
var key_d := TestObj.new("A")
assert_dict({key_a:1, key_b:2, key_c:3})\
.contains_same_key_value(key_a, 1)\
.contains_same_key_value(key_b, 2)
assert_failure(func(): assert_dict({key_a:1, key_b:2, key_c:3}).contains_same_key_value(key_a, 2)) \
.is_failed() \
.has_message("""
Expecting contains SAME key and value:
<class:A:0> : '2'
but contains
<class:A:0> : '1'"""
.dedent().trim_prefix("\n")
)
assert_failure(func(): assert_dict({key_a:1, key_b:2, key_c:3}).contains_same_key_value(key_d, 1)) \
.is_failed() \
.has_message("""
Expecting contains SAME key and value:
<class:A:0> : '1'
but contains
<class:A:0> : '[class:A:0, class:B:0, class:C:0]'"""
.dedent().trim_prefix("\n")
)
func test_not_contains_same_keys() -> void:
var key_a := TestObj.new("A")
var key_b := TestObj.new("B")
var key_c := TestObj.new("C")
var key_d := TestObj.new("A")
assert_dict({}).not_contains_same_keys([key_a])
assert_dict({key_a:1, key_b:2}).not_contains_same_keys([key_c, key_d])
assert_failure(func(): assert_dict({key_a:1, key_b:2}).not_contains_same_keys([key_c, key_b])) \
.is_failed() \
.has_message("""
Expecting NOT contains SAME keys
'[class:A:0, class:B:0]'
do not contains:
'[class:C:0, class:B:0]'
but contains key's:
'[class:B:0]'"""
.dedent().trim_prefix("\n")
)
func test_override_failure_message() -> void:
assert_failure(func(): assert_dict({1:1}) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_dict({}).is_empty()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_dict({}).is_not_empty()).is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_dict({}).is_empty()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()
# should abort here because we had an failing assert
if is_failure():
return
assert_bool(true).override_failure_message("This line shold never be called").is_false()

View file

@ -0,0 +1,79 @@
# GdUnit generated TestSuite
class_name GdUnitFailureAssertImplTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitFailureAssertImpl.gd'
func last_assert() -> Variant:
return GdUnitThreadManager.get_current_context().get_assert()
func test_has_line() -> void:
assert_failure(func(): assert_bool(true).is_false()) \
.is_failed() \
.has_line(16)
func test_has_message() -> void:
assert_failure(func(): assert_bool(true).is_true()) \
.is_success()
assert_failure(func(): assert_bool(true).is_false()) \
.is_failed()\
.has_message("Expecting: 'false' but is 'true'")
func test_starts_with_message() -> void:
assert_failure(func(): assert_bool(true).is_false()) \
.is_failed()\
.starts_with_message("Expecting: 'false' bu")
func test_assert_failure_on_invalid_cb() -> void:
assert_failure(func(): prints())\
.is_failed()\
.has_message("Invalid Callable! It must be a callable of 'GdUnitAssert'")
@warning_ignore("unused_parameter")
func test_assert_failure_on_assert(test_name :String, assert_type, value, test_parameters = [
["GdUnitBoolAssert", GdUnitBoolAssert, true],
["GdUnitStringAssert", GdUnitStringAssert, "value"],
["GdUnitIntAssert", GdUnitIntAssert, 42],
["GdUnitFloatAssert", GdUnitFloatAssert, 42.0],
["GdUnitObjectAssert", GdUnitObjectAssert, RefCounted.new()],
["GdUnitVectorAssert", GdUnitVectorAssert, Vector2.ZERO],
["GdUnitVectorAssert", GdUnitVectorAssert, Vector3.ZERO],
["GdUnitArrayAssert", GdUnitArrayAssert, Array()],
["GdUnitDictionaryAssert", GdUnitDictionaryAssert, {}],
]) -> void:
var instance := assert_failure(func(): assert_that(value))
assert_object(last_assert()).is_instanceof(assert_type)
assert_object(instance).is_instanceof(GdUnitFailureAssert)
func test_assert_failure_on_assert_file() -> void:
var instance := assert_failure(func(): assert_file("res://foo.gd"))
assert_object(last_assert()).is_instanceof(GdUnitFileAssert)
assert_object(instance).is_instanceof(GdUnitFailureAssert)
func test_assert_failure_on_assert_func() -> void:
var instance := assert_failure(func(): assert_func(RefCounted.new(), "_to_string"))
assert_object(last_assert()).is_instanceof(GdUnitFuncAssert)
assert_object(instance).is_instanceof(GdUnitFailureAssert)
func test_assert_failure_on_assert_signal() -> void:
var instance := assert_failure(func(): assert_signal(null))
assert_object(last_assert()).is_instanceof(GdUnitSignalAssert)
assert_object(instance).is_instanceof(GdUnitFailureAssert)
func test_assert_failure_on_assert_result() -> void:
var instance := assert_failure(func(): assert_result(null))
assert_object(last_assert()).is_instanceof(GdUnitResultAssert)
assert_object(instance).is_instanceof(GdUnitFailureAssert)

View file

@ -0,0 +1,246 @@
# GdUnit generated TestSuite
class_name GdUnitFloatAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitFloatAssertImpl.gd'
func test_is_null():
assert_float(null).is_null()
assert_failure(func(): assert_float(23.2).is_null()) \
.is_failed() \
.starts_with_message("Expecting: '<null>' but was '23.200000'")
func test_is_not_null():
assert_float(23.2).is_not_null()
assert_failure(func(): assert_float(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_equal():
assert_float(23.2).is_equal(23.2)
assert_failure(func(): assert_float(23.2).is_equal(23.4)) \
.is_failed() \
.has_message("Expecting:\n '23.400000'\n but was\n '23.200000'")
assert_failure(func(): assert_float(null).is_equal(23.4)) \
.is_failed() \
.has_message("Expecting:\n '23.400000'\n but was\n '<null>'")
func test_is_not_equal():
assert_float(null).is_not_equal(23.4)
assert_float(23.2).is_not_equal(23.4)
assert_failure(func(): assert_float(23.2).is_not_equal(23.2)) \
.is_failed() \
.has_message("Expecting:\n '23.200000'\n not equal to\n '23.200000'")
func test_is_equal_approx() -> void:
assert_float(23.2).is_equal_approx(23.2, 0.01)
assert_float(23.19).is_equal_approx(23.2, 0.01)
assert_float(23.20).is_equal_approx(23.2, 0.01)
assert_float(23.21).is_equal_approx(23.2, 0.01)
assert_failure(func(): assert_float(23.18).is_equal_approx(23.2, 0.01)) \
.is_failed() \
.has_message("Expecting:\n '23.180000'\n in range between\n '23.190000' <> '23.210000'")
assert_failure(func(): assert_float(23.22).is_equal_approx(23.2, 0.01)) \
.is_failed() \
.has_message("Expecting:\n '23.220000'\n in range between\n '23.190000' <> '23.210000'")
assert_failure(func(): assert_float(null).is_equal_approx(23.2, 0.01)) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n in range between\n '23.190000' <> '23.210000'")
func test_is_less_():
assert_failure(func(): assert_float(23.2).is_less(23.2)) \
.is_failed() \
.has_message("Expecting to be less than:\n '23.200000' but was '23.200000'")
func test_is_less():
assert_float(23.2).is_less(23.4)
assert_float(23.2).is_less(26.0)
assert_failure(func(): assert_float(23.2).is_less(23.2)) \
.is_failed() \
.has_message("Expecting to be less than:\n '23.200000' but was '23.200000'")
assert_failure(func(): assert_float(null).is_less(23.2)) \
.is_failed() \
.has_message("Expecting to be less than:\n '23.200000' but was '<null>'")
func test_is_less_equal():
assert_float(23.2).is_less_equal(23.4)
assert_float(23.2).is_less_equal(23.2)
assert_failure(func(): assert_float(23.2).is_less_equal(23.1)) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '23.100000' but was '23.200000'")
assert_failure(func(): assert_float(null).is_less_equal(23.1)) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '23.100000' but was '<null>'")
func test_is_greater():
assert_float(23.2).is_greater(23.0)
assert_float(23.4).is_greater(22.1)
assert_failure(func(): assert_float(23.2).is_greater(23.2)) \
.is_failed() \
.has_message("Expecting to be greater than:\n '23.200000' but was '23.200000'")
assert_failure(func(): assert_float(null).is_greater(23.2)) \
.is_failed() \
.has_message("Expecting to be greater than:\n '23.200000' but was '<null>'")
func test_is_greater_equal():
assert_float(23.2).is_greater_equal(20.2)
assert_float(23.2).is_greater_equal(23.2)
assert_failure(func(): assert_float(23.2).is_greater_equal(23.3)) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '23.300000' but was '23.200000'")
assert_failure(func(): assert_float(null).is_greater_equal(23.3)) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '23.300000' but was '<null>'")
func test_is_negative():
assert_float(-13.2).is_negative()
assert_failure(func(): assert_float(13.2).is_negative()) \
.is_failed() \
.has_message("Expecting:\n '13.200000' be negative")
assert_failure(func(): assert_float(null).is_negative()) \
.is_failed() \
.has_message("Expecting:\n '<null>' be negative")
func test_is_not_negative():
assert_float(13.2).is_not_negative()
assert_failure(func(): assert_float(-13.2).is_not_negative()) \
.is_failed() \
.has_message("Expecting:\n '-13.200000' be not negative")
assert_failure(func(): assert_float(null).is_not_negative()) \
.is_failed() \
.has_message("Expecting:\n '<null>' be not negative")
func test_is_zero():
assert_float(0.0).is_zero()
assert_failure(func(): assert_float(0.00001).is_zero()) \
.is_failed() \
.has_message("Expecting:\n equal to 0 but is '0.000010'")
assert_failure(func(): assert_float(null).is_zero()) \
.is_failed() \
.has_message("Expecting:\n equal to 0 but is '<null>'")
func test_is_not_zero():
assert_float(0.00001).is_not_zero()
assert_failure(func(): assert_float(0.000001).is_not_zero()) \
.is_failed() \
.has_message("Expecting:\n not equal to 0")
assert_failure(func(): assert_float(null).is_not_zero()) \
.is_failed() \
.has_message("Expecting:\n not equal to 0")
func test_is_in():
assert_float(5.2).is_in([5.1, 5.2, 5.3, 5.4])
# this assertion fail because 5.5 is not in [5.1, 5.2, 5.3, 5.4]
assert_failure(func(): assert_float(5.5).is_in([5.1, 5.2, 5.3, 5.4])) \
.is_failed() \
.has_message("Expecting:\n '5.500000'\n is in\n '[5.1, 5.2, 5.3, 5.4]'")
assert_failure(func(): assert_float(null).is_in([5.1, 5.2, 5.3, 5.4])) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n is in\n '[5.1, 5.2, 5.3, 5.4]'")
func test_is_not_in():
assert_float(null).is_not_in([5.1, 5.3, 5.4])
assert_float(5.2).is_not_in([5.1, 5.3, 5.4])
# this assertion fail because 5.2 is not in [5.1, 5.2, 5.3, 5.4]
assert_failure(func(): assert_float(5.2).is_not_in([5.1, 5.2, 5.3, 5.4])) \
.is_failed() \
.has_message("Expecting:\n '5.200000'\n is not in\n '[5.1, 5.2, 5.3, 5.4]'")
func test_is_between():
assert_float(-20.0).is_between(-20.0, 20.9)
assert_float(10.0).is_between(-20.0, 20.9)
assert_float(20.9).is_between(-20.0, 20.9)
func test_is_between_must_fail():
assert_failure(func(): assert_float(-10.0).is_between(-9.0, 0.0)) \
.is_failed() \
.has_message("Expecting:\n '-10.000000'\n in range between\n '-9.000000' <> '0.000000'")
assert_failure(func(): assert_float(0.0).is_between(1, 10)) \
.is_failed() \
.has_message("Expecting:\n '0.000000'\n in range between\n '1.000000' <> '10.000000'")
assert_failure(func(): assert_float(10.0).is_between(11, 21)) \
.is_failed() \
.has_message("Expecting:\n '10.000000'\n in range between\n '11.000000' <> '21.000000'")
assert_failure(func(): assert_float(null).is_between(11, 21)) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n in range between\n '11.000000' <> '21.000000'")
func test_must_fail_has_invlalid_type():
assert_failure(func(): assert_float(1)) \
.is_failed() \
.has_message("GdUnitFloatAssert inital error, unexpected type <int>")
assert_failure(func(): assert_float(true)) \
.is_failed() \
.has_message("GdUnitFloatAssert inital error, unexpected type <bool>")
assert_failure(func(): assert_float("foo")) \
.is_failed() \
.has_message("GdUnitFloatAssert inital error, unexpected type <String>")
assert_failure(func(): assert_float(Resource.new())) \
.is_failed() \
.has_message("GdUnitFloatAssert inital error, unexpected type <Object>")
func test_override_failure_message() -> void:
assert_failure(func(): assert_float(3.14) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_float(0.0).is_zero()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_float(1.0).is_zero()) \
.is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_float(0.0).is_zero()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()
# should abort here because we had an failing assert
if is_failure():
return
assert_bool(true).override_failure_message("This line shold never be called").is_false()

View file

@ -0,0 +1,368 @@
# GdUnit generated TestSuite
class_name GdUnitFuncAssertImplTest
extends GdUnitTestSuite
@warning_ignore("unused_parameter")
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitFuncAssertImpl.gd'
const GdUnitTools = preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
# we need to skip await fail test because of an bug in Godot 4.0 stable
func is_skip_fail_await() -> bool:
return Engine.get_version_info().hex < 0x40002
class TestValueProvider:
var _max_iterations :int
var _current_itteration := 0
func _init(iterations := 0):
_max_iterations = iterations
func bool_value() -> bool:
_current_itteration += 1
if _current_itteration == _max_iterations:
return true
return false
func int_value() -> int:
return 0
func float_value() -> float:
return 0.0
func string_value() -> String:
return "value"
func object_value() -> Object:
return Resource.new()
func array_value() -> Array:
return []
func dict_value() -> Dictionary:
return {}
func vec2_value() -> Vector2:
return Vector2.ONE
func vec3_value() -> Vector3:
return Vector3.ONE
func no_value() -> void:
pass
func unknown_value():
return Vector3.ONE
class ValueProvidersWithArguments:
func is_type(_type :int) -> bool:
return true
func get_index(_instance :Object, _name :String) -> int:
return 1
func get_index2(_instance :Object, _name :String, _recursive := false) -> int:
return 1
class TestIterativeValueProvider:
var _max_iterations :int
var _current_itteration := 0
var _inital_value
var _final_value
func _init(inital_value, iterations :int, final_value):
_max_iterations = iterations
_inital_value = inital_value
_final_value = final_value
func bool_value() -> bool:
_current_itteration += 1
if _current_itteration >= _max_iterations:
return _final_value
return _inital_value
func int_value() -> int:
_current_itteration += 1
if _current_itteration >= _max_iterations:
return _final_value
return _inital_value
func obj_value() -> Variant:
_current_itteration += 1
if _current_itteration >= _max_iterations:
return _final_value
return _inital_value
func has_type(type :int, _recursive :bool = true) -> int:
_current_itteration += 1
#await Engine.get_main_loop().idle_frame
if type == _current_itteration:
return _final_value
return _inital_value
func await_value() -> int:
_current_itteration += 1
await Engine.get_main_loop().process_frame
prints("yielded_value", _current_itteration)
if _current_itteration >= _max_iterations:
return _final_value
return _inital_value
func reset() -> void:
_current_itteration = 0
func iteration() -> int:
return _current_itteration
@warning_ignore("unused_parameter")
func test_is_null(timeout = 2000) -> void:
var value_provider := TestIterativeValueProvider.new(RefCounted.new(), 5, null)
# without default timeout od 2000ms
assert_func(value_provider, "obj_value").is_not_null()
await assert_func(value_provider, "obj_value").is_null()
assert_int(value_provider.iteration()).is_equal(5)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "obj_value").is_not_null()
await assert_func(value_provider, "obj_value").wait_until(5000).is_null()
assert_int(value_provider.iteration()).is_equal(5)
# failure case
if is_skip_fail_await():
return
value_provider = TestIterativeValueProvider.new(RefCounted.new(), 1, RefCounted.new())
(
await assert_failure_await(func(): await assert_func(value_provider, "obj_value", []).wait_until(100).is_null())
).has_message("Expected: is null but timed out after 100ms")
@warning_ignore("unused_parameter")
func test_is_not_null(timeout = 2000) -> void:
var value_provider := TestIterativeValueProvider.new(null, 5, RefCounted.new())
# without default timeout od 2000ms
assert_func(value_provider, "obj_value").is_null()
await assert_func(value_provider, "obj_value").is_not_null()
assert_int(value_provider.iteration()).is_equal(5)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "obj_value").is_null()
await assert_func(value_provider, "obj_value").wait_until(5000).is_not_null()
assert_int(value_provider.iteration()).is_equal(5)
# failure case
value_provider = TestIterativeValueProvider.new(null, 1, null)
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(value_provider, "obj_value", []).wait_until(100).is_not_null())
).has_message("Expected: is not null but timed out after 100ms")
@warning_ignore("unused_parameter")
func test_is_true(timeout = 2000) -> void:
var value_provider := TestIterativeValueProvider.new(false, 5, true)
# without default timeout od 2000ms
assert_func(value_provider, "bool_value").is_false()
await assert_func(value_provider, "bool_value").is_true()
assert_int(value_provider.iteration()).is_equal(5)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "bool_value").is_false()
await assert_func(value_provider, "bool_value").wait_until(5000).is_true()
assert_int(value_provider.iteration()).is_equal(5)
# failure case
value_provider = TestIterativeValueProvider.new(false, 1, false)
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(value_provider, "bool_value", []).wait_until(100).is_true())
).has_message("Expected: is true but timed out after 100ms")
@warning_ignore("unused_parameter")
func test_is_false(timeout = 2000) -> void:
var value_provider := TestIterativeValueProvider.new(true, 5, false)
# without default timeout od 2000ms
assert_func(value_provider, "bool_value").is_true()
await assert_func(value_provider, "bool_value").is_false()
assert_int(value_provider.iteration()).is_equal(5)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "bool_value").is_true()
await assert_func(value_provider, "bool_value").wait_until(5000).is_false()
assert_int(value_provider.iteration()).is_equal(5)
# failure case
value_provider = TestIterativeValueProvider.new(true, 1, true)
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(value_provider, "bool_value", []).wait_until(100).is_false())
).has_message("Expected: is false but timed out after 100ms")
@warning_ignore("unused_parameter")
func test_is_equal(timeout = 2000) -> void:
var value_provider := TestIterativeValueProvider.new(42, 5, 23)
# without default timeout od 2000ms
assert_func(value_provider, "int_value").is_equal(42)
await assert_func(value_provider, "int_value").is_equal(23)
assert_int(value_provider.iteration()).is_equal(5)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "int_value").is_equal(42)
await assert_func(value_provider, "int_value").wait_until(5000).is_equal(23)
assert_int(value_provider.iteration()).is_equal(5)
# failing case
value_provider = TestIterativeValueProvider.new(23, 1, 23)
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(value_provider, "int_value", []).wait_until(100).is_equal(25))
).has_message("Expected: is equal '25' but timed out after 100ms")
@warning_ignore("unused_parameter")
func test_is_not_equal(timeout = 2000) -> void:
var value_provider := TestIterativeValueProvider.new(42, 5, 23)
# without default timeout od 2000ms
assert_func(value_provider, "int_value").is_equal(42)
await assert_func(value_provider, "int_value").is_not_equal(42)
assert_int(value_provider.iteration()).is_equal(5)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "int_value").is_equal(42)
await assert_func(value_provider, "int_value").wait_until(5000).is_not_equal(42)
assert_int(value_provider.iteration()).is_equal(5)
# failing case
value_provider = TestIterativeValueProvider.new(23, 1, 23)
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(value_provider, "int_value", []).wait_until(100).is_not_equal(23))
).has_message("Expected: is not equal '23' but timed out after 100ms")
@warning_ignore("unused_parameter")
func test_is_equal_wiht_func_arg(timeout = 1300) -> void:
var value_provider := TestIterativeValueProvider.new(42, 10, 23)
# without default timeout od 2000ms
assert_func(value_provider, "has_type", [1]).is_equal(42)
await assert_func(value_provider, "has_type", [10]).is_equal(23)
assert_int(value_provider.iteration()).is_equal(10)
# with a timeout of 5s
value_provider.reset()
assert_func(value_provider, "has_type", [1]).is_equal(42)
await assert_func(value_provider, "has_type", [10]).wait_until(5000).is_equal(23)
assert_int(value_provider.iteration()).is_equal(10)
# abort test after 500ms to fail
@warning_ignore("unused_parameter")
func test_timeout_and_assert_fails(timeout = 500) -> void:
# disable temporary the timeout errors for this test
discard_error_interupted_by_timeout()
var value_provider := TestIterativeValueProvider.new(1, 10, 10)
# wait longer than test timeout, the value will be never '42'
await assert_func(value_provider, "int_value").wait_until(1000).is_equal(42)
fail("The test must be interrupted after 500ms")
func timed_function() -> Color:
var color = Color.RED
await await_millis(20)
color = Color.GREEN
await await_millis(20)
color = Color.BLUE
await await_millis(20)
color = Color.BLACK
return color
func test_timer_yielded_function() -> void:
await assert_func(self, "timed_function").is_equal(Color.BLACK)
# will be never red
await assert_func(self, "timed_function").wait_until(100).is_not_equal(Color.RED)
# failure case
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(self, "timed_function", []).wait_until(100).is_equal(Color.RED))
).has_message("Expected: is equal 'Color(1, 0, 0, 1)' but timed out after 100ms")
func test_timer_yielded_function_timeout() -> void:
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(self, "timed_function", []).wait_until(40).is_equal(Color.BLACK))
).has_message("Expected: is equal 'Color()' but timed out after 40ms")
func yielded_function() -> Color:
var color = Color.RED
await get_tree().process_frame
color = Color.GREEN
await get_tree().process_frame
color = Color.BLUE
await get_tree().process_frame
color = Color.BLACK
return color
func test_idle_frame_yielded_function() -> void:
await assert_func(self, "yielded_function").is_equal(Color.BLACK)
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(self, "yielded_function", []).wait_until(500).is_equal(Color.RED))
).has_message("Expected: is equal 'Color(1, 0, 0, 1)' but timed out after 500ms")
func test_has_failure_message() -> void:
if is_skip_fail_await():
return
var value_provider := TestIterativeValueProvider.new(10, 1, 10)
(
await assert_failure_await(func(): await assert_func(value_provider, "int_value", []).wait_until(500).is_equal(42))
).has_message("Expected: is equal '42' but timed out after 500ms")
func test_override_failure_message() -> void:
if is_skip_fail_await():
return
var value_provider := TestIterativeValueProvider.new(10, 1, 20)
(
await assert_failure_await(func(): await assert_func(value_provider, "int_value", []) \
.override_failure_message("Custom failure message") \
.wait_until(100) \
.is_equal(42))
).has_message("Custom failure message")
@warning_ignore("unused_parameter")
func test_invalid_function(timeout = 100):
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_func(self, "invalid_func_name", [])\
.wait_until(1000)\
.is_equal(42))
).starts_with_message("The function 'invalid_func_name' do not exists checked instance")

View file

@ -0,0 +1,137 @@
# GdUnit generated TestSuite
class_name GdUnitGodotErrorAssertImplTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitGodotErrorAssertImpl.gd'
class GodotErrorTestClass:
func test(value :int) -> void:
match value:
0:
@warning_ignore("assert_always_true")
assert(true, "no error" )
1: # failing assert
await Engine.get_main_loop().process_frame
if OS.is_debug_build():
# do not break the debug session we simmulate a assert by writing the error manually
prints("""
USER SCRIPT ERROR: Assertion failed: this is an assert error
at: GodotErrorTestClass.test (res://addons/gdUnit4/test/asserts/GdUnitGodotErrorAssertImplTest.gd:18)
""".dedent())
else:
assert(false, "this is an assert error" )
2: # push_warning
push_warning('this is an push_warning')
3: # push_error
push_error('this is an push_error')
pass
4: # runtime error
if OS.is_debug_build():
# do not break the debug session we simmulate a assert by writing the error manually
prints("""
USER SCRIPT ERROR: Division by zero error in operator '/'.
at: GodotErrorTestClass.test (res://addons/gdUnit4/test/asserts/GdUnitGodotErrorAssertImplTest.gd:32)
""".dedent())
else:
var a = 0
@warning_ignore("integer_division")
@warning_ignore("unused_variable")
var x = 1/a
var _save_is_report_push_errors :bool
var _save_is_report_script_errors :bool
# skip see https://github.com/godotengine/godot/issues/80292
@warning_ignore('unused_parameter')
func before(do_skip=Engine.get_version_info().hex < 0x40100, skip_reason="Exclude this test suite for Godot versions <= 4.1.x"):
_save_is_report_push_errors = GdUnitSettings.is_report_push_errors()
_save_is_report_script_errors = GdUnitSettings.is_report_script_errors()
# disable default error reporting for testing
ProjectSettings.set_setting(GdUnitSettings.REPORT_PUSH_ERRORS, false)
ProjectSettings.set_setting(GdUnitSettings.REPORT_SCRIPT_ERRORS, false)
func after():
ProjectSettings.set_setting(GdUnitSettings.REPORT_PUSH_ERRORS, _save_is_report_push_errors)
ProjectSettings.set_setting(GdUnitSettings.REPORT_SCRIPT_ERRORS, _save_is_report_script_errors)
func after_test():
# Cleanup report artifacts
GdUnitThreadManager.get_current_context().get_execution_context().error_monitor._entries.clear()
func test_invalid_callable() -> void:
assert_failure(func(): assert_error(Callable()).is_success())\
.is_failed()\
.has_message("Invalid Callable 'null::null'")
func test_is_success() -> void:
await assert_error(func (): await GodotErrorTestClass.new().test(0)).is_success()
var assert_ = await assert_failure_await(func():
await assert_error(func (): await GodotErrorTestClass.new().test(1)).is_success())
assert_.is_failed().has_message("""
Expecting: no error's are ocured.
but found: 'Assertion failed: this is an assert error'
""".dedent().trim_prefix("\n"))
func test_is_assert_failed() -> void:
await assert_error(func (): await GodotErrorTestClass.new().test(1))\
.is_runtime_error('Assertion failed: this is an assert error')
var assert_ = await assert_failure_await(func():
await assert_error(func (): GodotErrorTestClass.new().test(0)).is_runtime_error('Assertion failed: this is an assert error'))
assert_.is_failed().has_message("""
Expecting: a runtime error is triggered.
message: 'Assertion failed: this is an assert error'
found: no errors
""".dedent().trim_prefix("\n"))
func test_is_push_warning() -> void:
await assert_error(func (): GodotErrorTestClass.new().test(2))\
.is_push_warning('this is an push_warning')
var assert_ = await assert_failure_await(func():
await assert_error(func (): GodotErrorTestClass.new().test(0)).is_push_warning('this is an push_warning'))
assert_.is_failed().has_message("""
Expecting: push_warning() is called.
message: 'this is an push_warning'
found: no errors
""".dedent().trim_prefix("\n"))
func test_is_push_error() -> void:
await assert_error(func (): GodotErrorTestClass.new().test(3))\
.is_push_error('this is an push_error')
var assert_ = await assert_failure_await(func():
await assert_error(func (): GodotErrorTestClass.new().test(0)).is_push_error('this is an push_error'))
assert_.is_failed().has_message("""
Expecting: push_error() is called.
message: 'this is an push_error'
found: no errors
""".dedent().trim_prefix("\n"))
func test_is_runtime_error() -> void:
await assert_error(func (): GodotErrorTestClass.new().test(4))\
.is_runtime_error("Division by zero error in operator '/'.")
var assert_ = await assert_failure_await(func():
await assert_error(func (): GodotErrorTestClass.new().test(0)).is_runtime_error("Division by zero error in operator '/'."))
assert_.is_failed().has_message("""
Expecting: a runtime error is triggered.
message: 'Division by zero error in operator '/'.'
found: no errors
""".dedent().trim_prefix("\n"))

View file

@ -0,0 +1,40 @@
extends GdUnitTestSuite
var _catched_events :Array[GdUnitEvent] = []
func test_assert_method_with_enabled_global_error_report() -> void:
ProjectSettings.set_setting(GdUnitSettings.REPORT_SCRIPT_ERRORS, true)
await assert_error(do_a_fail).is_runtime_error('Assertion failed: test')
func test_assert_method_with_disabled_global_error_report() -> void:
ProjectSettings.set_setting(GdUnitSettings.REPORT_SCRIPT_ERRORS, false)
await assert_error(do_a_fail).is_runtime_error('Assertion failed: test')
@warning_ignore("assert_always_false")
func do_a_fail():
if OS.is_debug_build():
# On debug level we need to simulate the assert log entry, otherwise we stuck on a breakpoint
prints("""
USER SCRIPT ERROR: Assertion failed: test
at: do_a_fail (res://addons/gdUnit4/test/asserts/GdUnitErrorAssertTest.gd:20)""")
else:
assert(3 == 1, 'test')
func catch_test_events(event :GdUnitEvent) -> void:
_catched_events.append(event)
func before() -> void:
GdUnitSignals.instance().gdunit_event.connect(catch_test_events)
func after() -> void:
# We expect no errors or failures, as we caught already the assert error by using the assert `assert_error` on the test case
assert_array(_catched_events).extractv(extr("error_count"), extr("failed_count"))\
.contains_exactly([tuple(0, 0), tuple(0,0), tuple(0,0), tuple(0,0)])
GdUnitSignals.instance().gdunit_event.disconnect(catch_test_events)

View file

@ -0,0 +1,242 @@
# GdUnit generated TestSuite
class_name GdUnitIntAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitIntAssertImpl.gd'
func test_is_null():
assert_int(null).is_null()
assert_failure(func(): assert_int(23).is_null()) \
.is_failed() \
.starts_with_message("Expecting: '<null>' but was '23'")
func test_is_not_null():
assert_int(23).is_not_null()
assert_failure(func(): assert_int(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_equal():
assert_int(23).is_equal(23)
assert_failure(func(): assert_int(23).is_equal(42)) \
.is_failed() \
.has_message("Expecting:\n '42'\n but was\n '23'")
assert_failure(func(): assert_int(null).is_equal(42)) \
.is_failed() \
.has_message("Expecting:\n '42'\n but was\n '<null>'")
func test_is_not_equal():
assert_int(null).is_not_equal(42)
assert_int(23).is_not_equal(42)
assert_failure(func(): assert_int(23).is_not_equal(23)) \
.is_failed() \
.has_message("Expecting:\n '23'\n not equal to\n '23'")
func test_is_less():
assert_int(23).is_less(42)
assert_int(23).is_less(24)
assert_failure(func(): assert_int(23).is_less(23)) \
.is_failed() \
.has_message("Expecting to be less than:\n '23' but was '23'")
assert_failure(func(): assert_int(null).is_less(23)) \
.is_failed() \
.has_message("Expecting to be less than:\n '23' but was '<null>'")
func test_is_less_equal():
assert_int(23).is_less_equal(42)
assert_int(23).is_less_equal(23)
assert_failure(func(): assert_int(23).is_less_equal(22)) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '22' but was '23'")
assert_failure(func(): assert_int(null).is_less_equal(22)) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '22' but was '<null>'")
func test_is_greater():
assert_int(23).is_greater(20)
assert_int(23).is_greater(22)
assert_failure(func(): assert_int(23).is_greater(23)) \
.is_failed() \
.has_message("Expecting to be greater than:\n '23' but was '23'")
assert_failure(func(): assert_int(null).is_greater(23)) \
.is_failed() \
.has_message("Expecting to be greater than:\n '23' but was '<null>'")
func test_is_greater_equal():
assert_int(23).is_greater_equal(20)
assert_int(23).is_greater_equal(23)
assert_failure(func(): assert_int(23).is_greater_equal(24)) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '24' but was '23'")
assert_failure(func(): assert_int(null).is_greater_equal(24)) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '24' but was '<null>'")
func test_is_even():
assert_int(12).is_even()
assert_failure(func(): assert_int(13).is_even()) \
.is_failed() \
.has_message("Expecting:\n '13' must be even")
assert_failure(func(): assert_int(null).is_even()) \
.is_failed() \
.has_message("Expecting:\n '<null>' must be even")
func test_is_odd():
assert_int(13).is_odd()
assert_failure(func(): assert_int(12).is_odd()) \
.is_failed() \
.has_message("Expecting:\n '12' must be odd")
assert_failure(func(): assert_int(null).is_odd()) \
.is_failed() \
.has_message("Expecting:\n '<null>' must be odd")
func test_is_negative():
assert_int(-13).is_negative()
assert_failure(func(): assert_int(13).is_negative()) \
.is_failed() \
.has_message("Expecting:\n '13' be negative")
assert_failure(func(): assert_int(null).is_negative()) \
.is_failed() \
.has_message("Expecting:\n '<null>' be negative")
func test_is_not_negative():
assert_int(13).is_not_negative()
assert_failure(func(): assert_int(-13).is_not_negative()) \
.is_failed() \
.has_message("Expecting:\n '-13' be not negative")
assert_failure(func(): assert_int(null).is_not_negative()) \
.is_failed() \
.has_message("Expecting:\n '<null>' be not negative")
func test_is_zero():
assert_int(0).is_zero()
assert_failure(func(): assert_int(1).is_zero()) \
.is_failed() \
.has_message("Expecting:\n equal to 0 but is '1'")
assert_failure(func(): assert_int(null).is_zero()) \
.is_failed() \
.has_message("Expecting:\n equal to 0 but is '<null>'")
func test_is_not_zero():
assert_int(null).is_not_zero()
assert_int(1).is_not_zero()
assert_failure(func(): assert_int(0).is_not_zero()) \
.is_failed() \
.has_message("Expecting:\n not equal to 0")
func test_is_in():
assert_int(5).is_in([3, 4, 5, 6])
# this assertion fail because 7 is not in [3, 4, 5, 6]
assert_failure(func(): assert_int(7).is_in([3, 4, 5, 6])) \
.is_failed() \
.has_message("Expecting:\n '7'\n is in\n '[3, 4, 5, 6]'")
assert_failure(func(): assert_int(null).is_in([3, 4, 5, 6])) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n is in\n '[3, 4, 5, 6]'")
func test_is_not_in():
assert_int(null).is_not_in([3, 4, 6, 7])
assert_int(5).is_not_in([3, 4, 6, 7])
# this assertion fail because 7 is not in [3, 4, 5, 6]
assert_failure(func(): assert_int(5).is_not_in([3, 4, 5, 6])) \
.is_failed() \
.has_message("Expecting:\n '5'\n is not in\n '[3, 4, 5, 6]'")
func test_is_between(fuzzer = Fuzzers.rangei(-20, 20)):
var value = fuzzer.next_value() as int
assert_int(value).is_between(-20, 20)
func test_is_between_must_fail():
assert_failure(func(): assert_int(-10).is_between(-9, 0)) \
.is_failed() \
.has_message("Expecting:\n '-10'\n in range between\n '-9' <> '0'")
assert_failure(func(): assert_int(0).is_between(1, 10)) \
.is_failed() \
.has_message("Expecting:\n '0'\n in range between\n '1' <> '10'")
assert_failure(func(): assert_int(10).is_between(11, 21)) \
.is_failed() \
.has_message("Expecting:\n '10'\n in range between\n '11' <> '21'")
assert_failure(func(): assert_int(null).is_between(11, 21)) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n in range between\n '11' <> '21'")
func test_must_fail_has_invlalid_type():
assert_failure(func(): assert_int(3.3)) \
.is_failed() \
.has_message("GdUnitIntAssert inital error, unexpected type <float>")
assert_failure(func(): assert_int(true)) \
.is_failed() \
.has_message("GdUnitIntAssert inital error, unexpected type <bool>")
assert_failure(func(): assert_int("foo")) \
.is_failed() \
.has_message("GdUnitIntAssert inital error, unexpected type <String>")
assert_failure(func(): assert_int(Resource.new())) \
.is_failed() \
.has_message("GdUnitIntAssert inital error, unexpected type <Object>")
func test_override_failure_message() -> void:
assert_failure(func(): assert_int(314)\
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_int(0).is_zero()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_int(1).is_zero()) \
.is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_int(0).is_zero()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()
# should abort here because we had an failing assert
if is_failure():
return
assert_bool(true).override_failure_message("This line shold never be called").is_false()

View file

@ -0,0 +1,178 @@
# GdUnit generated TestSuite
class_name GdUnitObjectAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitObjectAssertImpl.gd'
func test_is_equal():
assert_object(Mesh.new()).is_equal(Mesh.new())
assert_failure(func(): assert_object(Mesh.new()).is_equal(Skin.new())) \
.is_failed()
assert_failure(func(): assert_object(null).is_equal(Skin.new())) \
.is_failed() \
.has_message("Expecting:\n"
+ " <Skin>\n"
+ " but was\n"
+ " '<null>'")
func test_is_not_equal():
assert_object(null).is_not_equal(Skin.new())
assert_object(Mesh.new()).is_not_equal(Skin.new())
assert_failure(func(): assert_object(Mesh.new()).is_not_equal(Mesh.new())) \
.is_failed()
func test_is_instanceof():
# engine class test
assert_object(auto_free(Path3D.new())).is_instanceof(Node)
assert_object(auto_free(Camera3D.new())).is_instanceof(Camera3D)
# script class test
assert_object(auto_free(Udo.new())).is_instanceof(Person)
# inner class test
assert_object(auto_free(CustomClass.InnerClassA.new())).is_instanceof(Node)
assert_object(auto_free(CustomClass.InnerClassB.new())).is_instanceof(CustomClass.InnerClassA)
assert_failure(func(): assert_object(auto_free(Path3D.new())).is_instanceof(Tree)) \
.is_failed() \
.has_message("Expected instance of:\n 'Tree'\n But it was 'Path3D'")
assert_failure(func(): assert_object(null).is_instanceof(Tree)) \
.is_failed() \
.has_message("Expected instance of:\n 'Tree'\n But it was '<null>'")
func test_is_not_instanceof():
assert_object(null).is_not_instanceof(Tree)
# engine class test
assert_object(auto_free(Path3D.new())).is_not_instanceof(Tree)
# script class test
assert_object(auto_free(City.new())).is_not_instanceof(Person)
# inner class test
assert_object(auto_free(CustomClass.InnerClassA.new())).is_not_instanceof(Tree)
assert_object(auto_free(CustomClass.InnerClassB.new())).is_not_instanceof(CustomClass.InnerClassC)
assert_failure(func(): assert_object(auto_free(Path3D.new())).is_not_instanceof(Node)) \
.is_failed() \
.has_message("Expected not be a instance of <Node>")
func test_is_null():
assert_object(null).is_null()
assert_failure(func(): assert_object(auto_free(Node.new())).is_null()) \
.is_failed() \
.starts_with_message("Expecting: '<null>' but was <Node>")
func test_is_not_null():
assert_object(auto_free(Node.new())).is_not_null()
assert_failure(func(): assert_object(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_same():
var obj1 = auto_free(Node.new())
var obj2 = obj1
var obj3 = auto_free(obj1.duplicate())
assert_object(obj1).is_same(obj1)
assert_object(obj1).is_same(obj2)
assert_object(obj2).is_same(obj1)
assert_failure(func(): assert_object(null).is_same(obj1)) \
.is_failed() \
.has_message("Expecting:\n"
+ " <Node>\n"
+ " to refer to the same object\n"
+ " '<null>'")
assert_failure(func(): assert_object(obj1).is_same(obj3)) \
.is_failed()
assert_failure(func(): assert_object(obj3).is_same(obj1)) \
.is_failed()
assert_failure(func(): assert_object(obj3).is_same(obj2)) \
.is_failed()
func test_is_not_same():
var obj1 = auto_free(Node.new())
var obj2 = obj1
var obj3 = auto_free(obj1.duplicate())
assert_object(null).is_not_same(obj1)
assert_object(obj1).is_not_same(obj3)
assert_object(obj3).is_not_same(obj1)
assert_object(obj3).is_not_same(obj2)
assert_failure(func(): assert_object(obj1).is_not_same(obj1)) \
.is_failed() \
.has_message("""
Expecting not same:
<Node>"""
.dedent()
.trim_prefix("\n"))
assert_failure(func(): assert_object(obj1).is_not_same(obj2)) \
.is_failed() \
.has_message("""
Expecting not same:
<Node>"""
.dedent()
.trim_prefix("\n"))
assert_failure(func(): assert_object(obj2).is_not_same(obj1)) \
.is_failed() \
.has_message("""
Expecting not same:
<Node>"""
.dedent()
.trim_prefix("\n"))
func test_must_fail_has_invlalid_type():
assert_failure(func(): assert_object(1)) \
.is_failed() \
.has_message("GdUnitObjectAssert inital error, unexpected type <int>")
assert_failure(func(): assert_object(1.3)) \
.is_failed() \
.has_message("GdUnitObjectAssert inital error, unexpected type <float>")
assert_failure(func(): assert_object(true)) \
.is_failed() \
.has_message("GdUnitObjectAssert inital error, unexpected type <bool>")
assert_failure(func(): assert_object("foo")) \
.is_failed() \
.has_message("GdUnitObjectAssert inital error, unexpected type <String>")
func test_override_failure_message() -> void:
assert_failure(func(): assert_object(auto_free(Node.new())) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_object(null).is_null()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_object(RefCounted.new()).is_null()) \
.is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_object(null).is_null()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()
# should abort here because we had an failing assert
if is_failure():
return
assert_bool(true).override_failure_message("This line shold never be called").is_false()

View file

@ -0,0 +1,338 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitArrayAssertImpl.gd'
@warning_ignore("unused_parameter")
func test_is_array_assert(_test :String, array, test_parameters = [
["Array", Array()],
["PackedByteArray", PackedByteArray()],
["PackedInt32Array", PackedInt32Array()],
["PackedInt64Array", PackedInt64Array()],
["PackedFloat32Array", PackedFloat32Array()],
["PackedFloat64Array", PackedFloat64Array()],
["PackedStringArray", PackedStringArray()],
["PackedVector2Array", PackedVector2Array()],
["PackedVector3Array", PackedVector3Array()],
["PackedColorArray", PackedColorArray()] ]
) -> void:
var assert_ = assert_that(array)
assert_object(assert_).is_instanceof(GdUnitArrayAssert)
@warning_ignore("unused_parameter")
func test_is_null(_test :String, value, test_parameters = [
["Array", Array()],
["PackedByteArray", PackedByteArray()],
["PackedInt32Array", PackedInt32Array()],
["PackedInt64Array", PackedInt64Array()],
["PackedFloat32Array", PackedFloat32Array()],
["PackedFloat64Array", PackedFloat64Array()],
["PackedStringArray", PackedStringArray()],
["PackedVector2Array", PackedVector2Array()],
["PackedVector3Array", PackedVector3Array()],
["PackedColorArray", PackedColorArray()] ]
) -> void:
assert_array(null).is_null()
assert_failure(func(): assert_array(value).is_null()) \
.is_failed() \
.has_message("Expecting: '<null>' but was '%s'" % GdDefaultValueDecoder.decode(value))
@warning_ignore("unused_parameter")
func test_is_not_null(_test :String, array, test_parameters = [
["Array", Array()],
["PackedByteArray", PackedByteArray()],
["PackedInt32Array", PackedInt32Array()],
["PackedInt64Array", PackedInt64Array()],
["PackedFloat32Array", PackedFloat32Array()],
["PackedFloat64Array", PackedFloat64Array()],
["PackedStringArray", PackedStringArray()],
["PackedVector2Array", PackedVector2Array()],
["PackedVector3Array", PackedVector3Array()],
["PackedColorArray", PackedColorArray()] ]
) -> void:
assert_array(array).is_not_null()
assert_failure(func(): assert_array(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
@warning_ignore("unused_parameter")
func test_is_equal(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
var other = array.duplicate()
assert_array(array).is_equal(other)
# should fail because the array not contains same elements and has diff size
other.append(array[2])
assert_failure(func(): assert_array(array).is_equal(other)) \
.is_failed() \
.has_message("""
Expecting:
'%s'
but was
'%s'
Differences found:
Index Current Expected 5 <N/A> $value """
.dedent()
.trim_prefix("\n")
.replace("$value", str(array[2]) ) % [GdArrayTools.as_string(other, false), GdArrayTools.as_string(array, false)])
@warning_ignore("unused_parameter")
func test_is_not_equal(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
var other = array.duplicate()
other.append(array[2])
assert_array(array).is_not_equal(other)
# should fail because the array contains same elements
assert_failure(func(): assert_array(array).is_not_equal(array.duplicate())) \
.is_failed() \
.has_message("""
Expecting:
'%s'
not equal to
'%s'"""
.dedent()
.trim_prefix("\n") % [GdDefaultValueDecoder.decode(array), GdDefaultValueDecoder.decode(array)])
@warning_ignore("unused_parameter")
func test_is_empty(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
var empty = array.duplicate()
empty.clear()
assert_array(empty).is_empty()
# should fail because the array is not empty
assert_failure(func(): assert_array(array).is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'%s'"""
.dedent()
.trim_prefix("\n") % GdDefaultValueDecoder.decode(array))
@warning_ignore("unused_parameter")
func test_is_not_empty(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
assert_array(array).is_not_empty()
# should fail because the array is empty
var empty = array.duplicate()
empty.clear()
assert_failure(func(): assert_array(empty).is_not_empty()) \
.is_failed() \
.has_message("Expecting:\n must not be empty")
@warning_ignore("unused_parameter")
func test_is_same(value, test_parameters = [
[[0]],
[PackedByteArray([0])],
[PackedFloat32Array([0.0])],
[PackedFloat64Array([0.0])],
[PackedInt32Array([0])],
[PackedInt64Array([0])],
[PackedStringArray([""])],
[PackedColorArray([Color.RED])],
[PackedVector2Array([Vector2.ZERO])],
[PackedVector3Array([Vector3.ZERO])],
]) -> void:
assert_array(value).is_same(value)
var v := GdDefaultValueDecoder.decode(value)
assert_failure(func(): assert_array(value).is_same(value.duplicate()))\
.is_failed()\
.has_message("""
Expecting:
'%s'
to refer to the same object
'%s'"""
.dedent()
.trim_prefix("\n") % [v, v])
@warning_ignore("unused_parameter")
func test_is_not_same(value, test_parameters = [
[[0]],
[PackedByteArray([0])],
[PackedFloat32Array([0.0])],
[PackedFloat64Array([0.0])],
[PackedInt32Array([0])],
[PackedInt64Array([0])],
[PackedStringArray([""])],
[PackedColorArray([Color.RED])],
[PackedVector2Array([Vector2.ZERO])],
[PackedVector3Array([Vector3.ZERO])],
]) -> void:
assert_array(value).is_not_same(value.duplicate())
assert_failure(func(): assert_array(value).is_not_same(value))\
.is_failed()\
.has_message("Expecting not same:\n '%s'" % GdDefaultValueDecoder.decode(value))
@warning_ignore("unused_parameter")
func test_has_size(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
assert_array(array).has_size(5)
# should fail because the array has a size of 5
assert_failure(func(): assert_array(array).has_size(4)) \
.is_failed() \
.has_message("""
Expecting size:
'4'
but was
'5'"""
.dedent()
.trim_prefix("\n"))
@warning_ignore("unused_parameter")
func test_contains(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
assert_array(array).contains([array[1], array[3], array[4]])
# should fail because the array not contains 7 and 6
var do_contains := [array[1], 7, 6]
assert_failure(func(): assert_array(array).contains(do_contains)) \
.is_failed() \
.has_message("""
Expecting contains elements:
'$source'
do contains (in any order)
'$contains'
but could not find elements:
'[7, 6]'"""
.dedent()
.trim_prefix("\n")
.replace("$source", GdDefaultValueDecoder.decode(array))
.replace("$contains", GdDefaultValueDecoder.decode(do_contains))
)
@warning_ignore("unused_parameter")
func test_contains_exactly(_test :String, array, test_parameters = [
["Array", Array([1, 2, 3, 4, 5])],
["PackedByteArray", PackedByteArray([1, 2, 3, 4, 5])],
["PackedInt32Array", PackedInt32Array([1, 2, 3, 4, 5])],
["PackedInt64Array", PackedInt64Array([1, 2, 3, 4, 5])],
["PackedFloat32Array", PackedFloat32Array([1, 2, 3, 4, 5])],
["PackedFloat64Array", PackedFloat64Array([1, 2, 3, 4, 5])],
["PackedStringArray", PackedStringArray([1, 2, 3, 4, 5])],
["PackedVector2Array", PackedVector2Array([Vector2.ZERO, Vector2.LEFT, Vector2.RIGHT, Vector2.UP, Vector2.DOWN])],
["PackedVector3Array", PackedVector3Array([Vector3.ZERO, Vector3.LEFT, Vector3.RIGHT, Vector3.UP, Vector3.DOWN])],
["PackedColorArray", PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.BLACK])] ]
) -> void:
assert_array(array).contains_exactly(array.duplicate())
# should fail because the array not contains same elements but in different order
var shuffled = array.duplicate()
shuffled[1] = array[3]
shuffled[3] = array[1]
assert_failure(func(): assert_array(array).contains_exactly(shuffled)) \
.is_failed() \
.has_message("""
Expecting contains exactly elements:
'$source'
do contains (in same order)
'$contains'
but has different order at position '1'
'$A' vs '$B'"""
.dedent()
.trim_prefix("\n")
.replace("$A", GdDefaultValueDecoder.decode(array[1]))
.replace("$B", GdDefaultValueDecoder.decode(array[3]))
.replace("$source", GdDefaultValueDecoder.decode(array))
.replace("$contains", GdDefaultValueDecoder.decode(shuffled))
)
@warning_ignore("unused_parameter")
func test_override_failure_message(_test :String, array, test_parameters = [
["Array", Array()],
["PackedByteArray", PackedByteArray()],
["PackedInt32Array", PackedInt32Array()],
["PackedInt64Array", PackedInt64Array()],
["PackedFloat32Array", PackedFloat32Array()],
["PackedFloat64Array", PackedFloat64Array()],
["PackedStringArray", PackedStringArray()],
["PackedVector2Array", PackedVector2Array()],
["PackedVector3Array", PackedVector3Array()],
["PackedColorArray", PackedColorArray()] ]
) -> void:
assert_failure(func(): assert_array(array) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")

View file

@ -0,0 +1,143 @@
# GdUnit generated TestSuite
class_name GdUnitResultAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitResultAssertImpl.gd'
func test_is_null():
assert_result(null).is_null()
assert_failure(func(): assert_result(GdUnitResult.success("")).is_null()) \
.is_failed() \
.has_message('Expecting: \'<null>\' but was <{ "state": 0, "value": "\\"\\"", "warn_msg": "", "err_msg": "" }>')
func test_is_not_null():
assert_result(GdUnitResult.success("")).is_not_null()
assert_failure(func(): assert_result(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_empty():
assert_result(GdUnitResult.empty()).is_empty()
assert_failure(func(): assert_result(GdUnitResult.warn("a warning")).is_empty()) \
.is_failed() \
.has_message("Expecting the result must be a EMPTY but was WARNING:\n 'a warning'")
assert_failure(func(): assert_result(GdUnitResult.error("a error")).is_empty()) \
.is_failed() \
.has_message("Expecting the result must be a EMPTY but was ERROR:\n 'a error'")
assert_failure(func(): assert_result(null).is_empty()) \
.is_failed() \
.has_message("Expecting the result must be a EMPTY but was <null>.")
func test_is_success():
assert_result(GdUnitResult.success("")).is_success()
assert_failure(func(): assert_result(GdUnitResult.warn("a warning")).is_success()) \
.is_failed() \
.has_message("Expecting the result must be a SUCCESS but was WARNING:\n 'a warning'")
assert_failure(func(): assert_result(GdUnitResult.error("a error")).is_success()) \
.is_failed() \
.has_message("Expecting the result must be a SUCCESS but was ERROR:\n 'a error'")
assert_failure(func(): assert_result(null).is_success()) \
.is_failed() \
.has_message("Expecting the result must be a SUCCESS but was <null>.")
func test_is_warning():
assert_result(GdUnitResult.warn("a warning")).is_warning()
assert_failure(func(): assert_result(GdUnitResult.success("value")).is_warning()) \
.is_failed() \
.has_message("Expecting the result must be a WARNING but was SUCCESS.")
assert_failure(func(): assert_result(GdUnitResult.error("a error")).is_warning()) \
.is_failed() \
.has_message("Expecting the result must be a WARNING but was ERROR:\n 'a error'")
assert_failure(func(): assert_result(null).is_warning()) \
.is_failed() \
.has_message("Expecting the result must be a WARNING but was <null>.")
func test_is_error():
assert_result(GdUnitResult.error("a error")).is_error()
assert_failure(func(): assert_result(GdUnitResult.success("")).is_error()) \
.is_failed() \
.has_message("Expecting the result must be a ERROR but was SUCCESS.")
assert_failure(func(): assert_result(GdUnitResult.warn("a warning")).is_error()) \
.is_failed() \
.has_message("Expecting the result must be a ERROR but was WARNING:\n 'a warning'")
assert_failure(func(): assert_result(null).is_error()) \
.is_failed() \
.has_message("Expecting the result must be a ERROR but was <null>.")
func test_contains_message():
assert_result(GdUnitResult.error("a error")).contains_message("a error")
assert_result(GdUnitResult.warn("a warning")).contains_message("a warning")
assert_failure(func(): assert_result(GdUnitResult.success("")).contains_message("Error 500")) \
.is_failed() \
.has_message("Expecting:\n 'Error 500'\n but the GdUnitResult is a success.")
assert_failure(func(): assert_result(GdUnitResult.warn("Warning xyz!")).contains_message("Warning aaa!")) \
.is_failed() \
.has_message("Expecting:\n 'Warning aaa!'\n but was\n 'Warning xyz!'.")
assert_failure(func(): assert_result(GdUnitResult.error("Error 410")).contains_message("Error 500")) \
.is_failed() \
.has_message("Expecting:\n 'Error 500'\n but was\n 'Error 410'.")
assert_failure(func(): assert_result(null).contains_message("Error 500")) \
.is_failed() \
.has_message("Expecting:\n 'Error 500'\n but was\n '<null>'.")
func test_is_value():
assert_result(GdUnitResult.success("")).is_value("")
var result_value = auto_free(Node.new())
assert_result(GdUnitResult.success(result_value)).is_value(result_value)
assert_failure(func(): assert_result(GdUnitResult.success("")).is_value("abc")) \
.is_failed() \
.has_message("Expecting to contain same value:\n 'abc'\n but was\n '<empty>'.")
assert_failure(func(): assert_result(GdUnitResult.success("abc")).is_value("")) \
.is_failed() \
.has_message("Expecting to contain same value:\n '<empty>'\n but was\n 'abc'.")
assert_failure(func(): assert_result(GdUnitResult.success(result_value)).is_value("")) \
.is_failed() \
.has_message("Expecting to contain same value:\n '<empty>'\n but was\n <Node>.")
assert_failure(func(): assert_result(null).is_value("")) \
.is_failed() \
.has_message("Expecting to contain same value:\n '<empty>'\n but was\n '<null>'.")
func test_override_failure_message() -> void:
assert_failure(func(): assert_result(GdUnitResult.success("")) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_result(null).is_null()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_result(RefCounted.new()).is_null()).is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_result(null).is_null()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()

View file

@ -0,0 +1,228 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdUnitSignalAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitSignalAssertImpl.gd'
const GdUnitTools = preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
class TestEmitter extends Node:
signal test_signal_counted(value)
signal test_signal(value :int)
signal test_signal_unused()
var _trigger_count :int
var _count := 0
func _init(trigger_count := 10):
_trigger_count = trigger_count
func _process(_delta):
if _count >= _trigger_count:
test_signal_counted.emit(_count)
if _count == 20:
test_signal.emit(10)
test_signal.emit(20)
_count += 1
func reset_trigger(trigger_count := 10) -> void:
_trigger_count = trigger_count
var signal_emitter :TestEmitter
func before_test():
signal_emitter = auto_free(TestEmitter.new())
add_child(signal_emitter)
# we need to skip await fail test because of an bug in Godot 4.0 stable
func is_skip_fail_await() -> bool:
return Engine.get_version_info().hex < 0x40002
func test_invalid_arg() -> void:
(
await assert_failure_await(func(): await assert_signal(null).wait_until(50).is_emitted("test_signal_counted"))
).has_message("Can't wait for signal checked a NULL object.")
(
await assert_failure_await(func(): await assert_signal(null).wait_until(50).is_not_emitted("test_signal_counted"))
).has_message("Can't wait for signal checked a NULL object.")
func test_unknown_signal() -> void:
(
await assert_failure_await(func(): await assert_signal(signal_emitter).wait_until(50).is_emitted("unknown"))
).has_message("Can't wait for non-existion signal 'unknown' checked object 'Node'.")
func test_signal_is_emitted_without_args() -> void:
# wait until signal 'test_signal_counted' without args
await assert_signal(signal_emitter).is_emitted("test_signal", [10])
await assert_signal(signal_emitter).is_emitted("test_signal", [20])
# wait until signal 'test_signal_unused' where is never emitted
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_signal(signal_emitter).wait_until(500).is_emitted("test_signal_unused"))
).has_message("Expecting emit signal: 'test_signal_unused()' but timed out after 500ms")
func test_signal_is_emitted_with_args() -> void:
# wait until signal 'test_signal_counted' is emitted with value 20
await assert_signal(signal_emitter).is_emitted("test_signal_counted", [20])
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_signal(signal_emitter).wait_until(50).is_emitted("test_signal_counted", [500]))
).has_message("Expecting emit signal: 'test_signal_counted([500])' but timed out after 50ms")
func test_signal_is_emitted_use_argument_matcher() -> void:
# wait until signal 'test_signal_counted' is emitted by using any_int() matcher for signal arguments
await assert_signal(signal_emitter).is_emitted("test_signal_counted", [any_int()])
# should also work with any() matcher
signal_emitter.reset_trigger()
await assert_signal(signal_emitter).is_emitted("test_signal_counted", [any()])
# should fail because the matcher uses the wrong type
signal_emitter.reset_trigger()
(
await assert_failure_await( func(): await assert_signal(signal_emitter).wait_until(50).is_emitted("test_signal_counted", [any_string()]))
).has_message("Expecting emit signal: 'test_signal_counted([any_string()])' but timed out after 50ms")
func test_signal_is_not_emitted() -> void:
# wait to verify signal 'test_signal_counted()' is not emitted until the first 50ms
await assert_signal(signal_emitter).wait_until(50).is_not_emitted("test_signal_counted")
# wait to verify signal 'test_signal_counted(50)' is not emitted until the NEXT first 80ms
await assert_signal(signal_emitter).wait_until(30).is_not_emitted("test_signal_counted", [50])
if is_skip_fail_await():
return
# until the next 500ms the signal is emitted and ends in a failure
(
await assert_failure_await(func(): await assert_signal(signal_emitter).wait_until(1000).is_not_emitted("test_signal_counted", [50]))
).starts_with_message("Expecting do not emit signal: 'test_signal_counted([50])' but is emitted after")
func test_override_failure_message() -> void:
if is_skip_fail_await():
return
(
await assert_failure_await(func(): await assert_signal(signal_emitter) \
.override_failure_message("Custom failure message")\
.wait_until(100)\
.is_emitted("test_signal_unused"))
).has_message("Custom failure message")
func test_node_changed_emitting_signals():
var node :Node2D = auto_free(Node2D.new())
add_child(node)
await assert_signal(node).wait_until(200).is_emitted("draw")
node.visible = false;
await assert_signal(node).wait_until(200).is_emitted("visibility_changed")
# expecting to fail, we not changed the visibility
#node.visible = true;
if not is_skip_fail_await():
(
await assert_failure_await(func(): await assert_signal(node).wait_until(200).is_emitted("visibility_changed"))
).has_message("Expecting emit signal: 'visibility_changed()' but timed out after 200ms")
node.show()
await assert_signal(node).wait_until(200).is_emitted("draw")
func test_is_signal_exists() -> void:
var node :Node2D = auto_free(Node2D.new())
assert_signal(node).is_signal_exists("visibility_changed")\
.is_signal_exists("draw")\
.is_signal_exists("visibility_changed")\
.is_signal_exists("tree_entered")\
.is_signal_exists("tree_exiting")\
.is_signal_exists("tree_exited")
if is_skip_fail_await():
return
(
await assert_failure_await(func(): assert_signal(node).is_signal_exists("not_existing_signal"))
).has_message("The signal 'not_existing_signal' not exists checked object 'Node2D'.")
class MyEmitter extends Node:
signal my_signal_a
signal my_signal_b(value :String)
func do_emit_a() -> void:
my_signal_a.emit()
func do_emit_b() -> void:
my_signal_b.emit("foo")
func test_monitor_signals() -> void:
# start to watch on the emitter to collect all emitted signals
var emitter_a := monitor_signals(MyEmitter.new())
var emitter_b := monitor_signals(MyEmitter.new())
# verify the signals are not emitted initial
await assert_signal(emitter_a).wait_until(50).is_not_emitted('my_signal_a')
await assert_signal(emitter_a).wait_until(50).is_not_emitted('my_signal_b')
await assert_signal(emitter_b).wait_until(50).is_not_emitted('my_signal_a')
await assert_signal(emitter_b).wait_until(50).is_not_emitted('my_signal_b')
# emit signal `my_signal_a` on emitter_a
emitter_a.do_emit_a()
await assert_signal(emitter_a).is_emitted('my_signal_a')
# emit signal `my_signal_b` on emitter_a
emitter_a.do_emit_b()
await assert_signal(emitter_a).is_emitted('my_signal_b', ["foo"])
# verify emitter_b still has nothing emitted
await assert_signal(emitter_b).wait_until(50).is_not_emitted('my_signal_a')
await assert_signal(emitter_b).wait_until(50).is_not_emitted('my_signal_b')
# now verify emitter b
emitter_b.do_emit_a()
await assert_signal(emitter_b).wait_until(50).is_emitted('my_signal_a')
class ExampleResource extends Resource:
@export var title := "Title":
set(new_value):
title = new_value
changed.emit()
func change_title(p_title: String) -> void:
title = p_title
func test_monitor_signals_on_resource_set() -> void:
var sut = ExampleResource.new()
var emitter := monitor_signals(sut)
sut.change_title("Some title")
# title change should emit "changed" signal
await assert_signal(emitter).is_emitted("changed")
assert_str(sut.title).is_equal("Some title")

View file

@ -0,0 +1,450 @@
# GdUnit generated TestSuite
class_name GdUnitStringAssertImplTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitStringAssertImpl.gd'
func test_is_null():
assert_str(null).is_null()
assert_failure(func(): assert_str("abc").is_null()) \
.is_failed() \
.starts_with_message("Expecting: '<null>' but was 'abc'")
func test_is_not_null():
assert_str("abc").is_not_null()
assert_str(&"abc").is_not_null()
assert_failure(func(): assert_str(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
func test_is_equal():
assert_str("This is a test message").is_equal("This is a test message")
assert_str("abc").is_equal("abc")
assert_str("abc").is_equal(&"abc")
assert_str(&"abc").is_equal("abc")
assert_str(&"abc").is_equal(&"abc")
assert_failure(func(): assert_str("This is a test message").is_equal("This is a test Message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test Message'
but was
'This is a test Mmessage'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).is_equal("This is a test Message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test Message'
but was
'<null>'""".dedent().trim_prefix("\n"))
func test_is_equal_pipe_character() -> void:
assert_failure(func(): assert_str("AAA|BBB|CCC").is_equal("AAA|BBB.CCC")) \
.is_failed()
func test_is_equal_ignoring_case():
assert_str("This is a test message").is_equal_ignoring_case("This is a test Message")
assert_str("This is a test message").is_equal_ignoring_case(&"This is a test Message")
assert_str(&"This is a test message").is_equal_ignoring_case("This is a test Message")
assert_str(&"This is a test message").is_equal_ignoring_case(&"This is a test Message")
assert_failure(func(): assert_str("This is a test message").is_equal_ignoring_case("This is a Message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a Message'
but was
'This is a test Mmessage' (ignoring case)""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).is_equal_ignoring_case("This is a Message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a Message'
but was
'<null>' (ignoring case)""".dedent().trim_prefix("\n"))
func test_is_not_equal():
assert_str(null).is_not_equal("This is a test Message")
assert_str("This is a test message").is_not_equal("This is a test Message")
assert_str("This is a test message").is_not_equal(&"This is a test Message")
assert_str(&"This is a test message").is_not_equal("This is a test Message")
assert_str(&"This is a test message").is_not_equal(&"This is a test Message")
assert_failure(func(): assert_str("This is a test message").is_not_equal("This is a test message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
not equal to
'This is a test message'""".dedent().trim_prefix("\n"))
func test_is_not_equal_ignoring_case():
assert_str(null).is_not_equal_ignoring_case("This is a Message")
assert_str("This is a test message").is_not_equal_ignoring_case("This is a Message")
assert_str("This is a test message").is_not_equal_ignoring_case(&"This is a Message")
assert_str(&"This is a test message").is_not_equal_ignoring_case("This is a Message")
assert_str(&"This is a test message").is_not_equal_ignoring_case(&"This is a Message")
assert_failure(func(): assert_str("This is a test message").is_not_equal_ignoring_case("This is a test Message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test Message'
not equal to
'This is a test message'""".dedent().trim_prefix("\n"))
func test_is_empty():
assert_str("").is_empty()
assert_str(&"").is_empty()
assert_failure(func(): assert_str(" ").is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
' '""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str("abc").is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'abc'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(&"abc").is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'abc'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).is_empty()) \
.is_failed() \
.has_message("""
Expecting:
must be empty but was
'<null>'""".dedent().trim_prefix("\n"))
func test_is_not_empty():
assert_str(" ").is_not_empty()
assert_str(" ").is_not_empty()
assert_str("abc").is_not_empty()
assert_str(&"abc").is_not_empty()
assert_failure(func(): assert_str("").is_not_empty()) \
.is_failed() \
.has_message("""
Expecting:
must not be empty""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).is_not_empty()) \
.is_failed() \
.has_message("""
Expecting:
must not be empty""".dedent().trim_prefix("\n"))
func test_contains():
assert_str("This is a test message").contains("a test")
assert_str("This is a test message").contains(&"a test")
assert_str(&"This is a test message").contains("a test")
assert_str(&"This is a test message").contains(&"a test")
# must fail because of camel case difference
assert_failure(func(): assert_str("This is a test message").contains("a Test")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
do contains
'a Test'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).contains("a Test")) \
.is_failed() \
.has_message("""
Expecting:
'<null>'
do contains
'a Test'""".dedent().trim_prefix("\n"))
func test_not_contains():
assert_str(null).not_contains("a tezt")
assert_str("This is a test message").not_contains("a tezt")
assert_str("This is a test message").not_contains(&"a tezt")
assert_str(&"This is a test message").not_contains("a tezt")
assert_str(&"This is a test message").not_contains(&"a tezt")
assert_failure(func(): assert_str("This is a test message").not_contains("a test")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
not do contain
'a test'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(&"This is a test message").not_contains("a test")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
not do contain
'a test'""".dedent().trim_prefix("\n"))
func test_contains_ignoring_case():
assert_str("This is a test message").contains_ignoring_case("a Test")
assert_str("This is a test message").contains_ignoring_case(&"a Test")
assert_str(&"This is a test message").contains_ignoring_case("a Test")
assert_str(&"This is a test message").contains_ignoring_case(&"a Test")
assert_failure(func(): assert_str("This is a test message").contains_ignoring_case("a Tesd")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
contains
'a Tesd'
(ignoring case)""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).contains_ignoring_case("a Tesd")) \
.is_failed() \
.has_message("""
Expecting:
'<null>'
contains
'a Tesd'
(ignoring case)""".dedent().trim_prefix("\n"))
func test_not_contains_ignoring_case():
assert_str(null).not_contains_ignoring_case("a Test")
assert_str("This is a test message").not_contains_ignoring_case("a Tezt")
assert_str("This is a test message").not_contains_ignoring_case(&"a Tezt")
assert_str(&"This is a test message").not_contains_ignoring_case("a Tezt")
assert_str(&"This is a test message").not_contains_ignoring_case(&"a Tezt")
assert_failure(func(): assert_str("This is a test message").not_contains_ignoring_case("a Test")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
not do contains
'a Test'
(ignoring case)""".dedent().trim_prefix("\n"))
func test_starts_with():
assert_str("This is a test message").starts_with("This is")
assert_str("This is a test message").starts_with(&"This is")
assert_str(&"This is a test message").starts_with("This is")
assert_str(&"This is a test message").starts_with(&"This is")
assert_failure(func(): assert_str("This is a test message").starts_with("This iss")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
to start with
'This iss'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str("This is a test message").starts_with("this is")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
to start with
'this is'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str("This is a test message").starts_with("test")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
to start with
'test'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).starts_with("test")) \
.is_failed() \
.has_message("""
Expecting:
'<null>'
to start with
'test'""".dedent().trim_prefix("\n"))
func test_ends_with():
assert_str("This is a test message").ends_with("test message")
assert_str("This is a test message").ends_with(&"test message")
assert_str(&"This is a test message").ends_with("test message")
assert_str(&"This is a test message").ends_with(&"test message")
assert_failure(func(): assert_str("This is a test message").ends_with("tes message")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
to end with
'tes message'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str("This is a test message").ends_with("a test")) \
.is_failed() \
.has_message("""
Expecting:
'This is a test message'
to end with
'a test'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).ends_with("a test")) \
.is_failed() \
.has_message("""
Expecting:
'<null>'
to end with
'a test'""".dedent().trim_prefix("\n"))
func test_has_lenght():
assert_str("This is a test message").has_length(22)
assert_str(&"This is a test message").has_length(22)
assert_str("").has_length(0)
assert_str(&"").has_length(0)
assert_failure(func(): assert_str("This is a test message").has_length(23)) \
.is_failed() \
.has_message("""
Expecting size:
'23' but was '22' in
'This is a test message'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).has_length(23)) \
.is_failed() \
.has_message("""
Expecting size:
'23' but was '<null>' in
'<null>'""".dedent().trim_prefix("\n"))
func test_has_lenght_less_than():
assert_str("This is a test message").has_length(23, Comparator.LESS_THAN)
assert_str("This is a test message").has_length(42, Comparator.LESS_THAN)
assert_str(&"This is a test message").has_length(42, Comparator.LESS_THAN)
assert_failure(func(): assert_str("This is a test message").has_length(22, Comparator.LESS_THAN)) \
.is_failed() \
.has_message("""
Expecting size to be less than:
'22' but was '22' in
'This is a test message'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).has_length(22, Comparator.LESS_THAN)) \
.is_failed() \
.has_message("""
Expecting size to be less than:
'22' but was '<null>' in
'<null>'""".dedent().trim_prefix("\n"))
func test_has_lenght_less_equal():
assert_str("This is a test message").has_length(22, Comparator.LESS_EQUAL)
assert_str("This is a test message").has_length(23, Comparator.LESS_EQUAL)
assert_str(&"This is a test message").has_length(23, Comparator.LESS_EQUAL)
assert_failure(func(): assert_str("This is a test message").has_length(21, Comparator.LESS_EQUAL)) \
.is_failed() \
.has_message("""
Expecting size to be less than or equal:
'21' but was '22' in
'This is a test message'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).has_length(21, Comparator.LESS_EQUAL)) \
.is_failed() \
.has_message("""
Expecting size to be less than or equal:
'21' but was '<null>' in
'<null>'""".dedent().trim_prefix("\n"))
func test_has_lenght_greater_than():
assert_str("This is a test message").has_length(21, Comparator.GREATER_THAN)
assert_str(&"This is a test message").has_length(21, Comparator.GREATER_THAN)
assert_failure(func(): assert_str("This is a test message").has_length(22, Comparator.GREATER_THAN)) \
.is_failed() \
.has_message("""
Expecting size to be greater than:
'22' but was '22' in
'This is a test message'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).has_length(22, Comparator.GREATER_THAN)) \
.is_failed() \
.has_message("""
Expecting size to be greater than:
'22' but was '<null>' in
'<null>'""".dedent().trim_prefix("\n"))
func test_has_lenght_greater_equal():
assert_str("This is a test message").has_length(21, Comparator.GREATER_EQUAL)
assert_str("This is a test message").has_length(22, Comparator.GREATER_EQUAL)
assert_str(&"This is a test message").has_length(22, Comparator.GREATER_EQUAL)
assert_failure(func(): assert_str("This is a test message").has_length(23, Comparator.GREATER_EQUAL)) \
.is_failed() \
.has_message("""
Expecting size to be greater than or equal:
'23' but was '22' in
'This is a test message'""".dedent().trim_prefix("\n"))
assert_failure(func(): assert_str(null).has_length(23, Comparator.GREATER_EQUAL)) \
.is_failed() \
.has_message("""
Expecting size to be greater than or equal:
'23' but was '<null>' in
'<null>'""".dedent().trim_prefix("\n"))
func test_fluentable():
assert_str("value a").is_not_equal("a")\
.is_equal("value a")\
.has_length(7)\
.is_equal("value a")
func test_must_fail_has_invlalid_type():
assert_failure(func(): assert_str(1)) \
.is_failed() \
.has_message("GdUnitStringAssert inital error, unexpected type <int>")
assert_failure(func(): assert_str(1.3)) \
.is_failed() \
.has_message("GdUnitStringAssert inital error, unexpected type <float>")
assert_failure(func(): assert_str(true)) \
.is_failed() \
.has_message("GdUnitStringAssert inital error, unexpected type <bool>")
assert_failure(func(): assert_str(Resource.new())) \
.is_failed() \
.has_message("GdUnitStringAssert inital error, unexpected type <Object>")
func test_override_failure_message() -> void:
assert_failure(func(): assert_str("")\
.override_failure_message("Custom failure message")\
.is_null())\
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_str(null).is_null()
assert_bool(is_failure()).is_false()
# checked failed assert
assert_failure(func(): assert_str(RefCounted.new()).is_null()) \
.is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_str(null).is_null()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()

View file

@ -0,0 +1,367 @@
# GdUnit generated TestSuite
class_name GdUnitVectorAssertImplTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/asserts/GdUnitVectorAssertImpl.gd'
var _test_seta =[
[null],
[Vector2.ONE],
[Vector2i.ONE],
[Vector3.ONE],
[Vector3i.ONE],
[Vector4.ONE],
[Vector4i.ONE],
]
@warning_ignore("unused_parameter")
func test_supported_types(value, test_parameters = _test_seta):
assert_object(assert_vector(value))\
.is_not_null()\
.is_instanceof(GdUnitVectorAssert)
@warning_ignore("unused_parameter")
func test_unsupported_types(value, details :String, test_parameters =[
[true, 'bool'],
[42, 'int'],
[42.0, 'float'],
['foo', 'String'],
] ):
assert_failure(func(): assert_vector(value))\
.is_failed()\
.has_message("GdUnitVectorAssert error, the type <%s> is not supported." % details)
@warning_ignore("unused_parameter")
func test_is_null(value, test_parameters = _test_seta):
if value == null:
assert_vector(null).is_null()
else:
assert_failure(func(): assert_vector(value).is_null()) \
.is_failed() \
.starts_with_message("Expecting: '<null>' but was '%s'" % value)
@warning_ignore("unused_parameter")
func test_is_not_null(value, test_parameters = _test_seta):
if value == null:
assert_failure(func(): assert_vector(null).is_not_null()) \
.is_failed() \
.has_message("Expecting: not to be '<null>'")
else:
assert_vector(value).is_not_null()
@warning_ignore("unused_parameter")
func test_is_equal() -> void:
assert_vector(Vector2.ONE).is_equal(Vector2.ONE)
assert_vector(Vector2.LEFT).is_equal(Vector2.LEFT)
assert_vector(Vector2(1.2, 1.000001)).is_equal(Vector2(1.2, 1.000001))
# is not equal
assert_failure(func(): assert_vector(Vector2.ONE).is_equal(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting:\n '(1.2, 1.000001)'\n but was\n '(1, 1)'")
# is null
assert_failure(func(): assert_vector(null).is_equal(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting:\n '(1.2, 1.000001)'\n but was\n '<null>'")
# comparing different vector types
assert_failure(func(): assert_vector(Vector2.ONE).is_equal(Vector3.ONE)) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_equal_over_all_types(value, test_parameters = _test_seta) -> void:
assert_vector(value).is_equal(value)
func test_is_not_equal() -> void:
assert_vector(null).is_not_equal(Vector2.LEFT)
assert_vector(Vector2.ONE).is_not_equal(Vector2.LEFT)
assert_vector(Vector2.LEFT).is_not_equal(Vector2.ONE)
assert_vector(Vector2(1.2, 1.000001)).is_not_equal(Vector2(1.2, 1.000002))
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_not_equal(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting:\n '(1.2, 1.000001)'\n not equal to\n '(1.2, 1.000001)'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_not_equal(Vector3(1.2, 1.000001, 1.0))) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_not_equal_over_all_types(value, test_parameters = _test_seta) -> void:
var expected = Vector2.LEFT if value == null else value * 2
assert_vector(value).is_not_equal(expected)
func test_is_equal_approx() -> void:
assert_vector(Vector2.ONE).is_equal_approx(Vector2.ONE, Vector2(0.004, 0.004))
assert_vector(Vector2(0.996, 0.996)).is_equal_approx(Vector2.ONE, Vector2(0.004, 0.004))
assert_vector(Vector2(1.004, 1.004)).is_equal_approx(Vector2.ONE, Vector2(0.004, 0.004))
assert_failure(func(): assert_vector(Vector2(1.005, 1)).is_equal_approx(Vector2.ONE, Vector2(0.004, 0.004))) \
.is_failed() \
.has_message("Expecting:\n '(1.005, 1)'\n in range between\n '(0.996, 0.996)' <> '(1.004, 1.004)'")
assert_failure(func(): assert_vector(Vector2(1, 0.995)).is_equal_approx(Vector2.ONE, Vector2(0, 0.004))) \
.is_failed() \
.has_message("Expecting:\n '(1, 0.995)'\n in range between\n '(1, 0.996)' <> '(1, 1.004)'")
assert_failure(func(): assert_vector(null).is_equal_approx(Vector2.ONE, Vector2(0, 0.004))) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n in range between\n '(1, 0.996)' <> '(1, 1.004)'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_equal_approx(Vector3.ONE, Vector3(1.2, 1.000001, 1.0))) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
assert_failure(func(): assert_vector(Vector2(0.878431, 0.505882)).is_equal_approx(Vector2(0.878431, 0.105882), Vector2(0.000001, 0.000001))) \
.is_failed() \
.has_message("""
Expecting:
'(0.878431, 0.505882)'
in range between
'(0.87843, 0.105881)' <> '(0.878432, 0.105883)'"""
.dedent().trim_prefix("\n")
)
assert_failure(func(): assert_vector(Vector3(0.0, 0.878431, 0.505882)).is_equal_approx(Vector3(0.0, 0.878431, 0.105882), Vector3(0.000001, 0.000001, 0.000001))) \
.is_failed() \
.has_message("""
Expecting:
'(0, 0.878431, 0.505882)'
in range between
'(-0.000001, 0.87843, 0.105881)' <> '(0.000001, 0.878432, 0.105883)'"""
.dedent().trim_prefix("\n")
)
@warning_ignore("unused_parameter")
func test_is_equal_approx_over_all_types(value, expected, approx, test_parameters = [
[Vector2(0.996, 1.004), Vector2.ONE, Vector2(0.004, 0.004)],
[Vector2i(9, 11), Vector2i(10, 10), Vector2i(1, 1)],
[Vector3(0.996, 0.996, 1.004), Vector3.ONE, Vector3(0.004, 0.004, 0.004)],
[Vector3i(10, 9, 11), Vector3i(10, 10, 10), Vector3i(1, 1, 1)],
[Vector4(0.996, 0.996, 1.004, 1.004), Vector4.ONE, Vector4(0.004, 0.004, 0.004, 0.004)],
[Vector4i(10, 9, 11, 9), Vector4i(10, 10, 10, 10), Vector4i(1, 1, 1, 1)]
]) -> void:
assert_vector(value).is_equal_approx(expected, approx)
func test_is_less() -> void:
assert_vector(Vector2.LEFT).is_less(Vector2.ONE)
assert_vector(Vector2(1.2, 1.000001)).is_less(Vector2(1.2, 1.000002))
assert_failure(func(): assert_vector(Vector2.ONE).is_less(Vector2.ONE)) \
.is_failed() \
.has_message("Expecting to be less than:\n '(1, 1)' but was '(1, 1)'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_less(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting to be less than:\n '(1.2, 1.000001)' but was '(1.2, 1.000001)'")
assert_failure(func(): assert_vector(null).is_less(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting to be less than:\n '(1.2, 1.000001)' but was '<null>'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_less(Vector3(1.2, 1.000001, 1.0))) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_less_over_all_types(value, expected, test_parameters = [
[Vector2(1.0, 1.0), Vector2(1.0001, 1.0001)],
[Vector2i(1, 1), Vector2i(2, 1)],
[Vector3(1.0, 1.0, 1.0), Vector3(1.0001, 1.0001, 1.0)],
[Vector3i(1, 1, 1), Vector3i(2, 1, 1)],
[Vector4(1.0, 1.0, 1.0, 1.0), Vector4(1.0001, 1.0001, 1.0, 1.0)],
[Vector4i(1, 1, 1, 1), Vector4i(2, 1, 1, 1)],
]) -> void:
assert_vector(value).is_less(expected)
func test_is_less_equal() -> void:
assert_vector(Vector2.ONE).is_less_equal(Vector2.ONE)
assert_vector(Vector2(1.2, 1.000001)).is_less_equal(Vector2(1.2, 1.000001))
assert_vector(Vector2(1.2, 1.000001)).is_less_equal(Vector2(1.2, 1.000002))
assert_failure(func(): assert_vector(Vector2.ONE).is_less_equal(Vector2.ZERO)) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '(0, 0)' but was '(1, 1)'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000002)).is_less_equal(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '(1.2, 1.000001)' but was '(1.2, 1.000002)'")
assert_failure(func(): assert_vector(null).is_less_equal(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting to be less than or equal:\n '(1.2, 1.000001)' but was '<null>'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000002)).is_less_equal(Vector3(1.2, 1.000001, 1.0))) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_less_equal_over_all_types(value, expected, test_parameters = [
[Vector2(1.0, 1.0), Vector2(1.0001, 1.0001)],
[Vector2(1.0, 1.0), Vector2(1.0, 1.0)],
[Vector2i(1, 1), Vector2i(2, 1)],
[Vector2i(1, 1), Vector2i(1, 1)],
[Vector3(1.0, 1.0, 1.0), Vector3(1.0001, 1.0001, 1.0)],
[Vector3(1.0, 1.0, 1.0), Vector3(1.0, 1.0, 1.0)],
[Vector3i(1, 1, 1), Vector3i(2, 1, 1)],
[Vector3i(1, 1, 1), Vector3i(1, 1, 1)],
[Vector4(1.0, 1.0, 1.0, 1.0), Vector4(1.0001, 1.0001, 1.0, 1.0)],
[Vector4(1.0, 1.0, 1.0, 1.0), Vector4(1.0, 1.0, 1.0, 1.0)],
[Vector4i(1, 1, 1, 1), Vector4i(2, 1, 1, 1)],
[Vector4i(1, 1, 1, 1), Vector4i(1, 1, 1, 1)],
]) -> void:
assert_vector(value).is_less_equal(expected)
func test_is_greater() -> void:
assert_vector(Vector2.ONE).is_greater(Vector2.RIGHT)
assert_vector(Vector2(1.2, 1.000002)).is_greater(Vector2(1.2, 1.000001))
assert_failure(func(): assert_vector(Vector2.ZERO).is_greater(Vector2.ONE)) \
.is_failed() \
.has_message("Expecting to be greater than:\n '(1, 1)' but was '(0, 0)'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_greater(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting to be greater than:\n '(1.2, 1.000001)' but was '(1.2, 1.000001)'")
assert_failure(func(): assert_vector(null).is_greater(Vector2(1.2, 1.000001))) \
.is_failed() \
.has_message("Expecting to be greater than:\n '(1.2, 1.000001)' but was '<null>'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000001)).is_greater(Vector3(1.2, 1.000001, 1.0))) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_greater_over_all_types(value, expected, test_parameters = [
[Vector2(1.0001, 1.0001), Vector2(1.0, 1.0)],
[Vector2i(2, 1), Vector2i(1, 1)],
[Vector3(1.0001, 1.0001, 1.0), Vector3(1.0, 1.0, 1.0)],
[Vector3i(2, 1, 1), Vector3i(1, 1, 1)],
[Vector4(1.0001, 1.0001, 1.0, 1.0), Vector4(1.0, 1.0, 1.0, 1.0)],
[Vector4i(2, 1, 1, 1), Vector4i(1, 1, 1, 1)],
]) -> void:
assert_vector(value).is_greater(expected)
func test_is_greater_equal() -> void:
assert_vector(Vector2.ONE*2).is_greater_equal(Vector2.ONE)
assert_vector(Vector2.ONE).is_greater_equal(Vector2.ONE)
assert_vector(Vector2(1.2, 1.000001)).is_greater_equal(Vector2(1.2, 1.000001))
assert_vector(Vector2(1.2, 1.000002)).is_greater_equal(Vector2(1.2, 1.000001))
assert_failure(func(): assert_vector(Vector2.ZERO).is_greater_equal(Vector2.ONE)) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '(1, 1)' but was '(0, 0)'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000002)).is_greater_equal(Vector2(1.2, 1.000003))) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '(1.2, 1.000003)' but was '(1.2, 1.000002)'")
assert_failure(func(): assert_vector(null).is_greater_equal(Vector2(1.2, 1.000003))) \
.is_failed() \
.has_message("Expecting to be greater than or equal:\n '(1.2, 1.000003)' but was '<null>'")
assert_failure(func(): assert_vector(Vector2(1.2, 1.000002)).is_greater_equal(Vector3(1.2, 1.000003, 1.0))) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_greater_equal_over_all_types(value, expected, test_parameters = [
[Vector2(1.0001, 1.0001), Vector2(1.0, 1.0)],
[Vector2(1.0, 1.0), Vector2(1.0, 1.0)],
[Vector2i(2, 1), Vector2i(1, 1)],
[Vector2i(1, 1), Vector2i(1, 1)],
[Vector3(1.0001, 1.0001, 1.0), Vector3(1.0, 1.0, 1.0)],
[Vector3(1.0, 1.0, 1.0), Vector3(1.0, 1.0, 1.0)],
[Vector3i(2, 1, 1), Vector3i(1, 1, 1)],
[Vector3i(1, 1, 1), Vector3i(1, 1, 1)],
[Vector4(1.0001, 1.0001, 1.0, 1.0), Vector4(1.0, 1.0, 1.0, 1.0)],
[Vector4(1.0, 1.0, 1.0, 1.0), Vector4(1.0, 1.0, 1.0, 1.0)],
[Vector4i(2, 1, 1, 1), Vector4i(1, 1, 1, 1)],
[Vector4i(1, 1, 1, 1), Vector4i(1, 1, 1, 1)],
]) -> void:
assert_vector(value).is_greater_equal(expected)
func test_is_between(fuzzer = Fuzzers.rangev2(Vector2.ZERO, Vector2.ONE)):
var value :Vector2 = fuzzer.next_value()
assert_vector(value).is_between(Vector2.ZERO, Vector2.ONE)
assert_failure(func(): assert_vector(Vector2(1, 1.00001)).is_between(Vector2.ZERO, Vector2.ONE)) \
.is_failed() \
.has_message("Expecting:\n '(1, 1.00001)'\n in range between\n '(0, 0)' <> '(1, 1)'")
assert_failure(func(): assert_vector(null).is_between(Vector2.ZERO, Vector2.ONE)) \
.is_failed() \
.has_message("Expecting:\n '<null>'\n in range between\n '(0, 0)' <> '(1, 1)'")
assert_failure(func(): assert_vector(Vector2(1, 1.00001)).is_between(Vector2.ZERO, Vector3.ONE)) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_between_over_all_types(value, from, to, test_parameters = [
[Vector2(1.2, 1.2), Vector2(1.0, 1.0), Vector2(1.2, 1.2)],
[Vector2i(1, 1), Vector2i(1, 1), Vector2i(2, 2)],
[Vector3(1.2, 1.2, 1.2), Vector3(1.0, 1.0, 1.0), Vector3(1.2, 1.2, 1.2)],
[Vector3i(1, 1, 1), Vector3i(1, 1, 1), Vector3i(2, 2, 2)],
[Vector4(1.2, 1.2, 1.2, 1.2), Vector4(1.0, 1.0, 1.0, 1.0), Vector4(1.2, 1.2, 1.2, 1.2)],
[Vector4i(1, 1, 1, 1), Vector4i(1, 1, 1, 1), Vector4i(2, 2, 2, 2)],
]) -> void:
assert_vector(value).is_between(from, to)
func test_is_not_between(fuzzer = Fuzzers.rangev2(Vector2.ONE, Vector2.ONE*2)):
var value :Vector2 = fuzzer.next_value()
assert_vector(null).is_not_between(Vector2.ZERO, Vector2.ONE)
assert_vector(value).is_not_between(Vector2.ZERO, Vector2.ONE)
assert_failure(func(): assert_vector(Vector2.ONE).is_not_between(Vector2.ZERO, Vector2.ONE)) \
.is_failed() \
.has_message("Expecting:\n '(1, 1)'\n not in range between\n '(0, 0)' <> '(1, 1)'")
assert_failure(func(): assert_vector(Vector2.ONE).is_not_between(Vector3.ZERO, Vector2.ONE)) \
.is_failed() \
.has_message("Unexpected type comparison:\n Expecting type 'Vector2' but is 'Vector3'")
@warning_ignore("unused_parameter")
func test_is_not_between_over_all_types(value, from, to, test_parameters = [
[Vector2(3.2, 1.2), Vector2(1.0, 1.0), Vector2(1.2, 1.2)],
[Vector2i(3, 1), Vector2i(1, 1), Vector2i(2, 2)],
[Vector3(3.2, 1.2, 1.2), Vector3(1.0, 1.0, 1.0), Vector3(1.2, 1.2, 1.2)],
[Vector3i(3, 1, 1), Vector3i(1, 1, 1), Vector3i(2, 2, 2)],
[Vector4(3.2, 1.2, 1.2, 1.2), Vector4(1.0, 1.0, 1.0, 1.0), Vector4(1.2, 1.2, 1.2, 1.2)],
[Vector4i(3, 1, 1, 1), Vector4i(1, 1, 1, 1), Vector4i(2, 2, 2, 2)],
]) -> void:
assert_vector(value).is_not_between(from, to)
func test_override_failure_message() -> void:
assert_failure(func(): assert_vector(Vector2.ONE) \
.override_failure_message("Custom failure message") \
.is_null()) \
.is_failed() \
.has_message("Custom failure message")
# tests if an assert fails the 'is_failure' reflects the failure status
func test_is_failure() -> void:
# initial is false
assert_bool(is_failure()).is_false()
# checked success assert
assert_vector(null).is_null()
assert_bool(is_failure()).is_false()
# checked faild assert
assert_failure(func(): assert_vector(RefCounted.new()).is_null()) \
.is_failed()
assert_bool(is_failure()).is_true()
# checked next success assert
assert_vector(null).is_null()
# is true because we have an already failed assert
assert_bool(is_failure()).is_true()

View file

@ -0,0 +1,120 @@
# GdUnit generated TestSuite
class_name CmdArgumentParserTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/cmd/CmdArgumentParser.gd'
var option_a := CmdOption.new("-a", "some help text a", "some description a")
var option_f := CmdOption.new("-f, --foo", "some help text foo", "some description foo")
var option_b := CmdOption.new("-b, --bar", "-b <value>", "comand with required argument", TYPE_STRING)
var option_c := CmdOption.new("-c, --calc", "-c [value]", "command with optional argument", TYPE_STRING, true)
var option_x := CmdOption.new("-x", "some help text x", "some description x")
var _cmd_options :CmdOptions
func before():
# setup command options
_cmd_options = CmdOptions.new([
option_a,
option_f,
option_b,
option_c,
],
# advnaced options
[
option_x,
])
func test_parse_success():
var parser := CmdArgumentParser.new(_cmd_options, "CmdTool.gd")
assert_result(parser.parse([])).is_empty()
# check with godot cmd argumnents before tool argument
assert_result(parser.parse(["-d", "dir/dir/CmdTool.gd"])).is_empty()
# if valid argument set than don't show the help by default
var result := parser.parse(["-d", "dir/dir/CmdTool.gd", "-a"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-a"),
])
func test_parse_success_required_arg():
var parser := CmdArgumentParser.new(_cmd_options, "CmdTool.gd")
var result := parser.parse(["-d", "dir/dir/CmdTool.gd", "-a", "-b", "valueA", "-b", "valueB"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-a"),
CmdCommand.new("-b", ["valueA", "valueB"]),
])
# useing command long term
result = parser.parse(["-d", "dir/dir/CmdTool.gd", "-a", "--bar", "value"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-a"),
CmdCommand.new("-b", ["value"])
])
func test_parse_success_optional_arg():
var parser := CmdArgumentParser.new(_cmd_options, "CmdTool.gd")
# without argument
var result := parser.parse(["-d", "dir/dir/CmdTool.gd", "-c", "-a"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-c"),
CmdCommand.new("-a")
])
# without argument at end
result = parser.parse(["-d", "dir/dir/CmdTool.gd", "-a", "-c"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-a"),
CmdCommand.new("-c")
])
# with argument
result = parser.parse(["-d", "dir/dir/CmdTool.gd", "-c", "argument", "-a"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-c", ["argument"]),
CmdCommand.new("-a")
])
func test_parse_success_repead_cmd_args():
var parser := CmdArgumentParser.new(_cmd_options, "CmdTool.gd")
# without argument
var result := parser.parse(["-d", "dir/dir/CmdTool.gd", "-c", "argument", "-a"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-c", ["argument"]),
CmdCommand.new("-a")
])
# with repeading commands argument
result = parser.parse(["-d", "dir/dir/CmdTool.gd", "-c", "argument1", "-a", "-c", "argument2", "-c", "argument3"])
assert_result(result).is_success()
assert_array(result.value()).contains_exactly([
CmdCommand.new("-c", ["argument1", "argument2", "argument3"]),
CmdCommand.new("-a")
])
func test_parse_error():
var parser := CmdArgumentParser.new(_cmd_options, "CmdTool.gd")
assert_result(parser.parse([])).is_empty()
# if invalid arguemens set than return with error and show the help by default
assert_result(parser.parse(["-d", "dir/dir/CmdTool.gd", "-unknown"])).is_error()\
.contains_message("Unknown '-unknown' command!")

View file

@ -0,0 +1,123 @@
# GdUnit generated TestSuite
class_name CmdCommandHandlerTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/cmd/CmdCommandHandler.gd'
var _cmd_options: CmdOptions
var _cmd_instance: TestCommands
# small example of command class
class TestCommands:
func cmd_a() -> String:
return "cmd_a"
func cmd_foo() -> String:
return "cmd_foo"
func cmd_bar(value :String) -> String:
return value
func cmd_bar2(value_a: String, value_b: String) -> Array:
return [value_a, value_b]
func cmd_x() -> String:
return "cmd_x"
func before() -> void:
# setup command options
_cmd_options = CmdOptions.new([
CmdOption.new("-a", "some help text a", "some description a"),
CmdOption.new("-f, --foo", "some help text foo", "some description foo"),
CmdOption.new("-b, --bar", "some help text bar", "some description bar"),
CmdOption.new("-b2, --bar2", "some help text bar", "some description bar"),
],
# advnaced options
[
CmdOption.new("-x", "some help text x", "some description x"),
])
_cmd_instance = TestCommands.new()
func test__validate_no_registerd_commands() -> void:
var cmd_handler := CmdCommandHandler.new(_cmd_options)
assert_result(cmd_handler._validate()).is_success()
func test__validate_registerd_commands() -> void:
var cmd_handler: = CmdCommandHandler.new(_cmd_options)
cmd_handler.register_cb("-a", Callable(_cmd_instance, "cmd_a"))
cmd_handler.register_cb("-f", Callable(_cmd_instance, "cmd_foo"))
cmd_handler.register_cb("-b", Callable(_cmd_instance, "cmd_bar"))
assert_result(cmd_handler._validate()).is_success()
func test__validate_registerd_unknown_commands() -> void:
var cmd_handler: = CmdCommandHandler.new(_cmd_options)
cmd_handler.register_cb("-a", Callable(_cmd_instance, "cmd_a"))
cmd_handler.register_cb("-d", Callable(_cmd_instance, "cmd_foo"))
cmd_handler.register_cb("-b", Callable(_cmd_instance, "cmd_bar"))
cmd_handler.register_cb("-y", Callable(_cmd_instance, "cmd_x"))
assert_result(cmd_handler._validate())\
.is_error()\
.contains_message("The command '-d' is unknown, verify your CmdOptions!\nThe command '-y' is unknown, verify your CmdOptions!")
func test__validate_registerd_invalid_callbacks() -> void:
var cmd_handler := CmdCommandHandler.new(_cmd_options)
cmd_handler.register_cb("-a", Callable(_cmd_instance, "cmd_a"))
cmd_handler.register_cb("-f")
cmd_handler.register_cb("-b", Callable(_cmd_instance, "cmd_not_exists"))
assert_result(cmd_handler._validate())\
.is_error()\
.contains_message("Invalid function reference for command '-b', Check the function reference!")
func test__validate_registerd_register_same_callback_twice() -> void:
var cmd_handler: = CmdCommandHandler.new(_cmd_options)
cmd_handler.register_cb("-a", Callable(_cmd_instance, "cmd_a"))
cmd_handler.register_cb("-b", Callable(_cmd_instance, "cmd_a"))
if cmd_handler._enhanced_fr_test:
assert_result(cmd_handler._validate())\
.is_error()\
.contains_message("The function reference 'cmd_a' already registerd for command '-a'!")
func test_execute_no_commands() -> void:
var cmd_handler: = CmdCommandHandler.new(_cmd_options)
assert_result(cmd_handler.execute([])).is_success()
func test_execute_commands_no_cb_registered() -> void:
var cmd_handler: = CmdCommandHandler.new(_cmd_options)
assert_result(cmd_handler.execute([CmdCommand.new("-a")])).is_success()
func test_execute_commands_with_cb_registered() -> void:
var cmd_handler: = CmdCommandHandler.new(_cmd_options)
var cmd_spy = spy(_cmd_instance)
cmd_handler.register_cb("-a", Callable(cmd_spy, "cmd_a"))
cmd_handler.register_cb("-b", Callable(cmd_spy, "cmd_bar"))
cmd_handler.register_cbv("-b2", Callable(cmd_spy, "cmd_bar2"))
assert_result(cmd_handler.execute([CmdCommand.new("-a")])).is_success()
verify(cmd_spy).cmd_a()
verify_no_more_interactions(cmd_spy)
reset(cmd_spy)
assert_result(cmd_handler.execute([
CmdCommand.new("-a"),
CmdCommand.new("-b", ["some_value"]),
CmdCommand.new("-b2", ["value1", "value2"])])).is_success()
verify(cmd_spy).cmd_a()
verify(cmd_spy).cmd_bar("some_value")
verify(cmd_spy).cmd_bar2("value1", "value2")
verify_no_more_interactions(cmd_spy)

View file

@ -0,0 +1,32 @@
# GdUnit generated TestSuite
class_name CmdCommandTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/cmd/CmdCommand.gd'
func test_create():
var cmd_a := CmdCommand.new("cmd_a")
assert_str(cmd_a.name()).is_equal("cmd_a")
assert_array(cmd_a.arguments()).is_empty()
var cmd_b := CmdCommand.new("cmd_b", ["arg1"])
assert_str(cmd_b.name()).is_equal("cmd_b")
assert_array(cmd_b.arguments()).contains_exactly(["arg1"])
assert_object(cmd_a).is_not_equal(cmd_b)
func test_add_argument():
var cmd_a := CmdCommand.new("cmd_a")
cmd_a.add_argument("arg1")
cmd_a.add_argument("arg2")
assert_str(cmd_a.name()).is_equal("cmd_a")
assert_array(cmd_a.arguments()).contains_exactly(["arg1", "arg2"])
var cmd_b := CmdCommand.new("cmd_b", ["arg1"])
cmd_b.add_argument("arg2")
cmd_b.add_argument("arg3")
assert_str(cmd_b.name()).is_equal("cmd_b")
assert_array(cmd_b.arguments()).contains_exactly(["arg1", "arg2", "arg3"])

View file

@ -0,0 +1,85 @@
# GdUnit generated TestSuite
class_name CmdConsoleTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/cmd/CmdConsole.gd'
func test_print_color_default() -> void:
var console :CmdConsole = spy(CmdConsole.new())
console.print_color("test message", Color.RED)
verify(console).color(Color.RED)
verify(console).end_color()
verify(console).printl("test message")
verify(console).bold(false)
verify(console).italic(false)
verify(console).underline(false)
verify(console, 0).new_line()
reset(console)
console.print_color("test message2", Color.BLUE)
verify(console).color(Color.BLUE)
verify(console).end_color()
verify(console).printl("test message2")
verify(console).bold(false)
verify(console).italic(false)
verify(console).underline(false)
verify(console, 0).new_line()
func test_print_color_with_flags() -> void:
var console :CmdConsole = spy(CmdConsole.new())
# bold
console.print_color("test message", Color.RED, CmdConsole.BOLD)
verify(console).bold(true)
verify(console).italic(false)
verify(console).underline(false)
reset(console)
# italic
console.print_color("test message", Color.RED, CmdConsole.ITALIC)
verify(console).bold(false)
verify(console).italic(true)
verify(console).underline(false)
reset(console)
# underline
console.print_color("test message", Color.RED, CmdConsole.UNDERLINE)
verify(console).bold(false)
verify(console).italic(false)
verify(console).underline(true)
reset(console)
# combile italic & underline
console.print_color("test message", Color.RED, CmdConsole.ITALIC|CmdConsole.UNDERLINE)
verify(console).bold(false)
verify(console).italic(true)
verify(console).underline(true)
reset(console)
# combile bold & italic
console.print_color("test message", Color.RED, CmdConsole.BOLD|CmdConsole.ITALIC)
verify(console).bold(true)
verify(console).italic(true)
verify(console).underline(false)
reset(console)
# combile all
console.print_color("test message", Color.RED, CmdConsole.BOLD|CmdConsole.ITALIC|CmdConsole.UNDERLINE)
verify(console).bold(true)
verify(console).italic(true)
verify(console).underline(true)
reset(console)
func test_prints_color() -> void:
var console :CmdConsole = spy(CmdConsole.new())
console.prints_color("test message", Color.RED, CmdConsole.BOLD|CmdConsole.ITALIC)
# verify prints delegates to print_color
verify(console).print_color("test message", Color.RED, CmdConsole.BOLD|CmdConsole.ITALIC)
# and adds a new line
verify(console).new_line()

View file

@ -0,0 +1,51 @@
# GdUnit generated TestSuite
class_name CmdOptionTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/cmd/CmdOption.gd'
func test_commands():
assert_array(CmdOption.new("-a", "help a", "describe a").commands())\
.contains_exactly(["-a"])
assert_array(CmdOption.new("-a, --aaa", "help a", "describe a").commands())\
.contains_exactly(["-a", "--aaa"])
# containing space or tabs
assert_array(CmdOption.new("-b , --bb ", "help a", "describe a")\
.commands()).contains_exactly(["-b", "--bb"])
func test_short_command():
assert_str(CmdOption.new("-a, --aaa", "help a", "describe a").short_command()).is_equal("-a")
func test_help():
assert_str(CmdOption.new("-a, --aaa", "help a", "describe a").help()).is_equal("help a")
func test_description():
assert_str(CmdOption.new("-a, --aaa", "help a", "describe a").description()).is_equal("describe a")
func test_type():
assert_int(CmdOption.new("-a", "", "").type()).is_equal(TYPE_NIL)
assert_int(CmdOption.new("-a", "", "", TYPE_STRING).type()).is_equal(TYPE_STRING)
assert_int(CmdOption.new("-a", "", "", TYPE_BOOL).type()).is_equal(TYPE_BOOL)
func test_is_argument_optional():
assert_bool(CmdOption.new("-a", "", "").is_argument_optional()).is_false()
assert_bool(CmdOption.new("-a", "", "", TYPE_BOOL, false).is_argument_optional()).is_false()
assert_bool(CmdOption.new("-a", "", "", TYPE_BOOL, true).is_argument_optional()).is_true()
func test_has_argument():
assert_bool(CmdOption.new("-a", "", "").has_argument()).is_false()
assert_bool(CmdOption.new("-a", "", "", TYPE_NIL).has_argument()).is_false()
assert_bool(CmdOption.new("-a", "", "", TYPE_BOOL).has_argument()).is_true()
func test_describe():
assert_str(CmdOption.new("-a, --aaa", "help a", "describe a").describe())\
.is_equal(' ["-a", "--aaa"] describe a \n help a\n')

View file

@ -0,0 +1,57 @@
# GdUnit generated TestSuite
class_name CmdOptionsTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/cmd/CmdOptions.gd'
var option_a := CmdOption.new("-a", "some help text a", "some description a")
var option_f := CmdOption.new("-f, --foo", "some help text foo", "some description foo")
var option_b := CmdOption.new("-b, --bar", "some help text bar", "some description bar")
var option_x := CmdOption.new("-x", "some help text x", "some description x")
var _cmd_options :CmdOptions
func before():
# setup command options
_cmd_options = CmdOptions.new([
option_a,
option_f,
option_b,
],
# advnaced options
[
option_x,
])
func test_get_option():
assert_object(_cmd_options.get_option("-a")).is_same(option_a)
assert_object(_cmd_options.get_option("-f")).is_same(option_f)
assert_object(_cmd_options.get_option("--foo")).is_same(option_f)
assert_object(_cmd_options.get_option("-b")).is_same(option_b)
assert_object(_cmd_options.get_option("--bar")).is_same(option_b)
assert_object(_cmd_options.get_option("-x")).is_same(option_x)
# for not existsing command
assert_object(_cmd_options.get_option("-z")).is_null()
func test_default_options():
assert_array(_cmd_options.default_options()).contains_exactly([
option_a,
option_f,
option_b])
func test_advanced_options():
assert_array(_cmd_options.advanced_options()).contains_exactly([option_x])
func test_options():
assert_array(_cmd_options.options()).contains_exactly([
option_a,
option_f,
option_b,
option_x])

View file

@ -0,0 +1,21 @@
namespace GdUnit4.Tests.Resource
{
using static Assertions;
[TestSuite]
public partial class ExampleTestSuiteA
{
[TestCase]
public void TestCase1()
{
AssertBool(true).IsEqual(true);
}
[TestCase]
public void TestCase2()
{
AssertBool(false).IsEqual(false);
}
}
}

View file

@ -0,0 +1,154 @@
# GdUnit generated TestSuite
class_name GdArrayToolsTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdArrayTools.gd'
@warning_ignore('unused_parameter')
func test_as_string(_test :String, value, expected :String, test_parameters = [
['Array', Array([1, 2]), '[1, 2]'],
['Array', Array([1.0, 2.212]), '[1.000000, 2.212000]'],
['Array', Array([true, false]), '[true, false]'],
['Array', Array(["1", "2"]), '["1", "2"]'],
['Array', Array([Vector2.ZERO, Vector2.LEFT]), '[Vector2(), Vector2(-1, 0)]'],
['Array', Array([Vector3.ZERO, Vector3.LEFT]), '[Vector3(), Vector3(-1, 0, 0)]'],
['Array', Array([Color.RED, Color.GREEN]), '[Color(1, 0, 0, 1), Color(0, 1, 0, 1)]'],
['ArrayInt', Array([1, 2]) as Array[int], '[1, 2]'],
['ArrayFloat', Array([1.0, 2.212]) as Array[float], '[1.000000, 2.212000]'],
['ArrayBool', Array([true, false]) as Array[bool], '[true, false]'],
['ArrayString', Array(["1", "2"]) as Array[String], '["1", "2"]'],
['ArrayVector2', Array([Vector2.ZERO, Vector2.LEFT]) as Array[Vector2], '[Vector2(), Vector2(-1, 0)]'],
['ArrayVector2i', Array([Vector2i.ZERO, Vector2i.LEFT]) as Array[Vector2i], '[Vector2i(), Vector2i(-1, 0)]'],
['ArrayVector3', Array([Vector3.ZERO, Vector3.LEFT]) as Array[Vector3], '[Vector3(), Vector3(-1, 0, 0)]'],
['ArrayVector3i', Array([Vector3i.ZERO, Vector3i.LEFT]) as Array[Vector3i], '[Vector3i(), Vector3i(-1, 0, 0)]'],
['ArrayVector4', Array([Vector4.ZERO, Vector4.ONE]) as Array[Vector4], '[Vector4(), Vector4(1, 1, 1, 1)]'],
['ArrayVector4i', Array([Vector4i.ZERO, Vector4i.ONE]) as Array[Vector4i], '[Vector4i(), Vector4i(1, 1, 1, 1)]'],
['ArrayColor', Array([Color.RED, Color.GREEN]) as Array[Color], '[Color(1, 0, 0, 1), Color(0, 1, 0, 1)]'],
['PackedByteArray', PackedByteArray([1, 2]), 'PackedByteArray[1, 2]'],
['PackedInt32Array', PackedInt32Array([1, 2]), 'PackedInt32Array[1, 2]'],
['PackedInt64Array', PackedInt64Array([1, 2]), 'PackedInt64Array[1, 2]'],
['PackedFloat32Array', PackedFloat32Array([1, 2.212]), 'PackedFloat32Array[1.000000, 2.212000]'],
['PackedFloat64Array', PackedFloat64Array([1, 2.212]), 'PackedFloat64Array[1.000000, 2.212000]'],
['PackedStringArray', PackedStringArray([1, 2]), 'PackedStringArray["1", "2"]'],
['PackedVector2Array', PackedVector2Array([Vector2.ZERO, Vector2.LEFT]), 'PackedVector2Array[Vector2(), Vector2(-1, 0)]'],
['PackedVector3Array', PackedVector3Array([Vector3.ZERO, Vector3.LEFT]), 'PackedVector3Array[Vector3(), Vector3(-1, 0, 0)]'],
['PackedColorArray', PackedColorArray([Color.RED, Color.GREEN]), 'PackedColorArray[Color(1, 0, 0, 1), Color(0, 1, 0, 1)]'],
]) -> void:
assert_that(GdArrayTools.as_string(value)).is_equal(expected)
func test_as_string_simple_format():
var value := PackedStringArray(["a", "b"])
prints(GdArrayTools.as_string(value, false))
assert_that(GdArrayTools.as_string(value, false)).is_equal('[a, b]')
@warning_ignore("unused_parameter")
func test_is_array_type(_test :String, value, expected :bool, test_parameters = [
['bool', true, false],
['int', 42, false],
['float', 1.21, false],
['String', "abc", false],
['Dictionary', {}, false],
['RefCounted', RefCounted.new(), false],
['Array', Array([1, 2]), true],
['Array', Array([1.0, 2.212]), true],
['Array', Array([true, false]), true],
['Array', Array(["1", "2"]), true],
['Array', Array([Vector2.ZERO, Vector2.LEFT]), true],
['Array', Array([Vector3.ZERO, Vector3.LEFT]), true],
['Array', Array([Color.RED, Color.GREEN]), true],
['ArrayInt', Array([1, 2]) as Array[int], true],
['ArrayFloat', Array([1.0, 2.212]) as Array[float], true],
['ArrayBool', Array([true, false]) as Array[bool], true],
['ArrayString', Array(["1", "2"]) as Array[String], true],
['ArrayVector2', Array([Vector2.ZERO, Vector2.LEFT]) as Array[Vector2], true],
['ArrayVector2i', Array([Vector2i.ZERO, Vector2i.LEFT]) as Array[Vector2i], true],
['ArrayVector3', Array([Vector3.ZERO, Vector3.LEFT]) as Array[Vector3], true],
['ArrayVector3i', Array([Vector3i.ZERO, Vector3i.LEFT]) as Array[Vector3i], true],
['ArrayVector4', Array([Vector4.ZERO, Vector4.ONE]) as Array[Vector4], true],
['ArrayVector4i', Array([Vector4i.ZERO, Vector4i.ONE]) as Array[Vector4i], true],
['ArrayColor', Array([Color.RED, Color.GREEN]) as Array[Color], true],
['PackedByteArray', PackedByteArray([1, 2]), true],
['PackedInt32Array', PackedInt32Array([1, 2]), true],
['PackedInt64Array', PackedInt64Array([1, 2]), true],
['PackedFloat32Array', PackedFloat32Array([1, 2.212]), true],
['PackedFloat64Array', PackedFloat64Array([1, 2.212]), true],
['PackedStringArray', PackedStringArray([1, 2]), true],
['PackedVector2Array', PackedVector2Array([Vector2.ZERO, Vector2.LEFT]), true],
['PackedVector3Array', PackedVector3Array([Vector3.ZERO, Vector3.LEFT]), true],
['PackedColorArray', PackedColorArray([Color.RED, Color.GREEN]), true],
]) -> void:
assert_that(GdArrayTools.is_array_type(value)).is_equal(expected)
func test_is_type_array() -> void:
for type in [TYPE_NIL, TYPE_MAX]:
if type in [TYPE_ARRAY, TYPE_PACKED_COLOR_ARRAY]:
assert_that(GdArrayTools.is_type_array(type)).is_true()
else:
assert_that(GdArrayTools.is_type_array(type)).is_false()
@warning_ignore("unused_parameter")
func test_filter_value(value, expected_type :int, test_parameters = [
[[1, 2, 3, 1], TYPE_ARRAY],
[Array([1, 2, 3, 1]) as Array[int], TYPE_ARRAY],
[PackedByteArray([1, 2, 3, 1]), TYPE_PACKED_BYTE_ARRAY],
[PackedInt32Array([1, 2, 3, 1]), TYPE_PACKED_INT32_ARRAY],
[PackedInt64Array([1, 2, 3, 1]), TYPE_PACKED_INT64_ARRAY],
[PackedFloat32Array([1.0, 2, 1.1, 1.0]), TYPE_PACKED_FLOAT32_ARRAY],
[PackedFloat64Array([1.0, 2, 1.1, 1.0]), TYPE_PACKED_FLOAT64_ARRAY],
[PackedStringArray(["1", "2", "3", "1"]), TYPE_PACKED_STRING_ARRAY],
[PackedVector2Array([Vector2.ZERO, Vector2.ONE, Vector2.DOWN, Vector2.ZERO]), TYPE_PACKED_VECTOR2_ARRAY],
[PackedVector3Array([Vector3.ZERO, Vector3.ONE, Vector3.DOWN, Vector3.ZERO]), TYPE_PACKED_VECTOR3_ARRAY],
[PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.RED]), TYPE_PACKED_COLOR_ARRAY]
]) -> void:
var value_to_remove = value[0]
var result :Variant = GdArrayTools.filter_value(value, value_to_remove)
assert_array(result).not_contains([value_to_remove]).has_size(2)
assert_that(typeof(result)).is_equal(expected_type)
func test_filter_value_() -> void:
assert_array(GdArrayTools.filter_value([], null)).is_empty()
assert_array(GdArrayTools.filter_value([], "")).is_empty()
var current :Array = [null, "a", "b", null, "c", null]
var filtered :Variant= GdArrayTools.filter_value(current, null)
assert_array(filtered).contains_exactly(["a", "b", "c"])
# verify the source is not affected
assert_array(current).contains_exactly([null, "a", "b", null, "c", null])
current = [null, "a", "xxx", null, "xx", null]
filtered = GdArrayTools.filter_value(current, "xxx")
assert_array(filtered).contains_exactly([null, "a", null, "xx", null])
# verify the source is not affected
assert_array(current).contains_exactly([null, "a", "xxx", null, "xx", null])
func test_erase_value() -> void:
var current := []
GdArrayTools.erase_value(current, null)
assert_array(current).is_empty()
current = [null]
GdArrayTools.erase_value(current, null)
assert_array(current).is_empty()
current = [null, "a", "b", null, "c", null]
GdArrayTools.erase_value(current, null)
# verify the source is affected
assert_array(current).contains_exactly(["a", "b", "c"])
func test_scan_typed() -> void:
assert_that(GdArrayTools.scan_typed([1, 2, 3])).is_equal(TYPE_INT)
assert_that(GdArrayTools.scan_typed([1, 2.2, 3])).is_equal(GdObjects.TYPE_VARIANT)

View file

@ -0,0 +1,48 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdDiffToolTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdDiffTool.gd'
func test_string_diff_empty():
var diffs := GdDiffTool.string_diff("", "")
assert_array(diffs).has_size(2)
assert_array(diffs[0]).is_empty()
assert_array(diffs[1]).is_empty()
func test_string_diff_equals():
var diffs := GdDiffTool.string_diff("Abc", "Abc")
var expected_l_diff := "Abc".to_ascii_buffer()
var expected_r_diff := "Abc".to_ascii_buffer()
assert_array(diffs).has_size(2)
assert_array(diffs[0]).contains_exactly(expected_l_diff)
assert_array(diffs[1]).contains_exactly(expected_r_diff)
func test_string_diff():
# tests the result of string diff function like assert_str("Abc").is_equal("abc")
var diffs := GdDiffTool.string_diff("Abc", "abc")
var chars := "Aabc".to_ascii_buffer()
var ord_A := chars[0]
var ord_a := chars[1]
var ord_b := chars[2]
var ord_c := chars[3]
var expected_l_diff := PackedByteArray([GdDiffTool.DIV_SUB, ord_A, GdDiffTool.DIV_ADD, ord_a, ord_b, ord_c])
var expected_r_diff := PackedByteArray([GdDiffTool.DIV_ADD, ord_A, GdDiffTool.DIV_SUB, ord_a, ord_b, ord_c])
assert_array(diffs).has_size(2)
assert_array(diffs[0]).contains_exactly(expected_l_diff)
assert_array(diffs[1]).contains_exactly(expected_r_diff)
@warning_ignore("unused_parameter")
func test_string_diff_large_value(fuzzer := Fuzzers.rand_str(1000, 4000), fuzzer_iterations = 10):
# test diff with large values not crashes the API GD-100
var value :String = fuzzer.next_value()
GdDiffTool.string_diff(value, value)

View file

@ -0,0 +1,512 @@
extends GdUnitTestSuite
func test_equals_string():
var a := ""
var b := ""
var c := "abc"
var d := "abC"
assert_bool(GdObjects.equals("", "")).is_true()
assert_bool(GdObjects.equals(a, "")).is_true()
assert_bool(GdObjects.equals("", a)).is_true()
assert_bool(GdObjects.equals(a, a)).is_true()
assert_bool(GdObjects.equals(a, b)).is_true()
assert_bool(GdObjects.equals(b, a)).is_true()
assert_bool(GdObjects.equals(c, c)).is_true()
assert_bool(GdObjects.equals(c, String(c))).is_true()
assert_bool(GdObjects.equals(a, null)).is_false()
assert_bool(GdObjects.equals(null, a)).is_false()
assert_bool(GdObjects.equals("", c)).is_false()
assert_bool(GdObjects.equals(c, "")).is_false()
assert_bool(GdObjects.equals(c, d)).is_false()
assert_bool(GdObjects.equals(d, c)).is_false()
# against diverent type
assert_bool(GdObjects.equals(d, Array())).is_false()
assert_bool(GdObjects.equals(d, Dictionary())).is_false()
assert_bool(GdObjects.equals(d, Vector2.ONE)).is_false()
assert_bool(GdObjects.equals(d, Vector3.ONE)).is_false()
func test_equals_stringname():
assert_bool(GdObjects.equals("", &"")).is_true()
assert_bool(GdObjects.equals("abc", &"abc")).is_true()
assert_bool(GdObjects.equals("abc", &"abC")).is_false()
func test_equals_array():
var a := []
var b := []
var c := Array()
var d := [1,2,3,4,5]
var e := [1,2,3,4,5]
var x := [1,2,3,6,4,5]
assert_bool(GdObjects.equals(a, a)).is_true()
assert_bool(GdObjects.equals(a, b)).is_true()
assert_bool(GdObjects.equals(b, a)).is_true()
assert_bool(GdObjects.equals(a, c)).is_true()
assert_bool(GdObjects.equals(c, b)).is_true()
assert_bool(GdObjects.equals(d, d)).is_true()
assert_bool(GdObjects.equals(d, e)).is_true()
assert_bool(GdObjects.equals(e, d)).is_true()
assert_bool(GdObjects.equals(a, null)).is_false()
assert_bool(GdObjects.equals(null, a)).is_false()
assert_bool(GdObjects.equals(a, d)).is_false()
assert_bool(GdObjects.equals(d, a)).is_false()
assert_bool(GdObjects.equals(d, x)).is_false()
assert_bool(GdObjects.equals(x, d)).is_false()
# against diverent type
assert_bool(GdObjects.equals(a, "")).is_false()
assert_bool(GdObjects.equals(a, Dictionary())).is_false()
assert_bool(GdObjects.equals(a, Vector2.ONE)).is_false()
assert_bool(GdObjects.equals(a, Vector3.ONE)).is_false()
func test_equals_dictionary():
var a := {}
var b := {}
var c := {"a":"foo"}
var d := {"a":"foo"}
var e1 := {"a":"foo", "b":"bar"}
var e2 := {"b":"bar", "a":"foo"}
assert_bool(GdObjects.equals(a, a)).is_true()
assert_bool(GdObjects.equals(a, b)).is_true()
assert_bool(GdObjects.equals(b, a)).is_true()
assert_bool(GdObjects.equals(c, c)).is_true()
assert_bool(GdObjects.equals(c, d)).is_true()
assert_bool(GdObjects.equals(e1, e2)).is_true()
assert_bool(GdObjects.equals(e2, e1)).is_true()
assert_bool(GdObjects.equals(a, null)).is_false()
assert_bool(GdObjects.equals(null, a)).is_false()
assert_bool(GdObjects.equals(a, c)).is_false()
assert_bool(GdObjects.equals(c, a)).is_false()
assert_bool(GdObjects.equals(a, e1)).is_false()
assert_bool(GdObjects.equals(e1, a)).is_false()
assert_bool(GdObjects.equals(c, e1)).is_false()
assert_bool(GdObjects.equals(e1, c)).is_false()
class TestClass extends Resource:
enum {
A,
B
}
var _a:int
var _b:String
var _c:Array
func _init(a:int = 0,b:String = "",c:Array = []):
_a = a
_b = b
_c = c
func test_equals_class():
var a := TestClass.new()
var b := TestClass.new()
var c := TestClass.new(1, "foo", ["bar", "xxx"])
var d := TestClass.new(1, "foo", ["bar", "xxx"])
var x := TestClass.new(1, "foo", ["bar", "xsxx"])
assert_bool(GdObjects.equals(a, a)).is_true()
assert_bool(GdObjects.equals(a, b)).is_true()
assert_bool(GdObjects.equals(b, a)).is_true()
assert_bool(GdObjects.equals(c, d)).is_true()
assert_bool(GdObjects.equals(d, c)).is_true()
assert_bool(GdObjects.equals(a, null)).is_false()
assert_bool(GdObjects.equals(null, a)).is_false()
assert_bool(GdObjects.equals(a, c)).is_false()
assert_bool(GdObjects.equals(c, a)).is_false()
assert_bool(GdObjects.equals(d, x)).is_false()
assert_bool(GdObjects.equals(x, d)).is_false()
func test_equals_with_stack_deep():
# more extended version
var x2 := TestClass.new(1, "foo", [TestClass.new(22, "foo"), TestClass.new(22, "foo")])
var x3 := TestClass.new(1, "foo", [TestClass.new(22, "foo"), TestClass.new(23, "foo")])
assert_bool(GdObjects.equals(x2, x3)).is_false()
func test_equals_Node_with_deep_check():
var nodeA = auto_free(Node.new())
var nodeB = auto_free(Node.new())
# compares by default with deep parameter ckeck
assert_bool(GdObjects.equals(nodeA, nodeA)).is_true()
assert_bool(GdObjects.equals(nodeB, nodeB)).is_true()
assert_bool(GdObjects.equals(nodeA, nodeB)).is_true()
assert_bool(GdObjects.equals(nodeB, nodeA)).is_true()
# compares by object reference
assert_bool(GdObjects.equals(nodeA, nodeA, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_true()
assert_bool(GdObjects.equals(nodeB, nodeB, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_true()
assert_bool(GdObjects.equals(nodeA, nodeB, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_false()
assert_bool(GdObjects.equals(nodeB, nodeA, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_false()
func test_is_primitive_type():
assert_bool(GdObjects.is_primitive_type(false)).is_true()
assert_bool(GdObjects.is_primitive_type(true)).is_true()
assert_bool(GdObjects.is_primitive_type(0)).is_true()
assert_bool(GdObjects.is_primitive_type(0.1)).is_true()
assert_bool(GdObjects.is_primitive_type("")).is_true()
assert_bool(GdObjects.is_primitive_type(Vector2.ONE)).is_false()
class TestClassForIsType:
var x
func test_is_type():
# check build-in types
assert_bool(GdObjects.is_type(1)).is_false()
assert_bool(GdObjects.is_type(1.3)).is_false()
assert_bool(GdObjects.is_type(true)).is_false()
assert_bool(GdObjects.is_type(false)).is_false()
assert_bool(GdObjects.is_type([])).is_false()
assert_bool(GdObjects.is_type("abc")).is_false()
assert_bool(GdObjects.is_type(null)).is_false()
# an object type
assert_bool(GdObjects.is_type(Node)).is_true()
# an reference type
assert_bool(GdObjects.is_type(AStar3D)).is_true()
# an script type
assert_bool(GdObjects.is_type(GDScript)).is_true()
# an custom type
assert_bool(GdObjects.is_type(TestClassForIsType)).is_true()
# checked inner class type
assert_bool(GdObjects.is_type(CustomClass.InnerClassA)).is_true()
assert_bool(GdObjects.is_type(CustomClass.InnerClassC)).is_true()
# for instances must allways endup with false
assert_bool(GdObjects.is_type(auto_free(Node.new()))).is_false()
assert_bool(GdObjects.is_type(AStar3D.new())).is_false()
assert_bool(GdObjects.is_type(Dictionary())).is_false()
assert_bool(GdObjects.is_type(PackedColorArray())).is_false()
assert_bool(GdObjects.is_type(GDScript.new())).is_false()
assert_bool(GdObjects.is_type(TestClassForIsType.new())).is_false()
assert_bool(GdObjects.is_type(auto_free(CustomClass.InnerClassC.new()))).is_false()
func test_is_singleton() -> void:
for singleton_name in Engine.get_singleton_list():
var singleton = Engine.get_singleton(singleton_name)
assert_bool(GdObjects.is_singleton(singleton)) \
.override_failure_message("Expect to a singleton: '%s' Instance: %s, Class: %s" % [singleton_name, singleton, singleton.get_class()]) \
.is_true()
# false tests
assert_bool(GdObjects.is_singleton(10)).is_false()
assert_bool(GdObjects.is_singleton(true)).is_false()
assert_bool(GdObjects.is_singleton(Node)).is_false()
assert_bool(GdObjects.is_singleton(auto_free(Node.new()))).is_false()
func _is_instance(value) -> bool:
return GdObjects.is_instance(auto_free(value))
func test_is_instance_true():
assert_bool(_is_instance(RefCounted.new())).is_true()
assert_bool(_is_instance(Node.new())).is_true()
assert_bool(_is_instance(AStar3D.new())).is_true()
assert_bool(_is_instance(PackedScene.new())).is_true()
assert_bool(_is_instance(GDScript.new())).is_true()
assert_bool(_is_instance(Person.new())).is_true()
assert_bool(_is_instance(CustomClass.new())).is_true()
assert_bool(_is_instance(CustomNodeTestClass.new())).is_true()
assert_bool(_is_instance(TestClassForIsType.new())).is_true()
assert_bool(_is_instance(CustomClass.InnerClassC.new())).is_true()
func test_is_instance_false():
assert_bool(_is_instance(RefCounted)).is_false()
assert_bool(_is_instance(Node)).is_false()
assert_bool(_is_instance(AStar3D)).is_false()
assert_bool(_is_instance(PackedScene)).is_false()
assert_bool(_is_instance(GDScript)).is_false()
assert_bool(_is_instance(Dictionary())).is_false()
assert_bool(_is_instance(PackedColorArray())).is_false()
assert_bool(_is_instance(Person)).is_false()
assert_bool(_is_instance(CustomClass)).is_false()
assert_bool(_is_instance(CustomNodeTestClass)).is_false()
assert_bool(_is_instance(TestClassForIsType)).is_false()
assert_bool(_is_instance(CustomClass.InnerClassC)).is_false()
# shorter helper func to extract class name and using auto_free
func extract_class_name(value) -> GdUnitResult:
return GdObjects.extract_class_name(auto_free(value))
func test_get_class_name_from_class_path():
# extract class name by resoure path
assert_result(extract_class_name("res://addons/gdUnit4/test/resources/core/Person.gd"))\
.is_success().is_value("Person")
assert_result(extract_class_name("res://addons/gdUnit4/test/resources/core/CustomClass.gd"))\
.is_success().is_value("CustomClass")
assert_result(extract_class_name("res://addons/gdUnit4/test/mocker/resources/CustomNodeTestClass.gd"))\
.is_success().is_value("CustomNodeTestClass")
assert_result(extract_class_name("res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd"))\
.is_success().is_value("CustomResourceTestClass")
assert_result(extract_class_name("res://addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd"))\
.is_success().is_value("OverridenGetClassTestClass")
func test_get_class_name_from_snake_case_class_path():
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd"))\
.is_success().is_value("SnakeCaseWithClassName")
# without class_name
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd"))\
.is_success().is_value("SnakeCaseWithoutClassName")
func test_get_class_name_from_pascal_case_class_path():
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd"))\
.is_success().is_value("PascalCaseWithClassName")
# without class_name
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd"))\
.is_success().is_value("PascalCaseWithoutClassName")
func test_get_class_name_from_type():
assert_result(extract_class_name(Animation)).is_success().is_value("Animation")
assert_result(extract_class_name(GDScript)).is_success().is_value("GDScript")
assert_result(extract_class_name(Camera3D)).is_success().is_value("Camera3D")
assert_result(extract_class_name(Node)).is_success().is_value("Node")
assert_result(extract_class_name(Tree)).is_success().is_value("Tree")
# extract class name from custom classes
assert_result(extract_class_name(Person)).is_success().is_value("Person")
assert_result(extract_class_name(CustomClass)).is_success().is_value("CustomClass")
assert_result(extract_class_name(CustomNodeTestClass)).is_success().is_value("CustomNodeTestClass")
assert_result(extract_class_name(CustomResourceTestClass)).is_success().is_value("CustomResourceTestClass")
assert_result(extract_class_name(OverridenGetClassTestClass)).is_success().is_value("OverridenGetClassTestClass")
assert_result(extract_class_name(AdvancedTestClass)).is_success().is_value("AdvancedTestClass")
func test_get_class_name_from_inner_class():
assert_result(extract_class_name(CustomClass))\
.is_success().is_value("CustomClass")
assert_result(extract_class_name(CustomClass.InnerClassA))\
.is_success().is_value("CustomClass.InnerClassA")
assert_result(extract_class_name(CustomClass.InnerClassB))\
.is_success().is_value("CustomClass.InnerClassB")
assert_result(extract_class_name(CustomClass.InnerClassC))\
.is_success().is_value("CustomClass.InnerClassC")
assert_result(extract_class_name(CustomClass.InnerClassD))\
.is_success().is_value("CustomClass.InnerClassD")
assert_result(extract_class_name(AdvancedTestClass.SoundData))\
.is_success().is_value("AdvancedTestClass.SoundData")
assert_result(extract_class_name(AdvancedTestClass.AtmosphereData))\
.is_success().is_value("AdvancedTestClass.AtmosphereData")
assert_result(extract_class_name(AdvancedTestClass.Area4D))\
.is_success().is_value("AdvancedTestClass.Area4D")
func test_extract_class_name_from_instance():
assert_result(extract_class_name(Camera3D.new())).is_equal("Camera3D")
assert_result(extract_class_name(GDScript.new())).is_equal("GDScript")
assert_result(extract_class_name(Node.new())).is_equal("Node")
# extract class name from custom classes
assert_result(extract_class_name(Person.new())).is_equal("Person")
assert_result(extract_class_name(ClassWithNameA.new())).is_equal("ClassWithNameA")
assert_result(extract_class_name(ClassWithNameB.new())).is_equal("ClassWithNameB")
var classWithoutNameA = load("res://addons/gdUnit4/test/mocker/resources/ClassWithoutNameA.gd")
assert_result(extract_class_name(classWithoutNameA.new())).is_equal("ClassWithoutNameA")
assert_result(extract_class_name(CustomNodeTestClass.new())).is_equal("CustomNodeTestClass")
assert_result(extract_class_name(CustomResourceTestClass.new())).is_equal("CustomResourceTestClass")
assert_result(extract_class_name(OverridenGetClassTestClass.new())).is_equal("OverridenGetClassTestClass")
assert_result(extract_class_name(AdvancedTestClass.new())).is_equal("AdvancedTestClass")
# extract inner class name
assert_result(extract_class_name(AdvancedTestClass.SoundData.new())).is_equal("AdvancedTestClass.SoundData")
assert_result(extract_class_name(AdvancedTestClass.AtmosphereData.new())).is_equal("AdvancedTestClass.AtmosphereData")
assert_result(extract_class_name(AdvancedTestClass.Area4D.new(0))).is_equal("AdvancedTestClass.Area4D")
assert_result(extract_class_name(CustomClass.InnerClassC.new())).is_equal("CustomClass.InnerClassC")
# verify enigne class names are not converted by configured naming convention
@warning_ignore("unused_parameter")
func test_extract_class_name_from_class_path(fuzzer=GodotClassNameFuzzer.new(true, true), fuzzer_iterations = 100) -> void:
var clazz_name :String = fuzzer.next_value()
assert_str(GdObjects.extract_class_name_from_class_path(PackedStringArray([clazz_name]))).is_equal(clazz_name)
@warning_ignore("unused_parameter")
func test_extract_class_name_godot_classes(fuzzer=GodotClassNameFuzzer.new(true, true), fuzzer_iterations = 100):
var extract_class_name_ := fuzzer.next_value() as String
var instance :Variant = ClassDB.instantiate(extract_class_name_)
assert_result(extract_class_name(instance)).is_equal(extract_class_name_)
func test_extract_class_path_by_clazz():
# engine classes has no class path
assert_array(GdObjects.extract_class_path(Animation)).is_empty()
assert_array(GdObjects.extract_class_path(GDScript)).is_empty()
assert_array(GdObjects.extract_class_path(Camera3D)).is_empty()
assert_array(GdObjects.extract_class_path(Tree)).is_empty()
assert_array(GdObjects.extract_class_path(Node)).is_empty()
# script classes
assert_array(GdObjects.extract_class_path(Person))\
.contains_exactly(["res://addons/gdUnit4/test/resources/core/Person.gd"])
assert_array(GdObjects.extract_class_path(CustomClass))\
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd"])
assert_array(GdObjects.extract_class_path(CustomNodeTestClass))\
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/CustomNodeTestClass.gd"])
assert_array(GdObjects.extract_class_path(CustomResourceTestClass))\
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd"])
assert_array(GdObjects.extract_class_path(OverridenGetClassTestClass))\
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd"])
# script inner classes
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassA))\
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassA"])
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassB))\
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassB"])
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassC))\
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassC"])
assert_array(GdObjects.extract_class_path(AdvancedTestClass.SoundData))\
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd", "SoundData"])
assert_array(GdObjects.extract_class_path(AdvancedTestClass.AtmosphereData))\
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd", "AtmosphereData"])
assert_array(GdObjects.extract_class_path(AdvancedTestClass.Area4D))\
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd", "Area4D"])
# inner inner class
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassD.InnerInnerClassA))\
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassD", "InnerInnerClassA"])
#func __test_can_instantiate():
# assert_bool(GdObjects.can_instantiate(GDScript)).is_true()
# assert_bool(GdObjects.can_instantiate(Node)).is_true()
# assert_bool(GdObjects.can_instantiate(Tree)).is_true()
# assert_bool(GdObjects.can_instantiate(Camera3D)).is_true()
# assert_bool(GdObjects.can_instantiate(Person)).is_true()
# assert_bool(GdObjects.can_instantiate(CustomClass.InnerClassA)).is_true()
# assert_bool(GdObjects.can_instantiate(TreeItem)).is_true()
#
# creates a test instance by given class name or resource path
# instances created with auto free
func create_instance(clazz):
var result := GdObjects.create_instance(clazz)
if result.is_success():
return auto_free(result.value())
return null
func test_create_instance_by_class_name():
# instance of engine classes
assert_object(create_instance(Node))\
.is_not_null()\
.is_instanceof(Node)
assert_object(create_instance(Camera3D))\
.is_not_null()\
.is_instanceof(Camera3D)
# instance of custom classes
assert_object(create_instance(Person))\
.is_not_null()\
.is_instanceof(Person)
# instance of inner classes
assert_object(create_instance(CustomClass.InnerClassA))\
.is_not_null()\
.is_instanceof(CustomClass.InnerClassA)
func test_extract_class_name_on_null_value():
# we can't extract class name from a null value
assert_result(GdObjects.extract_class_name(null))\
.is_error()\
.contains_message("Can't extract class name form a null value.")
func test_is_public_script_class() -> void:
# snake case format class names
assert_bool(GdObjects.is_public_script_class("ScriptWithClassName")).is_true()
assert_bool(GdObjects.is_public_script_class("script_without_class_name")).is_false()
assert_bool(GdObjects.is_public_script_class("CustomClass")).is_true()
# inner classes not listed as public classes
assert_bool(GdObjects.is_public_script_class("CustomClass.InnerClassA")).is_false()
func test_is_instance_scene() -> void:
# checked none scene objects
assert_bool(GdObjects.is_instance_scene(RefCounted.new())).is_false()
assert_bool(GdObjects.is_instance_scene(CustomClass.new())).is_false()
assert_bool(GdObjects.is_instance_scene(auto_free(Control.new()))).is_false()
# now check checked a loaded scene
var resource = load("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
assert_bool(GdObjects.is_instance_scene(resource)).is_false()
# checked a instance of a scene
assert_bool(GdObjects.is_instance_scene(auto_free(resource.instantiate()))).is_true()
func test_is_scene_resource_path() -> void:
assert_bool(GdObjects.is_scene_resource_path(RefCounted.new())).is_false()
assert_bool(GdObjects.is_scene_resource_path(CustomClass.new())).is_false()
assert_bool(GdObjects.is_scene_resource_path(auto_free(Control.new()))).is_false()
# check checked a loaded scene
var resource = load("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
assert_bool(GdObjects.is_scene_resource_path(resource)).is_false()
# checked resource path
assert_bool(GdObjects.is_scene_resource_path("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")).is_true()
func test_extract_class_functions() -> void:
var functions := GdObjects.extract_class_functions("Resource", [""])
for f in functions:
if f["name"] == "get_path":
assert_str(GdFunctionDescriptor.extract_from(f)._to_string()).is_equal("[Line:-1] func get_path() -> String:")
functions = GdObjects.extract_class_functions("CustomResourceTestClass", ["res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd"])
for f in functions:
if f["name"] == "get_path":
assert_str(GdFunctionDescriptor.extract_from(f)._to_string()).is_equal("[Line:-1] func get_path() -> String:")
func test_all_types() -> void:
var expected_types :Array[int] = []
for type_index in TYPE_MAX:
expected_types.append(type_index)
expected_types.append(GdObjects.TYPE_VOID)
expected_types.append(GdObjects.TYPE_VARARG)
expected_types.append(GdObjects.TYPE_FUNC)
expected_types.append(GdObjects.TYPE_FUZZER)
expected_types.append(GdObjects.TYPE_VARIANT)
assert_array(GdObjects.all_types()).contains_exactly_in_any_order(expected_types)
func test_to_camel_case() -> void:
assert_str(GdObjects.to_camel_case("MyClassName")).is_equal("myClassName")
assert_str(GdObjects.to_camel_case("my_class_name")).is_equal("myClassName")
assert_str(GdObjects.to_camel_case("myClassName")).is_equal("myClassName")
func test_to_pascal_case() -> void:
assert_str(GdObjects.to_pascal_case("MyClassName")).is_equal("MyClassName")
assert_str(GdObjects.to_pascal_case("my_class_name")).is_equal("MyClassName")
assert_str(GdObjects.to_pascal_case("myClassName")).is_equal("MyClassName")
func test_to_snake_case() -> void:
assert_str(GdObjects.to_snake_case("MyClassName")).is_equal("my_class_name")
assert_str(GdObjects.to_snake_case("my_class_name")).is_equal("my_class_name")
assert_str(GdObjects.to_snake_case("myClassName")).is_equal("my_class_name")
func test_is_snake_case() -> void:
assert_bool(GdObjects.is_snake_case("my_class_name")).is_true()
assert_bool(GdObjects.is_snake_case("myclassname")).is_true()
assert_bool(GdObjects.is_snake_case("MyClassName")).is_false()
assert_bool(GdObjects.is_snake_case("my_class_nameTest")).is_false()

View file

@ -0,0 +1,67 @@
# GdUnit generated TestSuite
class_name GdUnit4VersionTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/.gd'
func test_parse() -> void:
var expected := GdUnit4Version.new(0, 9, 1)
assert_object(GdUnit4Version.parse("v0.9.1-rc")).is_equal(expected)
assert_object(GdUnit4Version.parse("v0.9.1RC")).is_equal(expected)
assert_object(GdUnit4Version.parse("0.9.1 rc")).is_equal(expected)
assert_object(GdUnit4Version.parse("0.9.1")).is_equal(expected)
func test_equals() -> void:
var version := GdUnit4Version.new(0, 9, 1)
assert_bool(version.equals(version)).is_true()
assert_bool(version.equals(GdUnit4Version.new(0, 9, 1))).is_true()
assert_bool(GdUnit4Version.new(0, 9, 1).equals(version)).is_true()
assert_bool(GdUnit4Version.new(0, 9, 2).equals(version)).is_false()
assert_bool(GdUnit4Version.new(0, 8, 1).equals(version)).is_false()
assert_bool(GdUnit4Version.new(1, 9, 1).equals(version)).is_false()
func test_to_string() -> void:
var version := GdUnit4Version.new(0, 9, 1)
assert_str(str(version)).is_equal("v0.9.1")
assert_str("%s" % version).is_equal("v0.9.1")
@warning_ignore("unused_parameter")
func test_is_greater_major(fuzzer_major := Fuzzers.rangei(1, 20), fuzzer_minor := Fuzzers.rangei(0, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void:
var version := GdUnit4Version.new(0, 9, 1)
var current := GdUnit4Version.new(fuzzer_major.next_value(), fuzzer_minor.next_value(), fuzzer_patch.next_value());
assert_bool(current.is_greater(version))\
.override_failure_message("Expect %s is greater then %s" % [current, version])\
.is_true()
@warning_ignore("unused_parameter")
func test_is_not_greater_major(fuzzer_major := Fuzzers.rangei(1, 10), fuzzer_minor := Fuzzers.rangei(0, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void:
var version := GdUnit4Version.new(11, 0, 0)
var current := GdUnit4Version.new(fuzzer_major.next_value(), fuzzer_minor.next_value(), fuzzer_patch.next_value());
assert_bool(current.is_greater(version))\
.override_failure_message("Expect %s is not greater then %s" % [current, version])\
.is_false()
@warning_ignore("unused_parameter")
func test_is_greater_minor(fuzzer_minor := Fuzzers.rangei(3, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void:
var version := GdUnit4Version.new(0, 2, 1)
var current := GdUnit4Version.new(0, fuzzer_minor.next_value(), fuzzer_patch.next_value());
assert_bool(current.is_greater(version))\
.override_failure_message("Expect %s is greater then %s" % [current, version])\
.is_true()
@warning_ignore("unused_parameter")
func test_is_greater_patch(fuzzer_patch := Fuzzers.rangei(1, 20), fuzzer_iterations = 500) -> void:
var version := GdUnit4Version.new(0, 2, 0)
var current := GdUnit4Version.new(0, 2, fuzzer_patch.next_value());
assert_bool(current.is_greater(version))\
.override_failure_message("Expect %s is greater then %s" % [current, version])\
.is_true()

View file

@ -0,0 +1,13 @@
# GdUnit generated TestSuite
class_name GdUnitClassDoublerTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitClassDoubler.gd'
# simple function doubler whitout any modifications
class TestFunctionDoubler extends GdFunctionDoubler:
func double(_func_descriptor :GdFunctionDescriptor) -> PackedStringArray:
return PackedStringArray([])

View file

@ -0,0 +1,231 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitFileAccess.gd'
var file_to_save :String
func after() -> void:
# verify tmp files are deleted automatically
assert_bool(FileAccess.file_exists(file_to_save)).is_false()
func _create_file(p_path :String, p_name :String) -> void:
var file := create_temp_file(p_path, p_name)
file.store_string("some content")
func test_copy_directory() -> void:
var temp_dir := create_temp_dir("test_copy_directory")
assert_bool(GdUnitFileAccess.copy_directory("res://addons/gdUnit4/test/core/resources/copy_test/folder_a/", temp_dir)).is_true()
assert_file("%s/file_a.txt" % temp_dir).exists()
assert_file("%s/file_b.txt" % temp_dir).exists()
func test_copy_directory_recursive() -> void:
var temp_dir := create_temp_dir("test_copy_directory_recursive")
assert_bool(GdUnitFileAccess.copy_directory("res://addons/gdUnit4/test/core/resources/copy_test/", temp_dir, true)).is_true()
assert_file("%s/folder_a/file_a.txt" % temp_dir).exists()
assert_file("%s/folder_a/file_b.txt" % temp_dir).exists()
assert_file("%s/folder_b/file_a.txt" % temp_dir).exists()
assert_file("%s/folder_b/file_b.txt" % temp_dir).exists()
assert_file("%s/folder_b/folder_ba/file_x.txt" % temp_dir).exists()
assert_file("%s/folder_c/file_z.txt" % temp_dir).exists()
func test_create_temp_dir() -> void:
var temp_dir := create_temp_dir("examples/game/save")
file_to_save = temp_dir + "/save_game.dat"
var data := {
'user': "Hoschi",
'level': 42
}
var file := FileAccess.open(file_to_save, FileAccess.WRITE)
file.store_line(JSON.stringify(data))
assert_bool(FileAccess.file_exists(file_to_save)).is_true()
func test_create_temp_file() -> void:
# setup - stores a tmp file with "user://tmp/examples/game/game.sav" (auto closed)
var file := create_temp_file("examples/game", "game.sav")
assert_object(file).is_not_null()
# write some example data
file.store_line("some data")
file.close()
# verify
var file_read := create_temp_file("examples/game", "game.sav", FileAccess.READ)
assert_object(file_read).is_not_null()
assert_str(file_read.get_as_text()).is_equal("some data\n")
# not needs to be manually close, will be auto closed after test suite execution
func test_make_qualified_path() -> void:
assert_str(GdUnitFileAccess.make_qualified_path("MyTest")).is_equal("MyTest")
assert_str(GdUnitFileAccess.make_qualified_path("/MyTest.gd")).is_equal("res://MyTest.gd")
assert_str(GdUnitFileAccess.make_qualified_path("/foo/bar/MyTest.gd")).is_equal("res://foo/bar/MyTest.gd")
assert_str(GdUnitFileAccess.make_qualified_path("res://MyTest.gd")).is_equal("res://MyTest.gd")
assert_str(GdUnitFileAccess.make_qualified_path("res://foo/bar/MyTest.gd")).is_equal("res://foo/bar/MyTest.gd")
func test_find_last_path_index() -> void:
# not existing directory
assert_int(GdUnitFileAccess.find_last_path_index("/foo", "report_")).is_equal(0)
# empty directory
var temp_dir := create_temp_dir("test_reports")
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(0)
# create some report directories
create_temp_dir("test_reports/report_1")
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(1)
create_temp_dir("test_reports/report_2")
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(2)
create_temp_dir("test_reports/report_3")
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(3)
create_temp_dir("test_reports/report_5")
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(5)
# create some more
for index in range(10, 42):
create_temp_dir("test_reports/report_%d" % index)
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(41)
func test_delete_path_index_lower_equals_than() -> void:
var temp_dir := create_temp_dir("test_reports_delete")
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).is_empty()
assert_int(GdUnitFileAccess.delete_path_index_lower_equals_than(temp_dir, "report_", 0)).is_equal(0)
# create some directories
for index in range(10, 42):
create_temp_dir("test_reports_delete/report_%d" % index)
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).has_size(32)
# try to delete directories with index lower than 0, shold delete nothing
assert_int(GdUnitFileAccess.delete_path_index_lower_equals_than(temp_dir, "report_", 0)).is_equal(0)
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).has_size(32)
# try to delete directories with index lower_equals than 30
# shold delet directories report_10 to report_30 = 21
assert_int(GdUnitFileAccess.delete_path_index_lower_equals_than(temp_dir, "report_", 30)).is_equal(21)
# and 12 directories are left
assert_array(GdUnitFileAccess.scan_dir(temp_dir))\
.has_size(11)\
.contains([
"report_31",
"report_32",
"report_33",
"report_34",
"report_35",
"report_36",
"report_37",
"report_38",
"report_39",
"report_40",
"report_41",
])
func test_scan_dir() -> void:
var temp_dir := create_temp_dir("test_scan_dir")
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).is_empty()
create_temp_dir("test_scan_dir/report_2")
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).contains_exactly(["report_2"])
# create some more directories and files
create_temp_dir("test_scan_dir/report_4")
create_temp_dir("test_scan_dir/report_5")
create_temp_dir("test_scan_dir/report_6")
create_temp_file("test_scan_dir", "file_a")
create_temp_file("test_scan_dir", "file_b")
# this shoul not be counted it is a file in a subdirectory
create_temp_file("test_scan_dir/report_6", "file_b")
assert_array(GdUnitFileAccess.scan_dir(temp_dir))\
.has_size(6)\
.contains([
"report_2",
"report_4",
"report_5",
"report_6",
"file_a",
"file_b"])
func test_delete_directory() -> void:
var tmp_dir := create_temp_dir("test_delete_dir")
create_temp_dir("test_delete_dir/data1")
create_temp_dir("test_delete_dir/data2")
_create_file("test_delete_dir", "example_a.txt")
_create_file("test_delete_dir", "example_b.txt")
_create_file("test_delete_dir/data1", "example.txt")
_create_file("test_delete_dir/data2", "example2.txt")
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).contains_exactly_in_any_order([
"data1",
"data2",
"example_a.txt",
"example_b.txt"
])
# Delete the entire directory and its contents
GdUnitFileAccess.delete_directory(tmp_dir)
assert_bool(DirAccess.dir_exists_absolute(tmp_dir)).is_false()
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).is_empty()
func test_delete_directory_content_only() -> void:
var tmp_dir := create_temp_dir("test_delete_dir")
create_temp_dir("test_delete_dir/data1")
create_temp_dir("test_delete_dir/data2")
_create_file("test_delete_dir", "example_a.txt")
_create_file("test_delete_dir", "example_b.txt")
_create_file("test_delete_dir/data1", "example.txt")
_create_file("test_delete_dir/data2", "example2.txt")
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).contains_exactly_in_any_order([
"data1",
"data2",
"example_a.txt",
"example_b.txt"
])
# Delete the entire directory and its contents
GdUnitFileAccess.delete_directory(tmp_dir, true)
assert_bool(DirAccess.dir_exists_absolute(tmp_dir)).is_true()
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).is_empty()
func test_extract_package() -> void:
clean_temp_dir()
var tmp_path := GdUnitFileAccess.create_temp_dir("test_update")
var source := "res://addons/gdUnit4/test/update/resources/update.zip"
# the temp should be inital empty
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).is_empty()
# now extract to temp
var result := GdUnitFileAccess.extract_zip(source, tmp_path)
assert_result(result).is_success()
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).contains_exactly_in_any_order([
"addons",
"runtest.cmd",
"runtest.sh",
])
func test_extract_package_invalid_package() -> void:
clean_temp_dir()
var tmp_path := GdUnitFileAccess.create_temp_dir("test_update")
var source := "res://addons/gdUnit4/test/update/resources/update_invalid.zip"
# the temp should be inital empty
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).is_empty()
# now extract to temp
var result := GdUnitFileAccess.extract_zip(source, tmp_path)
assert_result(result).is_error()\
.contains_message("Extracting `%s` failed! Please collect the error log and report this. Error Code: 1" % source)
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).is_empty()

View file

@ -0,0 +1,36 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitObjectInteractionsTemplate.gd'
func test___filter_vargs():
var template = load(__source).new()
var varags :Array = [
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE]
assert_array(template.__filter_vargs(varags)).is_empty()
var object := RefCounted.new()
varags = [
"foo",
"bar",
null,
true,
1,
object,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE]
assert_array(template.__filter_vargs(varags)).contains_exactly([
"foo",
"bar",
null,
true,
1,
object])

View file

@ -0,0 +1,37 @@
# GdUnit generated TestSuite
class_name GdUnitResultTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitResult.gd'
func test_serde():
var value = {
"info" : "test",
"meta" : 42
}
var source := GdUnitResult.success(value)
var serialized_result = GdUnitResult.serialize(source)
var deserialised_result := GdUnitResult.deserialize(serialized_result)
assert_object(deserialised_result)\
.is_instanceof(GdUnitResult) \
.is_equal(source)
func test_or_else_on_success():
var result := GdUnitResult.success("some value")
assert_str(result.value()).is_equal("some value")
assert_str(result.or_else("other value")).is_equal("some value")
func test_or_else_on_warning():
var result := GdUnitResult.warn("some warning message")
assert_object(result.value()).is_null()
assert_str(result.or_else("other value")).is_equal("other value")
func test_or_else_on_error():
var result := GdUnitResult.error("some error message")
assert_object(result.value()).is_null()
assert_str(result.or_else("other value")).is_equal("other value")

View file

@ -0,0 +1,189 @@
# GdUnit generated TestSuite
class_name GdUnitRunnerConfigTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitRunnerConfig.gd'
func test_initial_config():
var config := GdUnitRunnerConfig.new()
assert_dict(config.to_execute()).is_empty()
assert_dict(config.skipped()).is_empty()
func test_clear_on_initial_config():
var config := GdUnitRunnerConfig.new()
config.clear()
assert_dict(config.to_execute()).is_empty()
assert_dict(config.skipped()).is_empty()
func test_clear_on_filled_config():
var config := GdUnitRunnerConfig.new()
config.add_test_suite("res://foo")
config.skip_test_suite("res://bar")
assert_dict(config.to_execute()).is_not_empty()
assert_dict(config.skipped()).is_not_empty()
# clear it
config.clear()
assert_dict(config.to_execute()).is_empty()
assert_dict(config.skipped()).is_empty()
func test_set_server_port():
var config := GdUnitRunnerConfig.new()
# intial value
assert_int(config.server_port()).is_equal(-1)
config.set_server_port(1000)
assert_int(config.server_port()).is_equal(1000)
func test_self_test():
var config := GdUnitRunnerConfig.new()
# initial is empty
assert_dict(config.to_execute()).is_empty()
# configure self test
var to_execute := config.self_test().to_execute()
assert_dict(to_execute).contains_key_value("res://addons/gdUnit4/test/", PackedStringArray())
func test_add_test_suite():
var config := GdUnitRunnerConfig.new()
# skip should have no affect
config.skip_test_suite("res://bar")
config.add_test_suite("res://foo")
assert_dict(config.to_execute()).contains_key_value("res://foo", PackedStringArray())
# add two more
config.add_test_suite("res://foo2")
config.add_test_suite("res://bar/foo")
assert_dict(config.to_execute())\
.contains_key_value("res://foo", PackedStringArray())\
.contains_key_value("res://foo2", PackedStringArray())\
.contains_key_value("res://bar/foo", PackedStringArray())
func test_add_test_suites():
var config := GdUnitRunnerConfig.new()
# skip should have no affect
config.skip_test_suite("res://bar")
config.add_test_suites(PackedStringArray(["res://foo2", "res://bar/foo", "res://foo1"]))
assert_dict(config.to_execute())\
.contains_key_value("res://foo1", PackedStringArray())\
.contains_key_value("res://foo2", PackedStringArray())\
.contains_key_value("res://bar/foo", PackedStringArray())
func test_add_test_case():
var config := GdUnitRunnerConfig.new()
# skip should have no affect
config.skip_test_suite("res://bar")
config.add_test_case("res://foo1", "testcaseA")
assert_dict(config.to_execute()).contains_key_value("res://foo1", PackedStringArray(["testcaseA"]))
# add two more
config.add_test_case("res://foo1", "testcaseB")
config.add_test_case("res://foo2", "testcaseX")
assert_dict(config.to_execute())\
.contains_key_value("res://foo1", PackedStringArray(["testcaseA", "testcaseB"]))\
.contains_key_value("res://foo2", PackedStringArray(["testcaseX"]))
func test_add_test_suites_and_test_cases_combi():
var config := GdUnitRunnerConfig.new()
config.add_test_suite("res://foo1")
config.add_test_suite("res://foo2")
config.add_test_suite("res://bar/foo")
config.add_test_case("res://foo1", "testcaseA")
config.add_test_case("res://foo1", "testcaseB")
config.add_test_suites(PackedStringArray(["res://foo3", "res://bar/foo3", "res://foo4"]))
assert_dict(config.to_execute())\
.has_size(6)\
.contains_key_value("res://foo1", PackedStringArray(["testcaseA", "testcaseB"]))\
.contains_key_value("res://foo2", PackedStringArray())\
.contains_key_value("res://foo3", PackedStringArray())\
.contains_key_value("res://foo4", PackedStringArray())\
.contains_key_value("res://bar/foo3", PackedStringArray())\
.contains_key_value("res://bar/foo", PackedStringArray())
func test_skip_test_suite():
var config := GdUnitRunnerConfig.new()
config.skip_test_suite("res://foo1")
assert_dict(config.skipped()).contains_key_value("res://foo1", PackedStringArray())
# add two more
config.skip_test_suite("res://foo2")
config.skip_test_suite("res://bar/foo1")
assert_dict(config.skipped())\
.contains_key_value("res://foo1", PackedStringArray())\
.contains_key_value("res://foo2", PackedStringArray())\
.contains_key_value("res://bar/foo1", PackedStringArray())
func test_skip_test_suite_and_test_case():
var possible_paths :PackedStringArray = [
"/foo/MyTest.gd",
"res://foo/MyTest.gd",
"/foo/MyTest.gd:test_x",
"res://foo/MyTest.gd:test_y",
"MyTest",
"MyTest:test",
"MyTestX",
]
var config := GdUnitRunnerConfig.new()
for path in possible_paths:
config.skip_test_suite(path)
assert_dict(config.skipped())\
.has_size(3)\
.contains_key_value("res://foo/MyTest.gd", PackedStringArray(["test_x", "test_y"]))\
.contains_key_value("MyTest", PackedStringArray(["test"]))\
.contains_key_value("MyTestX", PackedStringArray())
func test_skip_test_case():
var config := GdUnitRunnerConfig.new()
config.skip_test_case("res://foo1", "testcaseA")
assert_dict(config.skipped()).contains_key_value("res://foo1", PackedStringArray(["testcaseA"]))
# add two more
config.skip_test_case("res://foo1", "testcaseB")
config.skip_test_case("res://foo2", "testcaseX")
assert_dict(config.skipped())\
.contains_key_value("res://foo1", PackedStringArray(["testcaseA", "testcaseB"]))\
.contains_key_value("res://foo2", PackedStringArray(["testcaseX"]))
func test_load_fail():
var config := GdUnitRunnerConfig.new()
assert_result(config.load_config("invalid_path"))\
.is_error()\
.contains_message("Can't find test runner configuration 'invalid_path'! Please select a test to run.")
func test_save_load():
var config := GdUnitRunnerConfig.new()
# add some dummy conf
config.set_server_port(1000)
config.skip_test_suite("res://bar")
config.add_test_suite("res://foo2")
config.add_test_case("res://foo1", "testcaseA")
var config_file := create_temp_dir("test_save_load") + "/testconf.cfg"
assert_result(config.save_config(config_file)).is_success()
assert_file(config_file).exists()
var config2 := GdUnitRunnerConfig.new()
assert_result(config2.load_config(config_file)).is_success()
# verify the config has original enties
assert_object(config2).is_equal(config).is_not_same(config)

View file

@ -0,0 +1,527 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitSceneRunner.gd'
var _runner :GdUnitSceneRunner
var _scene_spy :Node
func before_test():
_scene_spy = spy("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
_runner = scene_runner(_scene_spy)
assert_inital_mouse_state()
assert_inital_key_state()
# asserts to KeyList Enums
func assert_inital_key_state():
# scacode 4194304-4194415
for key in range(KEY_SPECIAL, KEY_LAUNCHF):
assert_that(Input.is_key_pressed(key)).is_false()
assert_that(Input.is_physical_key_pressed(key)).is_false()
# keycode 32-255
for key in range(KEY_SPACE, KEY_SECTION):
assert_that(Input.is_key_pressed(key)).is_false()
assert_that(Input.is_physical_key_pressed(key)).is_false()
#asserts to Mouse ButtonList Enums
func assert_inital_mouse_state():
for button in [
MOUSE_BUTTON_LEFT,
MOUSE_BUTTON_MIDDLE,
MOUSE_BUTTON_RIGHT,
MOUSE_BUTTON_XBUTTON1,
MOUSE_BUTTON_XBUTTON2,
MOUSE_BUTTON_WHEEL_UP,
MOUSE_BUTTON_WHEEL_DOWN,
MOUSE_BUTTON_WHEEL_LEFT,
MOUSE_BUTTON_WHEEL_RIGHT,
]:
assert_that(Input.is_mouse_button_pressed(button)).is_false()
assert_that(Input.get_mouse_button_mask()).is_equal(0)
func test_reset_to_inital_state_on_release():
var runner = scene_runner("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
# simulate mouse buttons and key press but we never released it
runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
runner.simulate_mouse_button_press(MOUSE_BUTTON_MIDDLE)
runner.simulate_key_press(KEY_0)
runner.simulate_key_press(KEY_X)
await await_idle_frame()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE)).is_true()
assert_that(Input.is_key_pressed(KEY_0)).is_true()
assert_that(Input.is_key_pressed(KEY_X)).is_true()
# unreference the scene runner to enforce reset to initial Input state
runner._notification(NOTIFICATION_PREDELETE)
await await_idle_frame()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_false()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_false()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE)).is_false()
assert_that(Input.is_key_pressed(KEY_0)).is_false()
assert_that(Input.is_key_pressed(KEY_X)).is_false()
func test_simulate_key_press() -> void:
# iterate over some example keys
for key in [KEY_A, KEY_D, KEY_X, KEY_0]:
_runner.simulate_key_press(key)
await await_idle_frame()
var event := InputEventKey.new()
event.keycode = key
event.physical_keycode = key
event.pressed = true
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_key_pressed(key)).is_true()
# verify all this keys are still handled as pressed
assert_that(Input.is_key_pressed(KEY_A)).is_true()
assert_that(Input.is_key_pressed(KEY_D)).is_true()
assert_that(Input.is_key_pressed(KEY_X)).is_true()
assert_that(Input.is_key_pressed(KEY_0)).is_true()
# other keys are not pressed
assert_that(Input.is_key_pressed(KEY_B)).is_false()
assert_that(Input.is_key_pressed(KEY_G)).is_false()
assert_that(Input.is_key_pressed(KEY_Z)).is_false()
assert_that(Input.is_key_pressed(KEY_1)).is_false()
func test_simulate_key_press_with_modifiers() -> void:
# press shift key + A
_runner.simulate_key_press(KEY_SHIFT)
_runner.simulate_key_press(KEY_A)
await await_idle_frame()
# results in two events, first is the shift key is press
var event := InputEventKey.new()
event.keycode = KEY_SHIFT
event.physical_keycode = KEY_SHIFT
event.pressed = true
event.shift_pressed = true
verify(_scene_spy, 1)._input(event)
# second is the comnbination of current press shift and key A
event = InputEventKey.new()
event.keycode = KEY_A
event.physical_keycode = KEY_A
event.pressed = true
event.shift_pressed = true
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_key_pressed(KEY_SHIFT)).is_true()
assert_that(Input.is_key_pressed(KEY_A)).is_true()
func test_simulate_many_keys_press() -> void:
# press and hold keys W and Z
_runner.simulate_key_press(KEY_W)
_runner.simulate_key_press(KEY_Z)
await await_idle_frame()
assert_that(Input.is_key_pressed(KEY_W)).is_true()
assert_that(Input.is_physical_key_pressed(KEY_W)).is_true()
assert_that(Input.is_key_pressed(KEY_Z)).is_true()
assert_that(Input.is_physical_key_pressed(KEY_Z)).is_true()
#now release key w
_runner.simulate_key_release(KEY_W)
await await_idle_frame()
assert_that(Input.is_key_pressed(KEY_W)).is_false()
assert_that(Input.is_physical_key_pressed(KEY_W)).is_false()
assert_that(Input.is_key_pressed(KEY_Z)).is_true()
assert_that(Input.is_physical_key_pressed(KEY_Z)).is_true()
func test_simulate_keypressed_as_action() -> void:
# add custom action `player_jump` for key 'Space' is pressed
var event := InputEventKey.new()
event.keycode = KEY_SPACE
InputMap.add_action("player_jump")
InputMap.action_add_event("player_jump", event)
var runner := scene_runner("res://addons/gdUnit4/test/core/resources/scenes/input_actions/InputEventTestScene.tscn")
# precondition checks
var action_event = InputMap.action_get_events("player_jump")
assert_array(action_event).contains_exactly([event])
assert_bool(Input.is_action_just_released("player_jump", true)).is_false()
assert_bool(Input.is_action_just_released("ui_accept", true)).is_false()
assert_bool(Input.is_action_just_released("ui_select", true)).is_false()
assert_bool(runner.scene()._player_jump_action_released).is_false()
# test a key event is trigger action event
# simulate press space
runner.simulate_key_pressed(KEY_SPACE)
# it is important do not wait for next frame here, otherwise the input action cache is cleared and can't be use to verify
assert_bool(Input.is_action_just_released("player_jump", true)).is_true()
assert_bool(Input.is_action_just_released("ui_accept", true)).is_true()
assert_bool(Input.is_action_just_released("ui_select", true)).is_true()
assert_bool(runner.scene()._player_jump_action_released).is_true()
# test a key event is not trigger the custom action event
# simulate press only space+ctrl
runner._reset_input_to_default()
runner.simulate_key_pressed(KEY_SPACE, false, true)
# it is important do not wait for next frame here, otherwise the input action cache is cleared and can't be use to verify
assert_bool(Input.is_action_just_released("player_jump", true)).is_false()
assert_bool(Input.is_action_just_released("ui_accept", true)).is_false()
assert_bool(Input.is_action_just_released("ui_select", true)).is_false()
assert_bool(runner.scene()._player_jump_action_released).is_false()
# cleanup custom action
InputMap.erase_action("player_jump")
InputMap.action_erase_events("player_jump")
func test_simulate_set_mouse_pos():
# save current global mouse pos
var gmp := _runner.get_global_mouse_position()
# set mouse to pos 100, 100
_runner.set_mouse_pos(Vector2(100, 100))
await await_idle_frame()
var event := InputEventMouseMotion.new()
event.position = Vector2(100, 100)
event.global_position = gmp
verify(_scene_spy, 1)._input(event)
# set mouse to pos 800, 400
gmp = _runner.get_global_mouse_position()
_runner.set_mouse_pos(Vector2(800, 400))
await await_idle_frame()
event = InputEventMouseMotion.new()
event.position = Vector2(800, 400)
event.global_position = gmp
verify(_scene_spy, 1)._input(event)
# and again back to 100,100
gmp = _runner.get_global_mouse_position()
_runner.set_mouse_pos(Vector2(100, 100))
await await_idle_frame()
event = InputEventMouseMotion.new()
event.position = Vector2(100, 100)
event.global_position = gmp
verify(_scene_spy, 1)._input(event)
func test_simulate_set_mouse_pos_with_modifiers():
var is_alt := false
var is_control := false
var is_shift := false
for modifier in [KEY_SHIFT, KEY_CTRL, KEY_ALT]:
is_alt = is_alt or KEY_ALT == modifier
is_control = is_control or KEY_CTRL == modifier
is_shift = is_shift or KEY_SHIFT == modifier
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
# simulate press shift, set mouse pos and final press mouse button
var gmp := _runner.get_global_mouse_position()
_runner.simulate_key_press(modifier)
_runner.set_mouse_pos(Vector2.ZERO)
_runner.simulate_mouse_button_press(mouse_button)
await await_idle_frame()
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.alt_pressed = is_alt
event.ctrl_pressed = is_control
event.shift_pressed = is_shift
event.pressed = true
event.button_index = mouse_button
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_true()
# finally release it
_runner.simulate_mouse_button_release(mouse_button)
await await_idle_frame()
func test_simulate_mouse_move():
_runner.set_mouse_pos(Vector2(10, 10))
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_move(Vector2(400, 100))
await await_idle_frame()
var event = InputEventMouseMotion.new()
event.position = Vector2(400, 100)
event.global_position = gmp
event.relative = Vector2(400, 100) - Vector2(10, 10)
verify(_scene_spy, 1)._input(event)
# move mouse to next pos
gmp = _runner.get_global_mouse_position()
_runner.simulate_mouse_move(Vector2(55, 42))
await await_idle_frame()
event = InputEventMouseMotion.new()
event.position = Vector2(55, 42)
event.global_position = gmp
event.relative = Vector2(55, 42) - Vector2(400, 100)
verify(_scene_spy, 1)._input(event)
func test_simulate_mouse_move_relative():
#OS.window_minimized = false
_runner.set_mouse_pos(Vector2(10, 10))
await await_idle_frame()
assert_that(_runner.get_mouse_position()).is_equal(Vector2(10, 10))
# move the mouse in time of 1 second
# the final position is current + relative = Vector2(10, 10) + (Vector2(900, 400)
await _runner.simulate_mouse_move_relative(Vector2(900, 400), 1)
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(910, 410), Vector2.ONE)
# move the mouse back in time of 0.1 second
# Use the negative value of the previously moved action to move it back to the starting position
await _runner.simulate_mouse_move_relative(Vector2(-900, -400), 0.1)
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(10, 10), Vector2.ONE)
func test_simulate_mouse_move_absolute():
#OS.window_minimized = false
_runner.set_mouse_pos(Vector2(10, 10))
await await_idle_frame()
assert_that(_runner.get_mouse_position()).is_equal(Vector2(10, 10))
# move the mouse in time of 1 second
await _runner.simulate_mouse_move_absolute(Vector2(900, 400), 1)
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(900, 400), Vector2.ONE)
# move the mouse back in time of 0.1 second
await _runner.simulate_mouse_move_absolute(Vector2(10, 10), 0.1)
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(10, 10), Vector2.ONE)
func test_simulate_mouse_button_press_left():
# simulate mouse button press and hold
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
await await_idle_frame()
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(MOUSE_BUTTON_LEFT)
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
func test_simulate_mouse_button_press_left_doubleclick():
# simulate mouse button press double_click
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT, true)
await await_idle_frame()
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.double_click = true
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(MOUSE_BUTTON_LEFT)
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
func test_simulate_mouse_button_press_right():
# simulate mouse button press and hold
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
await await_idle_frame()
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = MOUSE_BUTTON_RIGHT
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(MOUSE_BUTTON_RIGHT)
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
func test_simulate_mouse_button_press_left_and_right():
# simulate mouse button press left+right
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
_runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
await await_idle_frame()
# results in two events, first is left mouse button
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = MOUSE_BUTTON_MASK_LEFT
verify(_scene_spy, 1)._input(event)
# second is left+right and combined mask
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = MOUSE_BUTTON_RIGHT
event.button_mask = MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
assert_that(Input.get_mouse_button_mask()).is_equal(MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT)
func test_simulate_mouse_button_press_left_and_right_and_release():
# simulate mouse button press left+right
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
_runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
await await_idle_frame()
# will results into two events
# first for left mouse button
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = MOUSE_BUTTON_MASK_LEFT
verify(_scene_spy, 1)._input(event)
# second is left+right and combined mask
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = MOUSE_BUTTON_RIGHT
event.button_mask = MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
assert_that(Input.get_mouse_button_mask()).is_equal(MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT)
# now release the right button
gmp = _runner.get_global_mouse_position()
_runner.simulate_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
await await_idle_frame()
# will result in right button press false but stay with mask for left pressed
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = false
event.button_index = MOUSE_BUTTON_RIGHT
event.button_mask = MOUSE_BUTTON_MASK_LEFT
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_false()
assert_that(Input.get_mouse_button_mask()).is_equal(MOUSE_BUTTON_MASK_LEFT)
# finally relase left button
gmp = _runner.get_global_mouse_position()
_runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await await_idle_frame()
# will result in right button press false but stay with mask for left pressed
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = false
event.button_index = MOUSE_BUTTON_LEFT
event.button_mask = 0
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_false()
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_false()
assert_that(Input.get_mouse_button_mask()).is_equal(0)
func test_simulate_mouse_button_pressed():
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
# simulate mouse button press and release
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_pressed(mouse_button)
await await_idle_frame()
# it genrates two events, first for press and second as released
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = mouse_button
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
verify(_scene_spy, 1)._input(event)
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = false
event.button_index = mouse_button
event.button_mask = 0
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false()
verify(_scene_spy, 2)._input(any_class(InputEventMouseButton))
reset(_scene_spy)
func test_simulate_mouse_button_pressed_doubleclick():
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
# simulate mouse button press and release by double_click
var gmp := _runner.get_global_mouse_position()
_runner.simulate_mouse_button_pressed(mouse_button, true)
await await_idle_frame()
# it genrates two events, first for press and second as released
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.double_click = true
event.button_index = mouse_button
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
verify(_scene_spy, 1)._input(event)
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = false
event.double_click = false
event.button_index = mouse_button
event.button_mask = 0
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false()
verify(_scene_spy, 2)._input(any_class(InputEventMouseButton))
reset(_scene_spy)
func test_simulate_mouse_button_press_and_release():
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
var gmp := _runner.get_global_mouse_position()
# simulate mouse button press and release
_runner.simulate_mouse_button_press(mouse_button)
await await_idle_frame()
var event := InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = true
event.button_index = mouse_button
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_true()
# now simulate mouse button release
gmp = _runner.get_global_mouse_position()
_runner.simulate_mouse_button_release(mouse_button)
await await_idle_frame()
event = InputEventMouseButton.new()
event.position = Vector2.ZERO
event.global_position = gmp
event.pressed = false
event.button_index = mouse_button
#event.button_mask = 0
verify(_scene_spy, 1)._input(event)
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false()

View file

@ -0,0 +1,356 @@
# GdUnit generated TestSuite
class_name GdUnitSceneRunnerTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd'
# loads the test runner and register for auto freeing after test
func load_test_scene() -> Node:
return auto_free(load("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn").instantiate())
func before():
# use a dedicated FPS because we calculate frames by time
Engine.set_max_fps(60)
func after():
Engine.set_max_fps(0)
func test_get_property() -> void:
var runner := scene_runner(load_test_scene())
assert_that(runner.get_property("_box1")).is_instanceof(ColorRect)
assert_that(runner.get_property("_invalid")).is_equal("The property '_invalid' not exist checked loaded scene.")
assert_that(runner.get_property("_nullable")).is_null()
func test_set_property() -> void:
var runner := scene_runner(load_test_scene())
assert_that(runner.set_property("_invalid", 42)).is_equal(false)
assert_that(runner.set_property("_nullable", RefCounted.new())).is_equal(true)
assert_that(runner.get_property("_nullable")).is_instanceof(RefCounted)
func test_invoke_method() -> void:
var runner := scene_runner(load_test_scene())
assert_that(runner.invoke("add", 10, 12)).is_equal(22)
assert_that(runner.invoke("sub", 10, 12)).is_equal("The method 'sub' not exist checked loaded scene.")
@warning_ignore("unused_parameter")
func test_simulate_frames(timeout = 5000) -> void:
var runner := scene_runner(load_test_scene())
var box1 :ColorRect = runner.get_property("_box1")
# initial is white
assert_object(box1.color).is_equal(Color.WHITE)
# start color cycle by invoke the function 'start_color_cycle'
runner.invoke("start_color_cycle")
# we wait for 10 frames
await runner.simulate_frames(10)
# after 10 frame is still white
assert_object(box1.color).is_equal(Color.WHITE)
# we wait 30 more frames
await runner.simulate_frames(30)
# after 40 frames the box one should be changed to red
assert_object(box1.color).is_equal(Color.RED)
@warning_ignore("unused_parameter")
func test_simulate_frames_withdelay(timeout = 4000) -> void:
var runner := scene_runner(load_test_scene())
var box1 :ColorRect = runner.get_property("_box1")
# initial is white
assert_object(box1.color).is_equal(Color.WHITE)
# start color cycle by invoke the function 'start_color_cycle'
runner.invoke("start_color_cycle")
# we wait for 10 frames each with a 50ms delay
await runner.simulate_frames(10, 50)
# after 10 frame and in sum 500ms is should be changed to red
assert_object(box1.color).is_equal(Color.RED)
@warning_ignore("unused_parameter")
func test_run_scene_colorcycle(timeout=2000) -> void:
var runner := scene_runner(load_test_scene())
var box1 :ColorRect = runner.get_property("_box1")
# verify inital color
assert_object(box1.color).is_equal(Color.WHITE)
# start color cycle by invoke the function 'start_color_cycle'
runner.invoke("start_color_cycle")
# await for each color cycle is emited
await runner.await_signal("panel_color_change", [box1, Color.RED])
assert_object(box1.color).is_equal(Color.RED)
await runner.await_signal("panel_color_change", [box1, Color.BLUE])
assert_object(box1.color).is_equal(Color.BLUE)
await runner.await_signal("panel_color_change", [box1, Color.GREEN])
assert_object(box1.color).is_equal(Color.GREEN)
func test_simulate_scene_inteaction_by_press_enter(timeout=2000) -> void:
var runner := scene_runner(load_test_scene())
# inital no spell is fired
assert_object(runner.find_child("Spell")).is_null()
# fire spell be pressing enter key
runner.simulate_key_pressed(KEY_ENTER)
# wait until next frame
await await_idle_frame()
# verify a spell is created
assert_object(runner.find_child("Spell")).is_not_null()
# wait until spell is explode after around 1s
var spell = runner.find_child("Spell")
if spell == null:
return
await await_signal_on(spell, "spell_explode", [spell], timeout)
# verify spell is removed when is explode
assert_object(runner.find_child("Spell")).is_null()
# mock on a runner and spy on created spell
func test_simulate_scene_inteaction_in_combination_with_spy():
var spy_ = spy(load_test_scene())
# create a runner runner
var runner := scene_runner(spy_)
# simulate a key event to fire a spell
runner.simulate_key_pressed(KEY_ENTER)
verify(spy_).create_spell()
var spell = runner.find_child("Spell")
assert_that(spell).is_not_null()
assert_that(spell.is_connected("spell_explode", Callable(spy_, "_destroy_spell"))).is_true()
func test_simulate_scene_interact_with_buttons():
var spyed_scene = spy("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
var runner := scene_runner(spyed_scene)
# test button 1 interaction
await await_millis(1000)
runner.set_mouse_pos(Vector2(60, 20))
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await await_idle_frame()
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box1, Color.RED)
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box1, Color.GRAY)
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box2, any_color())
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box3, any_color())
# test button 2 interaction
reset(spyed_scene)
await await_millis(1000)
runner.set_mouse_pos(Vector2(160, 20))
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await await_idle_frame()
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box1, any_color())
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box2, Color.RED)
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box2, Color.GRAY)
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box3, any_color())
# test button 3 interaction (is changed after 1s to gray)
reset(spyed_scene)
await await_millis(1000)
runner.set_mouse_pos(Vector2(260, 20))
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
await await_idle_frame()
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box1, any_color())
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box2, any_color())
# is changed to red
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box3, Color.RED)
# no gray
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box3, Color.GRAY)
# after one second is changed to gray
await await_millis(1200)
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box3, Color.GRAY)
func test_await_func_without_time_factor() -> void:
var runner := scene_runner(load_test_scene())
await runner.await_func("color_cycle").is_equal("black")
func test_await_func_with_time_factor() -> void:
var runner := scene_runner(load_test_scene())
# set max time factor to minimize waiting time checked `runner.wait_func`
runner.set_time_factor(10)
await runner.await_func("color_cycle").wait_until(200).is_equal("black")
func test_await_signal_without_time_factor() -> void:
var runner := scene_runner(load_test_scene())
var box1 :ColorRect = runner.get_property("_box1")
runner.invoke("start_color_cycle")
await runner.await_signal("panel_color_change", [box1, Color.RED])
await runner.await_signal("panel_color_change", [box1, Color.BLUE])
await runner.await_signal("panel_color_change", [box1, Color.GREEN])
(
# should be interrupted is will never change to Color.KHAKI
await assert_failure_await(func x(): await runner.await_signal( "panel_color_change", [box1, Color.KHAKI], 300))
).has_message("await_signal_on(panel_color_change, [%s, %s]) timed out after 300ms" % [str(box1), str(Color.KHAKI)])\
.has_line(205)
func test_await_signal_with_time_factor() -> void:
var runner := scene_runner(load_test_scene())
var box1 :ColorRect = runner.get_property("_box1")
# set max time factor to minimize waiting time checked `runner.wait_func`
runner.set_time_factor(10)
runner.invoke("start_color_cycle")
await runner.await_signal("panel_color_change", [box1, Color.RED], 100)
await runner.await_signal("panel_color_change", [box1, Color.BLUE], 100)
await runner.await_signal("panel_color_change", [box1, Color.GREEN], 100)
(
# should be interrupted is will never change to Color.KHAKI
await assert_failure_await(func x(): await runner.await_signal("panel_color_change", [box1, Color.KHAKI], 30))
).has_message("await_signal_on(panel_color_change, [%s, %s]) timed out after 30ms" % [str(box1), str(Color.KHAKI)])\
.has_line(222)
func test_simulate_until_signal() -> void:
var runner := scene_runner(load_test_scene())
var box1 :ColorRect = runner.get_property("_box1")
# set max time factor to minimize waiting time checked `runner.wait_func`
runner.invoke("start_color_cycle")
await runner.simulate_until_signal("panel_color_change", box1, Color.RED)
await runner.simulate_until_signal("panel_color_change", box1, Color.BLUE)
await runner.simulate_until_signal("panel_color_change", box1, Color.GREEN)
@warning_ignore("unused_parameter")
func test_simulate_until_object_signal(timeout=2000) -> void:
var runner := scene_runner(load_test_scene())
# inital no spell is fired
assert_object(runner.find_child("Spell")).is_null()
# fire spell be pressing enter key
runner.simulate_key_pressed(KEY_ENTER)
# wait until next frame
await await_idle_frame()
var spell = runner.find_child("Spell")
prints(spell)
# simmulate scene until the spell is explode
await runner.simulate_until_object_signal(spell, "spell_explode", spell)
# verify spell is removed when is explode
assert_object(runner.find_child("Spell")).is_null()
func test_runner_by_null_instance() -> void:
var runner := scene_runner(null)
assert_object(runner._current_scene).is_null()
func test_runner_by_invalid_resource_path() -> void:
# not existing scene
assert_object(scene_runner("res://test_scene.tscn")._current_scene).is_null()
# not a path to a scene
assert_object(scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.gd")._current_scene).is_null()
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)
# 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_invalid_scene_instance() -> void:
var scene = RefCounted.new()
var runner := scene_runner(scene)
assert_object(runner._current_scene).is_null()
func test_runner_by_scene_instance() -> void:
var scene = load("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn").instantiate()
var runner := scene_runner(scene)
assert_object(runner.scene()).is_instanceof(Node2D)
# verify the scene is freed when the runner is freed
runner._notification(NOTIFICATION_PREDELETE)
# give engine time to free the resources
await await_idle_frame()
# scene runner using external scene do not free the scene at exit
assert_bool(is_instance_valid(scene)).is_true()
# needs to be manually freed
scene.free()
func test_mouse_drag_and_drop() -> void:
var spy_scene = spy("res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropTestScene.tscn")
var runner := scene_runner(spy_scene)
var slot_left :TextureRect = $"/root/DragAndDropScene/left/TextureRect"
var slot_right :TextureRect = $"/root/DragAndDropScene/right/TextureRect"
var save_mouse_pos := get_tree().root.get_mouse_position()
# set inital mouse pos over the left slot
var mouse_pos := slot_left.global_position + Vector2(10, 10)
runner.set_mouse_pos(mouse_pos)
await await_millis(1000)
await await_idle_frame()
var event := InputEventMouseMotion.new()
event.position = mouse_pos
event.global_position = save_mouse_pos
verify(spy_scene, 1)._gui_input(event)
runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
await await_idle_frame()
assert_bool(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
# start drag&drop to left pannel
for i in 20:
runner.simulate_mouse_move(mouse_pos + Vector2(i*.5*i, 0))
await await_millis(40)
runner.simulate_mouse_button_release(MOUSE_BUTTON_LEFT)
await await_idle_frame()
assert_that(slot_right.texture).is_equal(slot_left.texture)
func test_runner_GD_356() -> void:
# to avoid reporting the expected push_error as test failure we disable it
ProjectSettings.set_setting(GdUnitSettings.REPORT_PUSH_ERRORS, false)
var runner = scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn")
var player = runner.invoke("find_child", "Player", true, false)
assert_that(player).is_not_null()
await assert_func(player, "is_on_floor").wait_until(500).is_true()
assert_that(runner.scene()).is_not_null()
# run simulate_mouse_move_relative without await to reproduce https://github.com/MikeSchulze/gdUnit4/issues/356
# this results into releasing the scene while `simulate_mouse_move_relative` is processing the mouse move
runner.simulate_mouse_move_relative(Vector2(100, 100), 1.0)
assert_that(runner.scene()).is_not_null()
# we override the scene runner function for test purposes to hide push_error notifications
func scene_runner(scene, verbose := false) -> GdUnitSceneRunner:
return auto_free(GdUnitSceneRunnerImpl.new(scene, verbose, true))

View file

@ -0,0 +1,155 @@
# GdUnit generated TestSuite
class_name GdUnitSettingsTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitSettings.gd'
const MAIN_CATEGORY = "unit_test"
const CATEGORY_A = MAIN_CATEGORY + "/category_a"
const CATEGORY_B = MAIN_CATEGORY + "/category_b"
const TEST_PROPERTY_A = CATEGORY_A + "/a/prop_a"
const TEST_PROPERTY_B = CATEGORY_A + "/a/prop_b"
const TEST_PROPERTY_C = CATEGORY_A + "/a/prop_c"
const TEST_PROPERTY_D = CATEGORY_B + "/prop_d"
const TEST_PROPERTY_E = CATEGORY_B + "/c/prop_e"
const TEST_PROPERTY_F = CATEGORY_B + "/c/prop_f"
const TEST_PROPERTY_G = CATEGORY_B + "/a/prop_g"
func before() -> void:
GdUnitSettings.dump_to_tmp()
func after() -> void:
GdUnitSettings.restore_dump_from_tmp()
func before_test() -> void:
GdUnitSettings.create_property_if_need(TEST_PROPERTY_A, true, "helptext TEST_PROPERTY_A.")
GdUnitSettings.create_property_if_need(TEST_PROPERTY_B, false, "helptext TEST_PROPERTY_B.")
GdUnitSettings.create_property_if_need(TEST_PROPERTY_C, 100, "helptext TEST_PROPERTY_C.")
GdUnitSettings.create_property_if_need(TEST_PROPERTY_D, true, "helptext TEST_PROPERTY_D.")
GdUnitSettings.create_property_if_need(TEST_PROPERTY_E, false, "helptext TEST_PROPERTY_E.")
GdUnitSettings.create_property_if_need(TEST_PROPERTY_F, "abc", "helptext TEST_PROPERTY_F.")
GdUnitSettings.create_property_if_need(TEST_PROPERTY_G, 200, "helptext TEST_PROPERTY_G.")
func after_test() -> void:
ProjectSettings.clear(TEST_PROPERTY_A)
ProjectSettings.clear(TEST_PROPERTY_B)
ProjectSettings.clear(TEST_PROPERTY_C)
ProjectSettings.clear(TEST_PROPERTY_D)
ProjectSettings.clear(TEST_PROPERTY_E)
ProjectSettings.clear(TEST_PROPERTY_F)
ProjectSettings.clear(TEST_PROPERTY_G)
func test_list_settings() -> void:
var settingsA := GdUnitSettings.list_settings(CATEGORY_A)
assert_array(settingsA).extractv(extr("name"), extr("type"), extr("value"), extr("default"), extr("help"))\
.contains_exactly_in_any_order([
tuple(TEST_PROPERTY_A, TYPE_BOOL, true, true, "helptext TEST_PROPERTY_A."),
tuple(TEST_PROPERTY_B, TYPE_BOOL,false, false, "helptext TEST_PROPERTY_B."),
tuple(TEST_PROPERTY_C, TYPE_INT, 100, 100, "helptext TEST_PROPERTY_C.")
])
var settingsB := GdUnitSettings.list_settings(CATEGORY_B)
assert_array(settingsB).extractv(extr("name"), extr("type"), extr("value"), extr("default"), extr("help"))\
.contains_exactly_in_any_order([
tuple(TEST_PROPERTY_D, TYPE_BOOL, true, true, "helptext TEST_PROPERTY_D."),
tuple(TEST_PROPERTY_E, TYPE_BOOL, false, false, "helptext TEST_PROPERTY_E."),
tuple(TEST_PROPERTY_F, TYPE_STRING, "abc", "abc", "helptext TEST_PROPERTY_F."),
tuple(TEST_PROPERTY_G, TYPE_INT, 200, 200, "helptext TEST_PROPERTY_G.")
])
func test_enum_property() -> void:
var value_set :PackedStringArray = GdUnitSettings.NAMING_CONVENTIONS.keys()
GdUnitSettings.create_property_if_need("test/enum", GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT, "help", value_set)
var property := GdUnitSettings.get_property("test/enum")
assert_that(property.default()).is_equal(GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
assert_that(property.value()).is_equal(GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
assert_that(property.type()).is_equal(TYPE_INT)
assert_that(property.help()).is_equal('help ["AUTO_DETECT", "SNAKE_CASE", "PASCAL_CASE"]')
assert_that(property.value_set()).is_equal(value_set)
func test_migrate_property_change_key() -> void:
# setup old property
var old_property_X = "/category_patch/group_old/name"
var new_property_X = "/category_patch/group_new/name"
GdUnitSettings.create_property_if_need(old_property_X, "foo")
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_equal("foo")
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_null()
var old_property := GdUnitSettings.get_property(old_property_X)
# migrate
GdUnitSettings.migrate_property(old_property.name(),\
new_property_X,\
old_property.default(),\
old_property.help())
var new_property := GdUnitSettings.get_property(new_property_X)
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_null()
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_equal("foo")
assert_object(new_property).is_not_equal(old_property)
assert_str(new_property.value()).is_equal(old_property.value())
assert_array(new_property.value_set()).is_equal(old_property.value_set())
assert_int(new_property.type()).is_equal(old_property.type())
assert_str(new_property.default()).is_equal(old_property.default())
assert_str(new_property.help()).is_equal(old_property.help())
# cleanup
ProjectSettings.clear(new_property_X)
func test_migrate_property_change_value() -> void:
# setup old property
var old_property_X = "/category_patch/group_old/name"
var new_property_X = "/category_patch/group_new/name"
GdUnitSettings.create_property_if_need(old_property_X, "foo", "help to foo")
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_equal("foo")
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_null()
var old_property := GdUnitSettings.get_property(old_property_X)
# migrate property
GdUnitSettings.migrate_property(old_property.name(),\
new_property_X,\
old_property.default(),\
old_property.help(),\
func(_value): return "bar")
var new_property := GdUnitSettings.get_property(new_property_X)
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_null()
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_equal("bar")
assert_object(new_property).is_not_equal(old_property)
assert_str(new_property.value()).is_equal("bar")
assert_array(new_property.value_set()).is_equal(old_property.value_set())
assert_int(new_property.type()).is_equal(old_property.type())
assert_str(new_property.default()).is_equal(old_property.default())
assert_str(new_property.help()).is_equal(old_property.help())
# cleanup
ProjectSettings.clear(new_property_X)
const TEST_ROOT_FOLDER := "gdunit4/settings/test/test_root_folder"
const HELP_TEST_ROOT_FOLDER := "Sets the root folder where test-suites located/generated."
func test_migrate_properties_v215() -> void:
# rebuild original settings
GdUnitSettings.create_property_if_need(TEST_ROOT_FOLDER, "test", HELP_TEST_ROOT_FOLDER)
ProjectSettings.set_setting(TEST_ROOT_FOLDER, "xxx")
# migrate
GdUnitSettings.migrate_properties()
# verify
var property := GdUnitSettings.get_property(GdUnitSettings.TEST_LOOKUP_FOLDER)
assert_str(property.value()).is_equal("xxx")
assert_array(property.value_set()).is_empty()
assert_int(property.type()).is_equal(TYPE_STRING)
assert_str(property.default()).is_equal(GdUnitSettings.DEFAULT_TEST_LOOKUP_FOLDER)
assert_str(property.help()).is_equal(GdUnitSettings.HELP_TEST_LOOKUP_FOLDER)
assert_that(GdUnitSettings.get_property(TEST_ROOT_FOLDER)).is_null()
ProjectSettings.clear(GdUnitSettings.TEST_LOOKUP_FOLDER)

View file

@ -0,0 +1,46 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdUnitSignalAwaiterTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitSignalAwaiter.gd'
class Monster extends Node:
signal move(value :float)
signal slide(value, x, z )
var _pos :float = 0.0
func _process(_delta):
_pos += 0.2
emit_signal("move", _pos)
emit_signal("slide", _pos, 1 , 2)
func test_on_signal_with_single_arg() -> void:
var monster = auto_free(Monster.new())
add_child(monster)
var signal_arg = await await_signal_on(monster, "move", [1.0])
assert_float(signal_arg).is_equal(1.0)
remove_child(monster)
func test_on_signal_with_many_args() -> void:
var monster = auto_free(Monster.new())
add_child(monster)
var signal_args = await await_signal_on(monster, "slide", [1.0, 1, 2])
assert_array(signal_args).is_equal([1.0, 1, 2])
remove_child(monster)
func test_on_signal_fail() -> void:
var monster = auto_free(Monster.new())
add_child(monster)
(
await assert_failure_await( func x(): await await_signal_on(monster, "move", [4.0]))
).has_message("await_signal_on(move, [4]) timed out after 2000ms")
remove_child(monster)

View file

@ -0,0 +1,11 @@
extends GdUnitTestSuite
func test_instance() -> void:
var n = GdUnitSingleton.instance("singelton_test", func(): return Node.new() )
assert_object(n).is_instanceof(Node)
assert_bool(is_instance_valid(n)).is_true()
# free the singleton
GdUnitSingleton.unregister("singelton_test")
assert_bool(is_instance_valid(n)).is_false()

View file

@ -0,0 +1,65 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name GdUnitTestSuiteBuilderTest
extends GdUnitTestSuite
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitTestSuiteBuilder.gd'
var _example_source_gd :String
func before_test():
var temp := create_temp_dir("examples")
var result := GdUnitFileAccess.copy_file("res://addons/gdUnit4/test/core/resources/sources/test_person.gd", temp)
assert_result(result).is_success()
_example_source_gd = result.value() as String
func after_test():
clean_temp_dir()
func assert_tests(test_suite :Script) -> GdUnitArrayAssert:
# needs to be reload to get fresh method list
test_suite.reload()
var methods := test_suite.get_script_method_list()
var test_cases := Array()
for method in methods:
if method.name.begins_with("test_"):
test_cases.append(method.name)
return assert_array(test_cases)
func test_create_gd_success() -> void:
var source := load(_example_source_gd)
# create initial test suite based checked function selected by line 9
var result := GdUnitTestSuiteBuilder.create(source, 9)
assert_result(result).is_success()
var info := result.value() as Dictionary
assert_str(info.get("path")).is_equal("user://tmp/test/examples/test_person_test.gd")
assert_int(info.get("line")).is_equal(11)
assert_tests(load(info.get("path"))).contains_exactly(["test_first_name"])
# create additional test checked existing suite based checked function selected by line 15
result = GdUnitTestSuiteBuilder.create(source, 15)
assert_result(result).is_success()
info = result.value() as Dictionary
assert_str(info.get("path")).is_equal("user://tmp/test/examples/test_person_test.gd")
assert_int(info.get("line")).is_equal(16)
assert_tests(load(info.get("path"))).contains_exactly_in_any_order(["test_first_name", "test_fully_name"])
func test_create_gd_fail() -> void:
var source := load(_example_source_gd)
# attempt to create an initial test suite based checked the function selected in line 8, which has no function definition
var result := GdUnitTestSuiteBuilder.create(source, 8)
assert_result(result).is_error().contains_message("No function found at line: 8.")

View file

@ -0,0 +1,372 @@
# GdUnit generated TestSuite
#warning-ignore-all:unused_argument
#warning-ignore-all:return_value_discarded
class_name TestSuiteScannerTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd'
func before_test():
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
clean_temp_dir()
func after():
clean_temp_dir()
func resolve_path(source_file :String) -> String:
return GdUnitTestSuiteScanner.resolve_test_suite_path(source_file, "_test_")
func test_resolve_test_suite_path_project() -> void:
# if no `src` folder found use test folder as root
assert_str(resolve_path("res://foo.gd")).is_equal("res://_test_/foo_test.gd")
assert_str(resolve_path("res://project_name/module/foo.gd")).is_equal("res://_test_/project_name/module/foo_test.gd")
# otherwise build relative to 'src'
assert_str(resolve_path("res://src/foo.gd")).is_equal("res://_test_/foo_test.gd")
assert_str(resolve_path("res://project_name/src/foo.gd")).is_equal("res://project_name/_test_/foo_test.gd")
assert_str(resolve_path("res://project_name/src/module/foo.gd")).is_equal("res://project_name/_test_/module/foo_test.gd")
func test_resolve_test_suite_path_plugins() -> void:
assert_str(resolve_path("res://addons/plugin_a/foo.gd")).is_equal("res://addons/plugin_a/_test_/foo_test.gd")
assert_str(resolve_path("res://addons/plugin_a/src/foo.gd")).is_equal("res://addons/plugin_a/_test_/foo_test.gd")
func test_resolve_test_suite_path__no_test_root():
# from a project path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/models/events/ModelChangedEvent.gd", ""))\
.is_equal("res://project/src/models/events/ModelChangedEventTest.gd")
# from a plugin path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/src/models/events/ModelChangedEvent.gd", ""))\
.is_equal("res://addons/MyPlugin/src/models/events/ModelChangedEventTest.gd")
# located in user path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/src/models/events/ModelChangedEvent.gd", ""))\
.is_equal("user://project/src/models/events/ModelChangedEventTest.gd")
func test_resolve_test_suite_path__path_contains_src_folder():
# from a project path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/models/events/ModelChangedEvent.gd"))\
.is_equal("res://project/test/models/events/ModelChangedEventTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/models/events/ModelChangedEvent.gd", "custom_test"))\
.is_equal("res://project/custom_test/models/events/ModelChangedEventTest.gd")
# from a plugin path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/src/models/events/ModelChangedEvent.gd"))\
.is_equal("res://addons/MyPlugin/test/models/events/ModelChangedEventTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/src/models/events/ModelChangedEvent.gd", "custom_test"))\
.is_equal("res://addons/MyPlugin/custom_test/models/events/ModelChangedEventTest.gd")
# located in user path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/src/models/events/ModelChangedEvent.gd"))\
.is_equal("user://project/test/models/events/ModelChangedEventTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/src/models/events/ModelChangedEvent.gd", "custom_test"))\
.is_equal("user://project/custom_test/models/events/ModelChangedEventTest.gd")
func test_resolve_test_suite_path__path_not_contains_src_folder():
# from a project path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/models/events/ModelChangedEvent.gd"))\
.is_equal("res://test/project/models/events/ModelChangedEventTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/models/events/ModelChangedEvent.gd", "custom_test"))\
.is_equal("res://custom_test/project/models/events/ModelChangedEventTest.gd")
# from a plugin path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/models/events/ModelChangedEvent.gd"))\
.is_equal("res://addons/MyPlugin/test/models/events/ModelChangedEventTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/models/events/ModelChangedEvent.gd", "custom_test"))\
.is_equal("res://addons/MyPlugin/custom_test/models/events/ModelChangedEventTest.gd")
# located in user path
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/models/events/ModelChangedEvent.gd"))\
.is_equal("user://test/project/models/events/ModelChangedEventTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/models/events/ModelChangedEvent.gd", "custom_test"))\
.is_equal("user://custom_test/project/models/events/ModelChangedEventTest.gd")
func test_test_suite_exists():
var path_exists := "res://addons/gdUnit4/test/resources/core/GeneratedPersonTest.gd"
var path_not_exists := "res://addons/gdUnit4/test/resources/core/FamilyTest.gd"
assert_that(GdUnitTestSuiteScanner.test_suite_exists(path_exists)).is_true()
assert_that(GdUnitTestSuiteScanner.test_suite_exists(path_not_exists)).is_false()
func test_test_case_exists():
var test_suite_path := "res://addons/gdUnit4/test/resources/core/GeneratedPersonTest.gd"
assert_that(GdUnitTestSuiteScanner.test_case_exists(test_suite_path, "name")).is_true()
assert_that(GdUnitTestSuiteScanner.test_case_exists(test_suite_path, "last_name")).is_false()
func test_create_test_suite_pascal_case_path():
var temp_dir := create_temp_dir("TestSuiteScannerTest")
# checked source with class_name is set
var source_path := "res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd"
var suite_path := temp_dir + "/test/MyClassTest1.gd"
var result := GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
assert_that(result.is_success()).is_true()
assert_str(result.value()).is_equal(suite_path)
assert_file(result.value()).exists()\
.is_file()\
.is_script()\
.contains_exactly([
"# GdUnit generated TestSuite",
"class_name PascalCaseWithClassNameTest",
"extends GdUnitTestSuite",
"@warning_ignore('unused_parameter')",
"@warning_ignore('return_value_discarded')",
"",
"# TestSuite generated from",
"const __source = '%s'" % source_path,
""])
# checked source with class_name is NOT set
source_path = "res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd"
suite_path = temp_dir + "/test/MyClassTest2.gd"
result = GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
assert_that(result.is_success()).is_true()
assert_str(result.value()).is_equal(suite_path)
assert_file(result.value()).exists()\
.is_file()\
.is_script()\
.contains_exactly([
"# GdUnit generated TestSuite",
"class_name PascalCaseWithoutClassNameTest",
"extends GdUnitTestSuite",
"@warning_ignore('unused_parameter')",
"@warning_ignore('return_value_discarded')",
"",
"# TestSuite generated from",
"const __source = '%s'" % source_path,
""])
func test_create_test_suite_snake_case_path():
var temp_dir := create_temp_dir("TestSuiteScannerTest")
# checked source with class_name is set
var source_path :="res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd"
var suite_path := temp_dir + "/test/my_class_test1.gd"
var result := GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
assert_that(result.is_success()).is_true()
assert_str(result.value()).is_equal(suite_path)
assert_file(result.value()).exists()\
.is_file()\
.is_script()\
.contains_exactly([
"# GdUnit generated TestSuite",
"class_name SnakeCaseWithClassNameTest",
"extends GdUnitTestSuite",
"@warning_ignore('unused_parameter')",
"@warning_ignore('return_value_discarded')",
"",
"# TestSuite generated from",
"const __source = '%s'" % source_path,
""])
# checked source with class_name is NOT set
source_path ="res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd"
suite_path = temp_dir + "/test/my_class_test2.gd"
result = GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
assert_that(result.is_success()).is_true()
assert_str(result.value()).is_equal(suite_path)
assert_file(result.value()).exists()\
.is_file()\
.is_script()\
.contains_exactly([
"# GdUnit generated TestSuite",
"class_name SnakeCaseWithoutClassNameTest",
"extends GdUnitTestSuite",
"@warning_ignore('unused_parameter')",
"@warning_ignore('return_value_discarded')",
"",
"# TestSuite generated from",
"const __source = '%s'" % source_path,
""])
func test_create_test_case():
# store test class checked temp dir
var tmp_path := create_temp_dir("TestSuiteScannerTest")
var source_path := "res://addons/gdUnit4/test/resources/core/Person.gd"
# generate new test suite with test 'test_last_name()'
var test_suite_path = tmp_path + "/test/PersonTest.gd"
var result := GdUnitTestSuiteScanner.create_test_case(test_suite_path, "last_name", source_path)
assert_that(result.is_success()).is_true()
var info :Dictionary = result.value()
assert_int(info.get("line")).is_equal(11)
assert_file(info.get("path")).exists()\
.is_file()\
.is_script()\
.contains_exactly([
"# GdUnit generated TestSuite",
"class_name PersonTest",
"extends GdUnitTestSuite",
"@warning_ignore('unused_parameter')",
"@warning_ignore('return_value_discarded')",
"",
"# TestSuite generated from",
"const __source = '%s'" % source_path,
"",
"",
"func test_last_name() -> void:",
" # remove this line and complete your test",
" assert_not_yet_implemented()",
""])
# try to add again
result = GdUnitTestSuiteScanner.create_test_case(test_suite_path, "last_name", source_path)
assert_that(result.is_success()).is_true()
assert_that(result.value()).is_equal({"line" : 16, "path": test_suite_path})
# https://github.com/MikeSchulze/gdUnit4/issues/25
func test_build_test_suite_path() -> void:
# checked project root
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://new_script.gd")).is_equal("res://test/new_script_test.gd")
# checked project without src folder
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://foo/bar/new_script.gd")).is_equal("res://test/foo/bar/new_script_test.gd")
# project code structured by 'src'
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://src/new_script.gd")).is_equal("res://test/new_script_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://src/foo/bar/new_script.gd")).is_equal("res://test/foo/bar/new_script_test.gd")
# folder name contains 'src' in name
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://foo/srcare/new_script.gd")).is_equal("res://test/foo/srcare/new_script_test.gd")
# checked plugins without src folder
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/plugin/foo/bar/new_script.gd")).is_equal("res://addons/plugin/test/foo/bar/new_script_test.gd")
# plugin code structured by 'src'
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/plugin/src/foo/bar/new_script.gd")).is_equal("res://addons/plugin/test/foo/bar/new_script_test.gd")
# checked user temp folder
var tmp_path := create_temp_dir("projectX/entity")
var source_path := tmp_path + "/Person.gd"
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path(source_path)).is_equal("user://tmp/test/projectX/entity/PersonTest.gd")
func test_parse_and_add_test_cases() -> void:
var default_time := GdUnitSettings.test_timeout()
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
# fake a test suite
var test_suite :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
test_suite.set_script( load("res://addons/gdUnit4/test/core/resources/test_script_with_arguments.gd"))
var test_case_names := PackedStringArray([
"test_no_args",
"test_with_timeout",
"test_with_fuzzer",
"test_with_fuzzer_iterations",
"test_with_multible_fuzzers",
"test_multiline_arguments_a",
"test_multiline_arguments_b",
"test_multiline_arguments_c"])
scanner._parse_and_add_test_cases(test_suite, test_suite.get_script(), test_case_names)
assert_array(test_suite.get_children())\
.extractv(extr("get_name"), extr("timeout"), extr("fuzzer_arguments"), extr("iterations"))\
.contains_exactly([
tuple("test_no_args", default_time, [], Fuzzer.ITERATION_DEFAULT_COUNT),
tuple("test_with_timeout", 2000, [], Fuzzer.ITERATION_DEFAULT_COUNT),
tuple("test_with_fuzzer", default_time, [GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)")], Fuzzer.ITERATION_DEFAULT_COUNT),
tuple("test_with_fuzzer_iterations", default_time, [GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)")], 10),
tuple("test_with_multible_fuzzers", default_time, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 10),
tuple("test_multiline_arguments_a", default_time, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 42),
tuple("test_multiline_arguments_b", default_time, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 23),
tuple("test_multiline_arguments_c", 2000, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 33)
])
func test_scan_by_inheritance_class_name() -> void:
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
var test_suites := scanner.scan("res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/")
assert_array(test_suites).has_size(3)
# sort by names
test_suites.sort_custom(func by_name(a, b): return a.get_name() <= b.get_name())
assert_array(test_suites).extract("get_name")\
.contains_exactly(["BaseTest", "ExtendedTest", "ExtendsExtendedTest"])
assert_array(test_suites).extract("get_script.get_path")\
.contains_exactly([
"res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/BaseTest.gd",
"res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/ExtendedTest.gd",
"res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/ExtendsExtendedTest.gd"])
assert_array(test_suites[0].get_children()).extract("name")\
.contains_same_exactly_in_any_order([&"test_foo1"])
assert_array(test_suites[1].get_children()).extract("name")\
.contains_same_exactly_in_any_order([&"test_foo2", &"test_foo1"])
assert_array(test_suites[2].get_children()).extract("name")\
.contains_same_exactly_in_any_order([&"test_foo3", &"test_foo2", &"test_foo1"])
# finally free all scaned test suites
for ts in test_suites:
ts.free()
func test_scan_by_inheritance_class_path() -> void:
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
var test_suites := scanner.scan("res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/")
assert_array(test_suites).extractv(extr("get_name"), extr("get_script.get_path"), extr("get_children.get_name"))\
.contains_exactly_in_any_order([
tuple("BaseTest", "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/BaseTest.gd", [&"test_foo1"]),
tuple("ExtendedTest","res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/ExtendedTest.gd", [&"test_foo2", &"test_foo1"]),
tuple("ExtendsExtendedTest", "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/ExtendsExtendedTest.gd", [&"test_foo3", &"test_foo2", &"test_foo1"])
])
# finally free all scaned test suites
for ts in test_suites:
ts.free()
func test_get_test_case_line_number() -> void:
assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "get_test_case_line_number")).is_equal(317)
assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "unknown")).is_equal(-1)
func test__to_naming_convention() -> void:
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
assert_str(GdUnitTestSuiteScanner._to_naming_convention("MyClass")).is_equal("MyClassTest")
assert_str(GdUnitTestSuiteScanner._to_naming_convention("my_class")).is_equal("my_class_test")
assert_str(GdUnitTestSuiteScanner._to_naming_convention("myclass")).is_equal("myclass_test")
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.SNAKE_CASE)
assert_str(GdUnitTestSuiteScanner._to_naming_convention("MyClass")).is_equal("my_class_test")
assert_str(GdUnitTestSuiteScanner._to_naming_convention("my_class")).is_equal("my_class_test")
assert_str(GdUnitTestSuiteScanner._to_naming_convention("myclass")).is_equal("myclass_test")
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.PASCAL_CASE)
assert_str(GdUnitTestSuiteScanner._to_naming_convention("MyClass")).is_equal("MyClassTest")
assert_str(GdUnitTestSuiteScanner._to_naming_convention("my_class")).is_equal("MyClassTest")
assert_str(GdUnitTestSuiteScanner._to_naming_convention("myclass")).is_equal("MyclassTest")
func test_is_script_format_supported() -> void:
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.gd")).is_true()
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.gdns")).is_false()
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.vs")).is_false()
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.tres")).is_false()
func test_resolve_test_suite_path() -> void:
# forcing the use of a test folder next to the source folder
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/myclass.gd", "test")).is_equal("res://project/test/folder/myclass_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/MyClass.gd", "test")).is_equal("res://project/test/folder/MyClassTest.gd")
# forcing to use source directory to create the test
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/myclass.gd", "")).is_equal("res://project/src/folder/myclass_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/MyClass.gd", "")).is_equal("res://project/src/folder/MyClassTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/myclass.gd", "/")).is_equal("res://project/src/folder/myclass_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/MyClass.gd", "/")).is_equal("res://project/src/folder/MyClassTest.gd")
func test_resolve_test_suite_path_with_src_folders() -> void:
# forcing the use of a test folder next
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/myclass.gd", "test")).is_equal("res://test/project/folder/myclass_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/MyClass.gd", "test")).is_equal("res://test/project/folder/MyClassTest.gd")
# forcing to use source directory to create the test
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/myclass.gd", "")).is_equal("res://project/folder/myclass_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/MyClass.gd", "")).is_equal("res://project/folder/MyClassTest.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/myclass.gd", "/")).is_equal("res://project/folder/myclass_test.gd")
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/MyClass.gd", "/")).is_equal("res://project/folder/MyClassTest.gd")
func test_scan_test_suite_without_tests() -> void:
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
var test_suites := scanner.scan("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteWithoutTests.gd")
assert_that(test_suites).is_empty()

View file

@ -0,0 +1,49 @@
# GdUnit generated TestSuite
class_name GdUnitToolsTest
extends GdUnitTestSuite
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/GdUnitTools.gd'
class InnerTestNodeClass extends Node:
pass
class InnerTestRefCountedClass extends RefCounted:
pass
func test_free_instance() -> void:
# on valid instances
assert_that(await GdUnitTools.free_instance(RefCounted.new())).is_true()
assert_that(await GdUnitTools.free_instance(Node.new())).is_true()
assert_that(await GdUnitTools.free_instance(JavaClass.new())).is_true()
assert_that(await GdUnitTools.free_instance(InnerTestNodeClass.new())).is_true()
assert_that(await GdUnitTools.free_instance(InnerTestRefCountedClass.new())).is_true()
# on invalid instances
assert_that(await GdUnitTools.free_instance(null)).is_false()
assert_that(await GdUnitTools.free_instance(RefCounted)).is_false()
# on already freed instances
var node := Node.new()
node.free()
assert_that(await GdUnitTools.free_instance(node)).is_false()
func test_richtext_normalize() -> void:
assert_that(GdUnitTools.richtext_normalize("")).is_equal("")
assert_that(GdUnitTools.richtext_normalize("This is a Color Message")).is_equal("This is a Color Message")
var message = """
[color=green]line [/color][color=aqua]11:[/color] [color=#CD5C5C]Expecting:[/color]
must be empty but was
'[color=#1E90FF]after[/color]'
"""
assert_that(GdUnitTools.richtext_normalize(message)).is_equal("""
line 11: Expecting:
must be empty but was
'after'
""")

View file

@ -0,0 +1,69 @@
# GdUnit generated TestSuite
class_name LocalTimeTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/LocalTime.gd'
func test_time_constants():
assert_int(LocalTime.MILLIS_PER_HOUR).is_equal(1000*60*60)
assert_int(LocalTime.MILLIS_PER_MINUTE).is_equal(1000*60)
assert_int(LocalTime.MILLIS_PER_SECOND).is_equal(1000)
assert_int(LocalTime.HOURS_PER_DAY).is_equal(24)
assert_int(LocalTime.MINUTES_PER_HOUR).is_equal(60)
assert_int(LocalTime.SECONDS_PER_MINUTE).is_equal(60)
func test_now():
var current := Time.get_datetime_dict_from_system(true)
var local_time := LocalTime.now()
assert_int(local_time.hour()).is_equal(current.get("hour"))
assert_int(local_time.minute()).is_equal(current.get("minute"))
assert_int(local_time.second()).is_equal(current.get("second"))
# Time.get_datetime_dict_from_system() does not provide milliseconds
#assert_that(local_time.millis()).is_equal(0)
@warning_ignore("integer_division")
func test_of_unix_time():
var time := LocalTime._get_system_time_msecs()
var local_time := LocalTime.of_unix_time(time)
assert_int(local_time.hour()).is_equal((time / LocalTime.MILLIS_PER_HOUR) % 24)
assert_int(local_time.minute()).is_equal((time / LocalTime.MILLIS_PER_MINUTE) % 60)
assert_int(local_time.second()).is_equal((time / LocalTime.MILLIS_PER_SECOND) % 60)
assert_int(local_time.millis()).is_equal(time % 1000)
func test_to_string():
assert_str(LocalTime.local_time(10, 12, 22, 333)._to_string()).is_equal("10:12:22.333")
assert_str(LocalTime.local_time(23, 59, 59, 999)._to_string()).is_equal("23:59:59.999")
assert_str(LocalTime.local_time( 0, 0, 0, 000)._to_string()).is_equal("00:00:00.000")
assert_str(LocalTime.local_time( 2, 4, 3, 10)._to_string()).is_equal("02:04:03.010")
func test_plus_seconds():
var time := LocalTime.local_time(10, 12, 22, 333)
assert_str(time.plus(LocalTime.TimeUnit.SECOND, 10)._to_string()).is_equal("10:12:32.333")
assert_str(time.plus(LocalTime.TimeUnit.SECOND, 27)._to_string()).is_equal("10:12:59.333")
assert_str(time.plus(LocalTime.TimeUnit.SECOND, 1)._to_string()).is_equal("10:13:00.333")
# test overflow
var time2 := LocalTime.local_time(10, 59, 59, 333)
var start_time = time2._time
for iteration in 10000:
var t = LocalTime.of_unix_time(start_time)
var seconds:int = randi_range(0, 1000)
t.plus(LocalTime.TimeUnit.SECOND, seconds)
var expected := LocalTime.of_unix_time(start_time + (seconds * LocalTime.MILLIS_PER_SECOND))
assert_str(t._to_string()).is_equal(expected._to_string())
func test_elapsed():
assert_str(LocalTime.elapsed(10)).is_equal("10ms")
assert_str(LocalTime.elapsed(201)).is_equal("201ms")
assert_str(LocalTime.elapsed(999)).is_equal("999ms")
assert_str(LocalTime.elapsed(1000)).is_equal("1s 0ms")
assert_str(LocalTime.elapsed(2000)).is_equal("2s 0ms")
assert_str(LocalTime.elapsed(3040)).is_equal("3s 40ms")
assert_str(LocalTime.elapsed(LocalTime.MILLIS_PER_MINUTE * 6 + 3040)).is_equal("6min 3s 40ms")

View file

@ -0,0 +1,296 @@
#warning-ignore-all:unused_argument
class_name ParameterizedTestCaseTest
extends GdUnitTestSuite
var _collected_tests = {}
var _expected_tests = {
"test_parameterized_bool_value" : [
[0, false],
[1, true]
],
"test_parameterized_int_values" : [
[1, 2, 3, 6],
[3, 4, 5, 12],
[6, 7, 8, 21]
],
"test_parameterized_float_values" : [
[2.2, 2.2, 4.4],
[2.2, 2.3, 4.5],
[3.3, 2.2, 5.5]
],
"test_parameterized_string_values" : [
["2.2", "2.2", "2.22.2"],
["foo", "bar", "foobar"],
["a", "b", "ab"]
],
"test_parameterized_Vector2_values" : [
[Vector2.ONE, Vector2.ONE, Vector2(2, 2)],
[Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO],
[Vector2.ZERO, Vector2.LEFT, Vector2.LEFT]
],
"test_parameterized_Vector3_values" : [
[Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)],
[Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO],
[Vector3.ZERO, Vector3.LEFT, Vector3.LEFT]
],
"test_parameterized_obj_values" : [
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]
],
"test_parameterized_dict_values" : [
[{"key_a":"value_a"}, '{"key_a":"value_a"}'],
[{"key_b":"value_b"}, '{"key_b":"value_b"}']
],
"test_with_dynamic_paramater_resolving" : [
["test_a"],
["test_b"],
["test_c"],
["test_d"]
],
"test_with_dynamic_paramater_resolving2" : [
["test_a"],
["test_b"],
["test_c"]
],
"test_with_extern_parameter_set" : [
["test_a"],
["test_b"],
["test_c"]
]
}
var _test_node_before :Node
var _test_node_before_test :Node
func before() -> void:
_test_node_before = auto_free(SubViewport.new())
func before_test() -> void:
_test_node_before_test = auto_free(SubViewport.new())
func after():
for test_name in _expected_tests.keys():
if _collected_tests.has(test_name):
var current_values = _collected_tests[test_name]
var expected_values = _expected_tests[test_name]
assert_that(current_values)\
.override_failure_message("Expecting '%s' called with parameters:\n %s\n but was\n %s" % [test_name, expected_values, current_values])\
.is_equal(expected_values)
else:
fail("Missing test '%s' executed!" % test_name)
func collect_test_call(test_name :String, values :Array) -> void:
if not _collected_tests.has(test_name):
_collected_tests[test_name] = Array()
_collected_tests[test_name].append(values)
@warning_ignore("unused_parameter")
func test_parameterized_bool_value(a: int, expected :bool, test_parameters := [
[0, false],
[1, true]]):
collect_test_call("test_parameterized_bool_value", [a, expected])
assert_that(bool(a)).is_equal(expected)
@warning_ignore("unused_parameter")
func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_parameters := [
[1, 2, 3, 6],
[3, 4, 5, 12],
[6, 7, 8, 21] ]):
collect_test_call("test_parameterized_int_values", [a, b, c, expected])
assert_that(a+b+c).is_equal(expected)
@warning_ignore("unused_parameter")
func test_parameterized_float_values(a: float, b :float, expected :float, test_parameters := [
[2.2, 2.2, 4.4],
[2.2, 2.3, 4.5],
[3.3, 2.2, 5.5] ]):
collect_test_call("test_parameterized_float_values", [a, b, expected])
assert_float(a+b).is_equal(expected)
@warning_ignore("unused_parameter")
func test_parameterized_string_values(a: String, b :String, expected :String, test_parameters := [
["2.2", "2.2", "2.22.2"],
["foo", "bar", "foobar"],
["a", "b", "ab"] ]):
collect_test_call("test_parameterized_string_values", [a, b, expected])
assert_that(a+b).is_equal(expected)
@warning_ignore("unused_parameter")
func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2, test_parameters := [
[Vector2.ONE, Vector2.ONE, Vector2(2, 2)],
[Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO],
[Vector2.ZERO, Vector2.LEFT, Vector2.LEFT] ]):
collect_test_call("test_parameterized_Vector2_values", [a, b, expected])
assert_that(a+b).is_equal(expected)
@warning_ignore("unused_parameter")
func test_parameterized_Vector3_values(a: Vector3, b :Vector3, expected :Vector3, test_parameters := [
[Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)],
[Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO],
[Vector3.ZERO, Vector3.LEFT, Vector3.LEFT] ]):
collect_test_call("test_parameterized_Vector3_values", [a, b, expected])
assert_that(a+b).is_equal(expected)
class TestObj extends RefCounted:
var _value :String
func _init(value :String):
_value = value
func _to_string() -> String:
return _value
@warning_ignore("unused_parameter")
func test_parameterized_obj_values(a: Object, b :Object, expected :String, test_parameters := [
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]):
collect_test_call("test_parameterized_obj_values", [a, b, expected])
assert_that(a.to_string()+b.to_string()).is_equal(expected)
@warning_ignore("unused_parameter")
func test_parameterized_dict_values(data: Dictionary, expected :String, test_parameters := [
[{"key_a" : "value_a"}, '{"key_a":"value_a"}'],
[{"key_b" : "value_b"}, '{"key_b":"value_b"}']
]):
collect_test_call("test_parameterized_dict_values", [data, expected])
assert_that(str(data).replace(" ", "")).is_equal(expected)
@warning_ignore("unused_parameter")
func test_dictionary_div_number_types(
value : Dictionary,
expected : Dictionary,
test_parameters : Array = [
[{ top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}, { top = 50, bottom = 50, left = 50, right = 50}],
[{ top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}, { top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}],
[{ top = 50, bottom = 50, left = 50, right = 50}, { top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}],
[{ top = 50, bottom = 50, left = 50, right = 50}, { top = 50, bottom = 50, left = 50, right = 50}],
]
) -> void:
# allow to compare type unsave
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, false)
assert_that(value).is_equal(expected)
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, true)
@warning_ignore("unused_parameter")
func test_with_string_paramset(
values : Array,
expected : String,
test_parameters : Array = [
[ ["a"], "a" ],
[ ["a", "very", "long", "argument"], "a very long argument" ],
]
):
var current := " ".join(values)
assert_that(current.strip_edges()).is_equal(expected)
# https://github.com/MikeSchulze/gdUnit4/issues/213
@warning_ignore("unused_parameter")
func test_with_string_contains_brackets(
test_index :int,
value :String,
test_parameters := [
[1, "flowchart TD\nid>This is a flag shaped node]"],
[2, "flowchart TD\nid(((This is a double circle node)))"],
[3, "flowchart TD\nid((This is a circular node))"],
[4, "flowchart TD\nid>This is a flag shaped node]"],
[5, "flowchart TD\nid{'This is a rhombus node'}"],
[6, 'flowchart TD\nid((This is a circular node))'],
[7, 'flowchart TD\nid>This is a flag shaped node]'],
[8, 'flowchart TD\nid{"This is a rhombus node"}'],
[9, """
flowchart TD
id{"This is a rhombus node"}
"""],
]
):
match test_index:
1: assert_str(value).is_equal("flowchart TD\nid>This is a flag shaped node]")
2: assert_str(value).is_equal("flowchart TD\nid(((This is a double circle node)))")
3: assert_str(value).is_equal("flowchart TD\nid((This is a circular node))")
4: assert_str(value).is_equal("flowchart TD\nid>" + "This is a flag shaped node]")
5: assert_str(value).is_equal("flowchart TD\nid{'This is a rhombus node'}")
6: assert_str(value).is_equal('flowchart TD\nid((This is a circular node))')
7: assert_str(value).is_equal('flowchart TD\nid>This is a flag shaped node]')
8: assert_str(value).is_equal('flowchart TD\nid{"This is a rhombus node"}')
9: assert_str(value).is_equal("""
flowchart TD
id{"This is a rhombus node"}
""")
func test_with_dynamic_parameter_resolving(name: String, value, expected, test_parameters := [
["test_a", auto_free(Node2D.new()), Node2D],
["test_b", auto_free(Node3D.new()), Node3D],
["test_c", _test_node_before, SubViewport],
["test_d", _test_node_before_test, SubViewport],
]) -> void:
# all values must be resolved
assert_that(value).is_not_null().is_instanceof(expected)
if name == "test_c":
assert_that(value).is_same(_test_node_before)
if name == "test_d":
assert_that(value).is_same(_test_node_before_test)
# the argument 'test_parameters' must be replaced by <null> set to avoid re-instantiate of test arguments
assert_that(test_parameters).is_empty()
collect_test_call("test_with_dynamic_paramater_resolving", [name])
@warning_ignore("unused_parameter")
func test_with_dynamic_parameter_resolving2(
name: String,
type,
log_level,
expected_logs,
test_parameters = [
["test_a", null, "LOG", {}],
[
"test_b",
Node2D,
null,
{Node2D: "ERROR"}
],
[
"test_c",
Node2D,
"LOG",
{Node2D: "LOG"}
]
]
):
# the argument 'test_parameters' must be replaced by <null> set to avoid re-instantiate of test arguments
assert_that(test_parameters).is_empty()
collect_test_call("test_with_dynamic_paramater_resolving2", [name])
var _test_set =[
["test_a"],
["test_b"],
["test_c"]
]
@warning_ignore("unused_parameter")
func test_with_extern_parameter_set(value, test_parameters = _test_set):
assert_that(value).is_not_empty()
assert_that(test_parameters).is_empty()
collect_test_call("test_with_extern_parameter_set", [value])

View file

@ -0,0 +1,70 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/command/GdUnitCommandHandler.gd'
var _handler :GdUnitCommandHandler
func before():
_handler = GdUnitCommandHandler.new()
func after():
_handler._notification(NOTIFICATION_PREDELETE)
_handler = null
@warning_ignore('unused_parameter')
func test_create_shortcuts_defaults(shortcut :GdUnitShortcut.ShortCut, expected :String, test_parameters := [
[GdUnitShortcut.ShortCut.RUN_TESTCASE, "GdUnitShortcutAction: RUN_TESTCASE (Ctrl+Alt+F5) -> Run TestCases"],
[GdUnitShortcut.ShortCut.RUN_TESTCASE_DEBUG, "GdUnitShortcutAction: RUN_TESTCASE_DEBUG (Ctrl+Alt+F6) -> Run TestCases (Debug)"],
[GdUnitShortcut.ShortCut.RERUN_TESTS, "GdUnitShortcutAction: RERUN_TESTS (Ctrl+F5) -> ReRun Tests"],
[GdUnitShortcut.ShortCut.RERUN_TESTS_DEBUG, "GdUnitShortcutAction: RERUN_TESTS_DEBUG (Ctrl+F6) -> ReRun Tests (Debug)"],
[GdUnitShortcut.ShortCut.RUN_TESTS_OVERALL, "GdUnitShortcutAction: RUN_TESTS_OVERALL (Ctrl+F7) -> Debug Overall TestSuites"],
[GdUnitShortcut.ShortCut.STOP_TEST_RUN, "GdUnitShortcutAction: STOP_TEST_RUN (Ctrl+F8) -> Stop Test Run"],
[GdUnitShortcut.ShortCut.CREATE_TEST, "GdUnitShortcutAction: CREATE_TEST (Ctrl+Alt+F10) -> Create TestCase"],]) -> void:
if OS.get_name().to_lower() == "macos":
expected.replace("Ctrl", "Command")
var action := _handler.get_shortcut_action(shortcut)
assert_that(str(action)).is_equal(expected)
## actually needs to comment out, it produces a lot of leaked instances
func _test__check_test_run_stopped_manually() -> void:
var inspector :GdUnitCommandHandler = mock(GdUnitCommandHandler, CALL_REAL_FUNC)
inspector._client_id = 1
# simulate no test is running
do_return(false).on(inspector).is_test_running_but_stop_pressed()
inspector.check_test_run_stopped_manually()
verify(inspector, 0).cmd_stop(any_int())
# simulate the test runner was manually stopped by the editor
do_return(true).on(inspector).is_test_running_but_stop_pressed()
inspector.check_test_run_stopped_manually()
verify(inspector, 1).cmd_stop(inspector._client_id)
func test_scan_test_directorys() -> void:
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "test", [])).contains_exactly([
"res://addons/gdUnit4/test"
])
# for root folders
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "/", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "res://", [])).contains_exactly([
"res://addons", "res://assets", "res://gdUnit3-examples"
])
# a test folder not exists
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "notest", [])).is_empty()

View file

@ -0,0 +1,22 @@
# GdUnit generated TestSuite
class_name GdUnitEventTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/event/GdUnitEvent.gd'
func test_GdUnitEvent_defaults() -> void:
var event := GdUnitEvent.new()
assert_bool(event.is_success()).is_true()
assert_bool(event.is_warning()).is_false()
assert_bool(event.is_failed()).is_false()
assert_bool(event.is_error()).is_false()
assert_bool(event.is_skipped()).is_false()
assert_int(event.elapsed_time()).is_zero()
assert_int(event.orphan_nodes()).is_zero()
assert_int(event.total_count()).is_zero()
assert_int(event.failed_count()).is_zero()
assert_int(event.skipped_count()).is_zero()

View file

@ -0,0 +1,51 @@
# this test test for serialization and deserialization succcess
# of GdUnitEvent class
extends GdUnitTestSuite
func test_serde_suite_before():
var event := GdUnitEvent.new().suite_before("path", "test_suite_a", 22)
var serialized := event.serialize()
var deserialized := GdUnitEvent.new().deserialize(serialized)
assert_that(deserialized).is_instanceof(GdUnitEvent)
assert_that(deserialized).is_equal(event)
func test_serde_suite_after():
var event := GdUnitEvent.new().suite_after("path","test_suite_a")
var serialized := event.serialize()
var deserialized := GdUnitEvent.new().deserialize(serialized)
assert_that(deserialized).is_equal(event)
func test_serde_test_before():
var event := GdUnitEvent.new().test_before("path", "test_suite_a", "test_foo")
var serialized := event.serialize()
var deserialized := GdUnitEvent.new().deserialize(serialized)
assert_that(deserialized).is_equal(event)
func test_serde_test_after_no_report():
var event := GdUnitEvent.new().test_after("path", "test_suite_a", "test_foo")
var serialized := event.serialize()
var deserialized := GdUnitEvent.new().deserialize(serialized)
assert_that(deserialized).is_equal(event)
func test_serde_test_after_with_report():
var reports :Array[GdUnitReport] = [\
GdUnitReport.new().create(GdUnitReport.FAILURE, 24, "this is a error a"), \
GdUnitReport.new().create(GdUnitReport.FAILURE, 26, "this is a error b")]
var event := GdUnitEvent.new().test_after("path", "test_suite_a", "test_foo", {}, reports)
var serialized := event.serialize()
var deserialized := GdUnitEvent.new().deserialize(serialized)
assert_that(deserialized).is_equal(event)
assert_array(deserialized.reports()).contains_exactly(reports)
func test_serde_TestReport():
var report := GdUnitReport.new().create(GdUnitReport.FAILURE, 24, "this is a error")
var serialized := report.serialize()
var deserialized := GdUnitReport.new().deserialize(serialized)
assert_that(deserialized).is_equal(report)

View file

@ -0,0 +1,222 @@
# GdUnit generated TestSuite
class_name GdUnitExecutionContextTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/execution/GdUnitExecutionContext.gd'
func add_report(ec :GdUnitExecutionContext, report :GdUnitReport) -> void:
ec._report_collector.on_reports(ec.get_instance_id(), report)
func assert_statistics(ec :GdUnitExecutionContext):
assert_that(ec.has_failures()).is_false()
assert_that(ec.has_errors()).is_false()
assert_that(ec.has_warnings()).is_false()
assert_that(ec.has_skipped()).is_false()
assert_that(ec.count_failures(true)).is_equal(0)
assert_that(ec.count_errors(true)).is_equal(0)
assert_that(ec.count_skipped(true)).is_equal(0)
assert_that(ec.count_orphans()).is_equal(0)
assert_dict(ec.build_report_statistics(0))\
.contains_key_value(GdUnitEvent.FAILED, false)\
.contains_key_value(GdUnitEvent.ERRORS, false)\
.contains_key_value(GdUnitEvent.WARNINGS, false)\
.contains_key_value(GdUnitEvent.SKIPPED, false)\
.contains_key_value(GdUnitEvent.ORPHAN_NODES, 0)\
.contains_key_value(GdUnitEvent.FAILED_COUNT, 0)\
.contains_key_value(GdUnitEvent.ERROR_COUNT, 0)\
.contains_key_value(GdUnitEvent.SKIPPED_COUNT, 0)\
.contains_keys([GdUnitEvent.ELAPSED_TIME])
func test_create_context_of_test_suite() -> void:
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
var ec := GdUnitExecutionContext.of_test_suite(ts)
# verify the current context is not affected by this test itself
assert_object(__execution_context).is_not_same(ec)
# verify the execution context is assigned to the test suite
assert_object(ts.__execution_context).is_same(ec)
# verify execution context is fully initialized
assert_that(ec).is_not_null()
assert_object(ec.test_suite).is_same(ts)
assert_object(ec.test_case).is_null()
assert_array(ec._sub_context).is_empty()
assert_object(ec._orphan_monitor).is_not_null()
assert_object(ec._memory_observer).is_not_null()
assert_object(ec._report_collector).is_not_null()
assert_statistics(ec)
ec.dispose()
func test_create_context_of_test_case() -> void:
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
ts.add_child(tc)
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
# verify the current context is not affected by this test itself
assert_object(__execution_context).is_not_same(ec1)
assert_object(__execution_context).is_not_same(ec2)
# verify current execution contest is assigned to the test suite
assert_object(ts.__execution_context).is_same(ec2)
# verify execution context is fully initialized
assert_that(ec2).is_not_null()
assert_object(ec2.test_suite).is_same(ts)
assert_object(ec2.test_case).is_same(tc)
assert_array(ec2._sub_context).is_empty()
assert_object(ec2._orphan_monitor).is_not_null().is_not_same(ec1._orphan_monitor)
assert_object(ec2._memory_observer).is_not_null().is_not_same(ec1._memory_observer)
assert_object(ec2._report_collector).is_not_null().is_not_same(ec1._report_collector)
assert_statistics(ec2)
# check parent context ec1 is still valid
assert_that(ec1).is_not_null()
assert_object(ec1.test_suite).is_same(ts)
assert_object(ec1.test_case).is_null()
assert_array(ec1._sub_context).contains_exactly([ec2])
assert_object(ec1._orphan_monitor).is_not_null()
assert_object(ec1._memory_observer).is_not_null()
assert_object(ec1._report_collector).is_not_null()
assert_statistics(ec1)
ec1.dispose()
func test_create_context_of_test() -> void:
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
ts.add_child(tc)
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
var ec3 := GdUnitExecutionContext.of(ec2)
# verify the current context is not affected by this test itself
assert_object(__execution_context).is_not_same(ec1)
assert_object(__execution_context).is_not_same(ec2)
assert_object(__execution_context).is_not_same(ec3)
# verify current execution contest is assigned to the test suite
assert_object(ts.__execution_context).is_same(ec3)
# verify execution context is fully initialized
assert_that(ec3).is_not_null()
assert_object(ec3.test_suite).is_same(ts)
assert_object(ec3.test_case).is_same(tc)
assert_array(ec3._sub_context).is_empty()
assert_object(ec3._orphan_monitor).is_not_null()\
.is_not_same(ec1._orphan_monitor)\
.is_not_same(ec2._orphan_monitor)
assert_object(ec3._memory_observer).is_not_null()\
.is_not_same(ec1._memory_observer)\
.is_not_same(ec2._memory_observer)
assert_object(ec3._report_collector).is_not_null()\
.is_not_same(ec1._report_collector)\
.is_not_same(ec2._report_collector)
assert_statistics(ec3)
# check parent context ec2 is still valid
assert_that(ec2).is_not_null()
assert_object(ec2.test_suite).is_same(ts)
assert_object(ec2.test_case).is_same(tc)
assert_array(ec2._sub_context).contains_exactly([ec3])
assert_object(ec2._orphan_monitor).is_not_null()\
.is_not_same(ec1._orphan_monitor)
assert_object(ec2._memory_observer).is_not_null()\
.is_not_same(ec1._memory_observer)
assert_object(ec2._report_collector).is_not_null()\
.is_not_same(ec1._report_collector)
assert_statistics(ec2)
# check parent context ec1 is still valid
assert_that(ec1).is_not_null()
assert_object(ec1.test_suite).is_same(ts)
assert_object(ec1.test_case).is_null()
assert_array(ec1._sub_context).contains_exactly([ec2])
assert_object(ec1._orphan_monitor).is_not_null()
assert_object(ec1._memory_observer).is_not_null()
assert_object(ec1._report_collector).is_not_null()
assert_statistics(ec1)
ec1.dispose()
func test_report_collectors() -> void:
# setup
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
ts.add_child(tc)
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
var ec3 := GdUnitExecutionContext.of(ec2)
# add reports
var failure11 := GdUnitReport.new().create(GdUnitReport.FAILURE, 1, "error_ec11")
add_report(ec1, failure11)
var failure21 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec21")
var failure22 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec22")
add_report(ec2, failure21)
add_report(ec2, failure22)
var failure31 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec31")
var failure32 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec32")
var failure33 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec33")
add_report(ec3, failure31)
add_report(ec3, failure32)
add_report(ec3, failure33)
# verify
assert_array(ec1.reports()).contains_exactly([failure11])
assert_array(ec2.reports()).contains_exactly([failure21, failure22])
assert_array(ec3.reports()).contains_exactly([failure31, failure32, failure33])
ec1.dispose()
func test_has_and_count_failures() -> void:
# setup
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
ts.add_child(tc)
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
var ec3 := GdUnitExecutionContext.of(ec2)
# precheck
assert_that(ec1.has_failures()).is_false()
assert_that(ec1.count_failures(true)).is_equal(0)
assert_that(ec2.has_failures()).is_false()
assert_that(ec2.count_failures(true)).is_equal(0)
assert_that(ec3.has_failures()).is_false()
assert_that(ec3.count_failures(true)).is_equal(0)
# add four failure report to test
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 42, "error_ec31"))
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 43, "error_ec32"))
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 44, "error_ec33"))
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 45, "error_ec34"))
# verify
assert_that(ec1.has_failures()).is_true()
assert_that(ec1.count_failures(true)).is_equal(4)
assert_that(ec2.has_failures()).is_true()
assert_that(ec2.count_failures(true)).is_equal(4)
assert_that(ec3.has_failures()).is_true()
assert_that(ec3.count_failures(true)).is_equal(4)
# add two failure report to test_case_stage
add_report(ec2, GdUnitReport.new().create(GdUnitReport.FAILURE, 42, "error_ec21"))
add_report(ec2, GdUnitReport.new().create(GdUnitReport.FAILURE, 43, "error_ec22"))
# verify
assert_that(ec1.has_failures()).is_true()
assert_that(ec1.count_failures(true)).is_equal(6)
assert_that(ec2.has_failures()).is_true()
assert_that(ec2.count_failures(true)).is_equal(6)
assert_that(ec3.has_failures()).is_true()
assert_that(ec3.count_failures(true)).is_equal(4)
# add one failure report to test_suite_stage
add_report(ec1, GdUnitReport.new().create(GdUnitReport.FAILURE, 42, "error_ec1"))
# verify
assert_that(ec1.has_failures()).is_true()
assert_that(ec1.count_failures(true)).is_equal(7)
assert_that(ec2.has_failures()).is_true()
assert_that(ec2.count_failures(true)).is_equal(6)
assert_that(ec3.has_failures()).is_true()
assert_that(ec3.count_failures(true)).is_equal(4)
ec1.dispose()

View file

@ -0,0 +1,708 @@
# GdUnit generated TestSuite
class_name GdUnitTestSuiteExecutorTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/execution/GdUnitTestSuiteExecutor.gd'
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
const SUCCEEDED = true
const FAILED = false
const SKIPPED = true
const NOT_SKIPPED = false
var _collected_events :Array[GdUnitEvent] = []
func before() -> void:
GdUnitSignals.instance().gdunit_event_debug.connect(_on_gdunit_event_debug)
func after() -> void:
GdUnitSignals.instance().gdunit_event_debug.disconnect(_on_gdunit_event_debug)
func after_test():
_collected_events.clear()
func _on_gdunit_event_debug(event :GdUnitEvent) -> void:
_collected_events.append(event)
func _load(resource_path :String) -> GdUnitTestSuite:
return GdUnitTestResourceLoader.load_test_suite(resource_path) as GdUnitTestSuite
func flating_message(message :String) -> String:
return GdUnitTools.richtext_normalize(message)
func execute(test_suite :GdUnitTestSuite) -> Array[GdUnitEvent]:
await GdUnitThreadManager.run("test_executor", func():
var executor := GdUnitTestSuiteExecutor.new(true)
await executor.execute(test_suite))
return _collected_events
func assert_event_list(events :Array[GdUnitEvent], suite_name :String, test_case_names :Array[String]) -> void:
var expected_events := Array()
expected_events.append(tuple(GdUnitEvent.TESTSUITE_BEFORE, suite_name, "before", test_case_names.size()))
for test_case in test_case_names:
expected_events.append(tuple(GdUnitEvent.TESTCASE_BEFORE, suite_name, test_case, 0))
expected_events.append(tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, test_case, 0))
expected_events.append(tuple(GdUnitEvent.TESTSUITE_AFTER, suite_name, "after", 0))
var expected_event_count := 2 + test_case_names.size() * 2
assert_array(events)\
.override_failure_message("Expecting be %d events emitted, but counts %d." % [expected_event_count, events.size()])\
.has_size(expected_event_count)
assert_array(events)\
.extractv(extr("type"), extr("suite_name"), extr("test_name"), extr("total_count"))\
.contains_exactly(expected_events)
func assert_event_counters(events :Array[GdUnitEvent]) -> GdUnitArrayAssert:
return assert_array(events).extractv(extr("type"), extr("error_count"), extr("failed_count"), extr("orphan_nodes"))
func assert_event_states(events :Array[GdUnitEvent]) -> GdUnitArrayAssert:
return assert_array(events).extractv(extr("test_name"), extr("is_success"), extr("is_skipped"), extr("is_warning"), extr("is_failed"), extr("is_error"))
func assert_event_reports(events :Array[GdUnitEvent], expected_reports :Array) -> void:
for event_index in events.size():
var current :Array = events[event_index].reports()
var expected = expected_reports[event_index] if expected_reports.size() > event_index else []
if expected.is_empty():
for m in current.size():
assert_str(flating_message(current[m].message())).is_empty()
for m in expected.size():
if m < current.size():
assert_str(flating_message(current[m].message())).is_equal(expected[m])
else:
assert_str("<N/A>").is_equal(expected[m])
func test_execute_success() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteAllStagesSuccess.resource")
# simulate test suite execution
var events := await execute(test_suite)
assert_event_list(events,\
"TestSuiteAllStagesSuccess",\
["test_case1", "test_case2"])
# verify all counters are zero / no errors, failures, orphans
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
])
# all success no reports expected
assert_event_reports(events, [
[], [], [], [], [], []
])
func test_execute_failure_on_stage_before() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageBefore.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailOnStageBefore",\
["test_case1", "test_case2"])
# we expect the testsuite is failing on stage 'before()' and commits one failure
# reported finally at TESTSUITE_AFTER event
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
# report failure failed_count = 1
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 1, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
# report suite is not success, is failed
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# one failure at before()
assert_event_reports(events, [
[],
[],
[],
[],
[],
["failed on before()"]
])
func test_execute_failure_on_stage_after() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageAfter.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailOnStageAfter",\
["test_case1", "test_case2"])
# we expect the testsuite is failing on stage 'before()' and commits one failure
# reported finally at TESTSUITE_AFTER event
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
# report failure failed_count = 1
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 1, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
# report suite is not success, is failed
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# one failure at after()
assert_event_reports(events, [
[],
[],
[],
[],
[],
["failed on after()"]
])
func test_execute_failure_on_stage_before_test() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageBeforeTest.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailOnStageBeforeTest",\
["test_case1", "test_case2"])
# we expect the testsuite is failing on stage 'before_test()' and commits one failure on each test case
# because is in scope of test execution
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# failure is count to the test
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# failure is count to the test
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
# report suite is not success, is failed
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# before_test() failure report is append to each test
assert_event_reports(events, [
[],
[],
# verify failure report is append to 'test_case1'
["failed on before_test()"],
[],
# verify failure report is append to 'test_case2'
["failed on before_test()"],
[]
])
func test_execute_failure_on_stage_after_test() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageAfterTest.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailOnStageAfterTest",\
["test_case1", "test_case2"])
# we expect the testsuite is failing on stage 'after_test()' and commits one failure on each test case
# because is in scope of test execution
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# failure is count to the test
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# failure is count to the test
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
# report suite is not success, is failed
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# 'after_test' failure report is append to each test
assert_event_reports(events, [
[],
[],
# verify failure report is append to 'test_case1'
["failed on after_test()"],
[],
# verify failure report is append to 'test_case2'
["failed on after_test()"],
[]
])
func test_execute_failure_on_stage_test_case1() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageTestCase1.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailOnStageTestCase1",\
["test_case1", "test_case2"])
# we expect the test case 'test_case1' is failing and commits one failure
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# test has one failure
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
# report suite is not success, is failed
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# only 'test_case1' reports a failure
assert_event_reports(events, [
[],
[],
# verify failure report is append to 'test_case1'
["failed on test_case1()"],
[],
[],
[]
])
func test_execute_failure_on_multiple_stages() -> void:
# this is a more complex failure state, we expect to find multipe failures on different stages
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnMultipeStages.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailOnMultipeStages",\
["test_case1", "test_case2"])
# we expect failing on multiple stages
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# the first test has two failures plus one from 'before_test'
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 3, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# the second test has no failures but one from 'before_test'
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
# and one failure is on stage 'after' found
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 1, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
# report suite is not success, is failed
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# only 'test_case1' reports a 'real' failures plus test setup stage failures
assert_event_reports(events, [
[],
[],
# verify failure reports to 'test_case1'
["failed on before_test()", "failed 1 on test_case1()", "failed 2 on test_case1()"],
[],
# verify failure reports to 'test_case2'
["failed on before_test()"],
# and one failure detected at stage 'after'
["failed on after()"]
])
# GD-63
func test_execute_failure_and_orphans() -> void:
# this is a more complex failure state, we expect to find multipe orphans on different stages
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailAndOrpahnsDetected.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailAndOrpahnsDetected",\
["test_case1", "test_case2"])
# we expect failing on multiple stages
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# the first test ends with a warning and in summ 5 orphans detected
# 2 from stage 'before_test' + 3 from test itself
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 5),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# the second test ends with a one failure and in summ 6 orphans detected
# 2 from stage 'before_test' + 4 from test itself
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 6),
# and one orphan detected from stage 'before'
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 1),
])
# is_success, is_warning, is_failed, is_error
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
# test case has only warnings
tuple("test_case1", FAILED, NOT_SKIPPED, true, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
# test case has failures and warnings
tuple("test_case2", FAILED, NOT_SKIPPED, true, true, false),
# report suite is not success, has warnings and failures
tuple("after", FAILED, NOT_SKIPPED, true, true, false),
])
# only 'test_case1' reports a 'real' failures plus test setup stage failures
assert_event_reports(events, [
[],
[],
# ends with warnings
["WARNING:\n Detected <2> orphan nodes during test setup! Check before_test() and after_test()!",
"WARNING:\n Detected <3> orphan nodes during test execution!"],
[],
# ends with failure and warnings
["WARNING:\n Detected <2> orphan nodes during test setup! Check before_test() and after_test()!",
"WARNING:\n Detected <4> orphan nodes during test execution!",
"faild on test_case2()"],
# and one failure detected at stage 'after'
["WARNING:\n Detected <1> orphan nodes during test suite setup stage! Check before() and after()!"]
])
func test_execute_failure_and_orphans_report_orphan_disabled() -> void:
# this is a more complex failure state, we expect to find multipe orphans on different stages
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailAndOrpahnsDetected.resource")
# simulate test suite execution whit disabled orphan detection
ProjectSettings.set_setting(GdUnitSettings.REPORT_ORPHANS, false)
var events = await execute(test_suite)
ProjectSettings.set_setting(GdUnitSettings.REPORT_ORPHANS, true)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailAndOrpahnsDetected",\
["test_case1", "test_case2"])
# we expect failing on multiple stages, no orphans reported
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# one failure
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
# is_success, is_warning, is_failed, is_error
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
# test case has success
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
# test case has a failure
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
# report suite is not success, has warnings and failures
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# only 'test_case1' reports a failure, orphans are not reported
assert_event_reports(events, [
[],
[],
[],
[],
# ends with a failure
["faild on test_case2()"],
[]
])
func test_execute_error_on_test_timeout() -> void:
# this tests a timeout on a test case reported as error
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteErrorOnTestTimeout.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteErrorOnTestTimeout",\
["test_case1", "test_case2"])
# we expect test_case1 fails by a timeout
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
# the first test timed out after 2s
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 1, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
# testcase ends with a timeout error
tuple("test_case1", FAILED, NOT_SKIPPED, false, false, true),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
# report suite is not success, is error
tuple("after", FAILED, NOT_SKIPPED, false, false, true),
])
# 'test_case1' reports a error triggered by test timeout
assert_event_reports(events, [
[],
[],
# verify error reports to 'test_case1'
["Timeout !\n 'Test timed out after 2s 0ms'"],
[],
[],
[]
])
# This test checks if all test stages are called at each test iteration.
func test_execute_fuzzed_metrics() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFuzzedMetricsTest.resource")
var events = await execute(test_suite)
assert_event_states(events).contains([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
])
assert_event_reports(events, [
[],
[],
[],
[],
[],
[]
])
# This test checks if all test stages are called at each test iteration.
func test_execute_parameterized_metrics() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedMetricsTest.resource")
var events = await execute(test_suite)
assert_event_states(events).contains([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
])
assert_event_reports(events, [
[],
[],
[],
[],
[],
[]
])
func test_execute_failure_fuzzer_iteration() -> void:
# this tests a timeout on a test case reported as error
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/GdUnitFuzzerTest.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events, "GdUnitFuzzerTest", [
"test_multi_yielding_with_fuzzer",
"test_multi_yielding_with_fuzzer_fail_after_3_iterations"])
# we expect failing at 'test_multi_yielding_with_fuzzer_fail_after_3_iterations' after three iterations
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
# test failed after 3 iterations
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
# is_success, is_warning, is_failed, is_error
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_multi_yielding_with_fuzzer", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_multi_yielding_with_fuzzer", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_multi_yielding_with_fuzzer_fail_after_3_iterations", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_multi_yielding_with_fuzzer_fail_after_3_iterations", FAILED, NOT_SKIPPED, false, true, false),
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
])
# 'test_case1' reports a error triggered by test timeout
assert_event_reports(events, [
[],
[],
[],
[],
# must fail after three iterations
["Found an error after '3' test iterations\n Expecting: 'false' but is 'true'"],
[]
])
func test_execute_add_child_on_before_GD_106() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailAddChildStageBefore.resource")
# simulate test suite execution
var events = await execute(test_suite)
# verify basis infos
assert_event_list(events,\
"TestSuiteFailAddChildStageBefore",\
["test_case1", "test_case2"])
# verify all counters are zero / no errors, failures, orphans
assert_event_counters(events).contains_exactly([
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
])
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
])
# all success no reports expected
assert_event_reports(events, [
[], [], [], [], [], []
])
func test_execute_parameterizied_tests() -> void:
# this is a more complex failure state, we expect to find multipe failures on different stages
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource")
# simulate test suite execution
# run the tests with to compare type save
var original_mode = ProjectSettings.get_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE)
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, true)
var events = await execute(test_suite)
var suite_name = "TestSuiteParameterizedTests"
# the test is partial failing because of diverent type in the dictionary
assert_array(events).extractv(
extr("type"), extr("suite_name"), TestCaseNameExtractor.new(), extr("is_error"), extr("is_failed"), extr("orphan_nodes"))\
.contains([
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:0", false, true, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:1", false, false, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:2", false, true, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:3", false, false, 0)
])
# rerun the same tests again with allow to compare type unsave
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, false)
# simulate test suite execution
test_suite = _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource")
events = await execute(test_suite)
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, original_mode)
# the test should now be successful
assert_array(events).extractv(
extr("type"), extr("suite_name"), TestCaseNameExtractor.new(), extr("is_error"), extr("is_failed"), extr("orphan_nodes"))\
.contains([
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:0", false, false, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:1", false, false, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:2", false, false, 0),
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:3", false, false, 0)
])
func test_execute_test_suite_is_skipped() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteSkipped.resource")
# simulate test suite execution
var events = await execute(test_suite)
# the entire test-suite is skipped
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("after", FAILED, SKIPPED, false, false, false),
])
assert_event_reports(events, [
[],
# must fail after three iterations
["""
Entire test-suite is skipped!
Tests skipped: '2'
Reason: '"do not run this"'
""".dedent().trim_prefix("\n")]
])
func test_execute_test_case_is_skipped() -> void:
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestCaseSkipped.resource")
# simulate test suite execution
var events = await execute(test_suite)
# the test_case1 is skipped
assert_event_states(events).contains_exactly([
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case1", FAILED, SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
])
assert_event_reports(events, [
[],
[],
["""
This test is skipped!
Reason: '"do not run this"'
""".dedent().trim_prefix("\n")],
[],
[],
[]
])
class TestCaseNameExtractor extends GdUnitValueExtractor:
var r := RegEx.create_from_string("^.*:\\d")
func extract_value(value):
var m := r.search(value.test_name())
return m.get_string(0) if m != null else value.test_name()

View file

@ -0,0 +1,255 @@
# GdUnit generated TestSuite
class_name GdDefaultValueDecoderTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd'
var _tested_types = {}
func after():
# we verify we have covered all variant types
for type_id in TYPE_MAX:
if type_id == TYPE_OBJECT:
continue
assert_that(_tested_types.get(type_id))\
.override_failure_message("Missing Variant type '%s'" % GdObjects.type_as_string(type_id))\
.is_not_null()
@warning_ignore("unused_parameter")
func test_decode_Primitives(variant_type :int, value, expected :String, test_parameters := [
[TYPE_NIL, null, "null"],
[TYPE_BOOL, true, "true"],
[TYPE_BOOL, false, "false"],
[TYPE_INT, -100, "-100"],
[TYPE_INT, 0, "0"],
[TYPE_INT, 100, "100"],
[TYPE_FLOAT, -100.123, "-100.123000"],
[TYPE_FLOAT, 0.00, "0.000000"],
[TYPE_FLOAT, 100, "100.000000"],
[TYPE_FLOAT, 100.123, "100.123000"],
[TYPE_STRING, "hello", '"hello"'],
[TYPE_STRING, "", '""'],
[TYPE_STRING_NAME, StringName("hello"), 'StringName("hello")'],
[TYPE_STRING_NAME, StringName(""), 'StringName()'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Vectors(variant_type :int, value, expected :String, test_parameters := [
[TYPE_VECTOR2, Vector2(), "Vector2()"],
[TYPE_VECTOR2, Vector2(1,2), "Vector2(1, 2)"],
[TYPE_VECTOR2I, Vector2i(), "Vector2i()"],
[TYPE_VECTOR2I, Vector2i(1,2), "Vector2i(1, 2)"],
[TYPE_VECTOR3, Vector3(), "Vector3()"],
[TYPE_VECTOR3, Vector3(1,2,3), "Vector3(1, 2, 3)"],
[TYPE_VECTOR3I, Vector3i(), "Vector3i()"],
[TYPE_VECTOR3I, Vector3i(1,2,3), "Vector3i(1, 2, 3)"],
[TYPE_VECTOR4, Vector4(), "Vector4()"],
[TYPE_VECTOR4, Vector4(1,2,3,4), "Vector4(1, 2, 3, 4)"],
[TYPE_VECTOR4I, Vector4i(), "Vector4i()"],
[TYPE_VECTOR4I, Vector4i(1,2,3,4), "Vector4i(1, 2, 3, 4)"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Rect2(variant_type :int, value, expected :String, test_parameters := [
[TYPE_RECT2, Rect2(), "Rect2()"],
[TYPE_RECT2, Rect2(1,2, 10,20), "Rect2(Vector2(1, 2), Vector2(10, 20))"],
[TYPE_RECT2I, Rect2i(), "Rect2i()"],
[TYPE_RECT2I, Rect2i(1,2, 10,20), "Rect2i(Vector2i(1, 2), Vector2i(10, 20))"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Transforms(variant_type :int, value, expected :String, test_parameters := [
[TYPE_TRANSFORM2D, Transform2D(),
"Transform2D()"],
[TYPE_TRANSFORM2D, Transform2D(2.0, Vector2(1,2)),
"Transform2D(Vector2(-0.416147, 0.909297), Vector2(-0.909297, -0.416147), Vector2(1, 2))"],
[TYPE_TRANSFORM2D, Transform2D(2.0, Vector2(1,2), 2.0, Vector2(3,4)),
"Transform2D(Vector2(-0.416147, 0.909297), Vector2(1.513605, -1.307287), Vector2(3, 4))"],
[TYPE_TRANSFORM2D, Transform2D(Vector2(1,2), Vector2(3,4), Vector2.ONE),
"Transform2D(Vector2(1, 2), Vector2(3, 4), Vector2(1, 1))"],
[TYPE_TRANSFORM3D, Transform3D(),
"Transform3D()"],
[TYPE_TRANSFORM3D, Transform3D(Basis.FLIP_X, Vector3.ONE),
"Transform3D(Vector3(-1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), Vector3(1, 1, 1))"],
[TYPE_TRANSFORM3D, Transform3D(Vector3(1,2,3), Vector3(4,5,6), Vector3(7,8,9), Vector3.ONE),
"Transform3D(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 1, 1))"],
[TYPE_PROJECTION, Projection(),
"Projection(Vector4(1, 0, 0, 0), Vector4(0, 1, 0, 0), Vector4(0, 0, 1, 0), Vector4(0, 0, 0, 1))"],
[TYPE_PROJECTION, Projection(Vector4.ONE, Vector4.ONE*2, Vector4.ONE*3, Vector4.ZERO),
"Projection(Vector4(1, 1, 1, 1), Vector4(2, 2, 2, 2), Vector4(3, 3, 3, 3), Vector4(0, 0, 0, 0))"]
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Plane(variant_type :int, value, expected :String, test_parameters := [
[TYPE_PLANE, Plane(), "Plane()"],
[TYPE_PLANE, Plane(1,2,3,4), "Plane(1, 2, 3, 4)"],
[TYPE_PLANE, Plane(Vector3.ONE, Vector3.ZERO), "Plane(1, 1, 1, 0)"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Quaternion(variant_type :int, value, expected :String, test_parameters := [
[TYPE_QUATERNION, Quaternion(), "Quaternion()"],
[TYPE_QUATERNION, Quaternion(1,2,3,4), "Quaternion(1, 2, 3, 4)"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_AABB(variant_type :int, value, expected :String, test_parameters := [
[TYPE_AABB, AABB(), "AABB()"],
[TYPE_AABB, AABB(Vector3.ONE, Vector3(10,20,30)), "AABB(Vector3(1, 1, 1), Vector3(10, 20, 30))"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Basis(variant_type :int, value, expected :String, test_parameters := [
[TYPE_BASIS, Basis(), "Basis()"],
[TYPE_BASIS, Basis(Vector3(0.1,0.2,0.3).normalized(), .1),
"Basis(Vector3(0.995361, 0.080758, -0.052293), Vector3(-0.079331, 0.996432, 0.028823), Vector3(0.054434, -0.024541, 0.998216))"],
[TYPE_BASIS, Basis(Vector3.ONE, Vector3.ONE*2, Vector3.ONE*3),
"Basis(Vector3(1, 1, 1), Vector3(2, 2, 2), Vector3(3, 3, 3))"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Color(variant_type :int, value, expected :String, test_parameters := [
[TYPE_COLOR, Color(), "Color()"],
[TYPE_COLOR, Color.RED, "Color(1, 0, 0, 1)"],
[TYPE_COLOR, Color(1,.2,.5,.5), "Color(1, 0.2, 0.5, 0.5)"],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_NodePath(variant_type :int, value, expected :String, test_parameters := [
[TYPE_NODE_PATH, NodePath(), 'NodePath()'],
[TYPE_NODE_PATH, NodePath("/foo/bar"), 'NodePath("/foo/bar")'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_RID(variant_type :int, value, expected :String, test_parameters := [
[TYPE_RID, RID(), 'RID()'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func _test_decode_Object(variant_type :int, value, expected :String, test_parameters := [
[TYPE_OBJECT, Node.new(), 'Node.new()'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Callable(variant_type :int, value, expected :String, test_parameters := [
[TYPE_CALLABLE, Callable(), 'Callable()'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Signal(variant_type :int, value, expected :String, test_parameters := [
[TYPE_SIGNAL, Signal(), 'Signal()'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Dictionary(variant_type :int, value, expected :String, test_parameters := [
[TYPE_DICTIONARY, {}, '{}'],
[TYPE_DICTIONARY, Dictionary(), '{}'],
[TYPE_DICTIONARY, {1:2, 2:3}, '{ 1: 2, 2: 3 }'],
[TYPE_DICTIONARY, {"aa":2, "bb":"cc"}, '{ "aa": 2, "bb": "cc" }'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_Array(variant_type :int, value, expected :String, test_parameters := [
[TYPE_ARRAY, [], '[]'],
[TYPE_ARRAY, Array(), '[]'],
[TYPE_ARRAY, [1,2,3], '[1, 2, 3]'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1
@warning_ignore("unused_parameter")
func test_decode_typedArrays(variant_type :int, value, expected :String, test_parameters := [
[TYPE_PACKED_BYTE_ARRAY, PackedByteArray(),
'PackedByteArray()'],
[TYPE_PACKED_BYTE_ARRAY, PackedByteArray([1, 2, 3]),
'PackedByteArray([1, 2, 3])'],
[TYPE_PACKED_COLOR_ARRAY, PackedColorArray(),
'PackedColorArray()'],
[TYPE_PACKED_COLOR_ARRAY, PackedColorArray([Color.RED, Color.BLUE]),
'PackedColorArray([Color(1, 0, 0, 1), Color(0, 0, 1, 1)])'],
[TYPE_PACKED_FLOAT32_ARRAY, PackedFloat32Array(),
'PackedFloat32Array()'],
[TYPE_PACKED_FLOAT32_ARRAY, PackedFloat32Array([1.2, 2.3]),
'PackedFloat32Array([1.20000004768372, 2.29999995231628])'],
[TYPE_PACKED_FLOAT64_ARRAY, PackedFloat64Array(),
'PackedFloat64Array()'],
[TYPE_PACKED_FLOAT64_ARRAY, PackedFloat64Array([1.2, 2.3]),
'PackedFloat64Array([1.2, 2.3])'],
[TYPE_PACKED_INT32_ARRAY, PackedInt32Array(),
'PackedInt32Array()'],
[TYPE_PACKED_INT32_ARRAY, PackedInt32Array([1, 2]),
'PackedInt32Array([1, 2])'],
[TYPE_PACKED_INT64_ARRAY, PackedInt64Array(),
'PackedInt64Array()'],
[TYPE_PACKED_INT64_ARRAY, PackedInt64Array([1, 2]),
'PackedInt64Array([1, 2])'],
[TYPE_PACKED_STRING_ARRAY, PackedStringArray(),
'PackedStringArray()'],
[TYPE_PACKED_STRING_ARRAY, PackedStringArray(["aa", "bb"]),
'PackedStringArray(["aa", "bb"])'],
[TYPE_PACKED_VECTOR2_ARRAY, PackedVector2Array(),
'PackedVector2Array()'],
[TYPE_PACKED_VECTOR2_ARRAY, PackedVector2Array([Vector2.ONE, Vector2.ONE*2]),
'PackedVector2Array([Vector2(1, 1), Vector2(2, 2)])'],
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array(),
'PackedVector3Array()'],
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array([Vector3.ONE, Vector3.ONE*2]),
'PackedVector3Array([Vector3(1, 1, 1), Vector3(2, 2, 2)])'],
]) -> void:
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
_tested_types[variant_type] = 1

View file

@ -0,0 +1,76 @@
# GdUnit generated TestSuite
class_name GdFunctionArgumentTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionArgument.gd'
func test__parse_argument_as_array_typ1() -> void:
var test_parameters := """[
[1, "flowchart TD\nid>This is a flag shaped node]"],
[
2,
"flowchart TD\nid(((This is a\tdouble circle node)))"
],
[3,
"flowchart TD\nid((This is a circular node))"],
[
4, "flowchart TD\nid>This is a flag shaped node]"
],
[5, "flowchart TD\nid{'This is a rhombus node'}"],
[6, 'flowchart TD\nid((This is a circular node))'],
[7, 'flowchart TD\nid>This is a flag shaped node]'], [8, 'flowchart TD\nid{"This is a rhombus node"}'],
[9, \"\"\"
flowchart TD
id{"This is a rhombus node"}
\"\"\"]
]"""
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
assert_array(fa.parameter_sets()).contains_exactly([
"""[1, "flowchart TDid>This is a flag shaped node]"]""",
"""[2, "flowchart TDid(((This is a\tdouble circle node)))"]""",
"""[3, "flowchart TDid((This is a circular node))"]""",
"""[4, "flowchart TDid>This is a flag shaped node]"]""",
"""[5, "flowchart TDid{'This is a rhombus node'}"]""",
"""[6, 'flowchart TDid((This is a circular node))']""",
"""[7, 'flowchart TDid>This is a flag shaped node]']""",
"""[8, 'flowchart TDid{"This is a rhombus node"}']""",
"""[9, \"\"\"flowchart TDid{"This is a rhombus node"}\"\"\"]"""
]
)
func test__parse_argument_as_array_typ2() -> void:
var test_parameters := """[
["test_a", null, "LOG", {}],
[
"test_b",
Node2D,
null,
{Node2D: "ER,ROR"}
],
[
"test_c",
Node2D,
"LOG",
{Node2D: "LOG"}
]
]"""
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
assert_array(fa.parameter_sets()).contains_exactly([
"""["test_a", null, "LOG", {}]""",
"""["test_b", Node2D, null, {Node2D: "ER,ROR"}]""",
"""["test_c", Node2D, "LOG", {Node2D: "LOG"}]"""
]
)
func test__parse_argument_as_reference() -> void:
var test_parameters := "_test_args()"
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
assert_array(fa.parameter_sets()).is_empty()

View file

@ -0,0 +1,146 @@
# GdUnit generated TestSuite
class_name GdFunctionDescriptorTest
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd'
# helper to get method descriptor
func get_method_description(clazz_name :String, method_name :String) -> Dictionary:
var method_list :Array = ClassDB.class_get_method_list(clazz_name)
for method_descriptor in method_list:
if method_descriptor["name"] == method_name:
return method_descriptor
return Dictionary()
func test_extract_from_func_without_return_type():
# void add_sibling(sibling: Node, force_readable_name: bool = false)
var method_descriptor := get_method_description("Node", "add_sibling")
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
assert_str(fd.name()).is_equal("add_sibling")
assert_bool(fd.is_virtual()).is_false()
assert_bool(fd.is_static()).is_false()
assert_bool(fd.is_engine()).is_true()
assert_bool(fd.is_vararg()).is_false()
assert_int(fd.return_type()).is_equal(TYPE_NIL)
assert_array(fd.args()).contains_exactly([
GdFunctionArgument.new("sibling_", GdObjects.TYPE_NODE),
GdFunctionArgument.new("force_readable_name_", TYPE_BOOL, "false")
])
# void add_sibling(node: Node, child_node: Node, legible_unique_name: bool = false)
assert_str(fd.typeless()).is_equal("func add_sibling(sibling_, force_readable_name_=false) -> void:")
func test_extract_from_func_with_return_type():
# Node find_child(pattern: String, recursive: bool = true, owned: bool = true) const
var method_descriptor := get_method_description("Node", "find_child")
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
assert_str(fd.name()).is_equal("find_child")
assert_bool(fd.is_virtual()).is_false()
assert_bool(fd.is_static()).is_false()
assert_bool(fd.is_engine()).is_true()
assert_bool(fd.is_vararg()).is_false()
assert_int(fd.return_type()).is_equal(TYPE_OBJECT)
assert_array(fd.args()).contains_exactly([
GdFunctionArgument.new("pattern_", TYPE_STRING),
GdFunctionArgument.new("recursive_", TYPE_BOOL, "true"),
GdFunctionArgument.new("owned_", TYPE_BOOL, "true"),
])
# Node find_child(mask: String, recursive: bool = true, owned: bool = true) const
assert_str(fd.typeless()).is_equal("func find_child(pattern_, recursive_=true, owned_=true) -> Node:")
func test_extract_from_func_with_vararg():
# Error emit_signal(signal: StringName, ...) vararg
var method_descriptor := get_method_description("Node", "emit_signal")
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
assert_str(fd.name()).is_equal("emit_signal")
assert_bool(fd.is_virtual()).is_false()
assert_bool(fd.is_static()).is_false()
assert_bool(fd.is_engine()).is_true()
assert_bool(fd.is_vararg()).is_true()
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
assert_array(fd.args()).contains_exactly([GdFunctionArgument.new("signal_", TYPE_STRING_NAME)])
assert_array(fd.varargs()).contains_exactly([
GdFunctionArgument.new("vararg0_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg1_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg2_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg3_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg4_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg5_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg6_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg7_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg8_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
GdFunctionArgument.new("vararg9_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE)
])
assert_str(fd.typeless()).is_equal("func emit_signal(signal_, vararg0_=\"__null__\", vararg1_=\"__null__\", vararg2_=\"__null__\", vararg3_=\"__null__\", vararg4_=\"__null__\", vararg5_=\"__null__\", vararg6_=\"__null__\", vararg7_=\"__null__\", vararg8_=\"__null__\", vararg9_=\"__null__\") -> Error:")
func test_extract_from_descriptor_is_virtual_func():
var method_descriptor := get_method_description("Node", "_enter_tree")
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
assert_str(fd.name()).is_equal("_enter_tree")
assert_bool(fd.is_virtual()).is_true()
assert_bool(fd.is_static()).is_false()
assert_bool(fd.is_engine()).is_true()
assert_bool(fd.is_vararg()).is_false()
assert_int(fd.return_type()).is_equal(TYPE_NIL)
assert_array(fd.args()).is_empty()
# void _enter_tree() virtual
assert_str(fd.typeless()).is_equal("func _enter_tree() -> void:")
func test_extract_from_descriptor_is_virtual_func_full_check():
var methods := ClassDB.class_get_method_list("Node")
var expected_virtual_functions := [
# Object virtuals
"_get",
"_get_property_list",
"_init",
"_notification",
"_property_can_revert",
"_property_get_revert",
"_set",
"_to_string",
# Note virtuals
"_enter_tree",
"_exit_tree",
"_get_configuration_warnings",
"_input",
"_physics_process",
"_process",
"_ready",
"_shortcut_input",
"_unhandled_input",
"_unhandled_key_input"
]
# since Godot 4.2 there are more virtual functions
if Engine.get_version_info().hex >= 0x40200:
expected_virtual_functions.append("_validate_property")
var _count := 0
for method_descriptor in methods:
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
if fd.is_virtual():
_count += 1
assert_array(expected_virtual_functions).contains([fd.name()])
assert_int(_count).is_equal(expected_virtual_functions.size())
func test_extract_from_func_with_return_type_variant():
var method_descriptor := get_method_description("Node", "get")
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
assert_str(fd.name()).is_equal("get")
assert_bool(fd.is_virtual()).is_false()
assert_bool(fd.is_static()).is_false()
assert_bool(fd.is_engine()).is_true()
assert_bool(fd.is_vararg()).is_false()
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
assert_array(fd.args()).contains_exactly([
GdFunctionArgument.new("property_", TYPE_STRING_NAME),
])
# Variant get(property: String) const
assert_str(fd.typeless()).is_equal("func get(property_) -> Variant:")

View file

@ -0,0 +1,632 @@
extends GdUnitTestSuite
var _parser: GdScriptParser
func before():
_parser = GdScriptParser.new()
func test_parse_argument():
# create example row whit different assignment types
var row = "func test_foo(arg1 = 41, arg2 := 42, arg3 : int = 43)"
assert_that(_parser.parse_argument(row, "arg1", 23)).is_equal(41)
assert_that(_parser.parse_argument(row, "arg2", 23)).is_equal(42)
assert_that(_parser.parse_argument(row, "arg3", 23)).is_equal(43)
func test_parse_argument_default_value():
# arg4 not exists expect to return the default value
var row = "func test_foo(arg1 = 41, arg2 := 42, arg3 : int = 43)"
assert_that(_parser.parse_argument(row, "arg4", 23)).is_equal(23)
func test_parse_argument_has_no_arguments():
assert_that(_parser.parse_argument("func test_foo()", "arg4", 23)).is_equal(23)
func test_parse_argument_with_bad_formatting():
var row = "func test_foo( arg1 = 41, arg2 : = 42, arg3 : int = 43 )"
assert_that(_parser.parse_argument(row, "arg3", 23)).is_equal(43)
func test_parse_argument_with_same_func_name():
var row = "func test_arg1(arg1 = 41)"
assert_that(_parser.parse_argument(row, "arg1", 23)).is_equal(41)
func test_parse_argument_timeout():
var DEFAULT_TIMEOUT = 1000
assert_that(_parser.parse_argument("func test_foo()", "timeout", DEFAULT_TIMEOUT)).is_equal(DEFAULT_TIMEOUT)
assert_that(_parser.parse_argument("func test_foo(timeout = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
assert_that(_parser.parse_argument("func test_foo(timeout: = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
assert_that(_parser.parse_argument("func test_foo(timeout:int = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
assert_that(_parser.parse_argument("func test_foo(arg1 = false, timeout=2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
func test_parse_arguments():
assert_array(_parser.parse_arguments("func foo():")) \
.has_size(0)
assert_array(_parser.parse_arguments("func foo() -> String:\n")) \
.has_size(0)
assert_array(_parser.parse_arguments("func foo(arg1, arg2, name):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_NIL),
GdFunctionArgument.new("arg2", TYPE_NIL),
GdFunctionArgument.new("name", TYPE_NIL)])
assert_array(_parser.parse_arguments('func foo(arg1 :int, arg2 :bool, name :String = "abc"):')) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_INT),
GdFunctionArgument.new("arg2", TYPE_BOOL),
GdFunctionArgument.new("name", TYPE_STRING, '"abc"')])
assert_array(_parser.parse_arguments('func bar(arg1 :int, arg2 :int = 23, name :String = "test") -> String:')) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_INT),
GdFunctionArgument.new("arg2", TYPE_INT, "23"),
GdFunctionArgument.new("name", TYPE_STRING, '"test"')])
assert_array(_parser.parse_arguments("func foo(arg1, arg2=value(1,2,3), name:=foo()):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_NIL),
GdFunctionArgument.new("arg2", GdObjects.TYPE_FUNC, "value(1,2,3)"),
GdFunctionArgument.new("name", GdObjects.TYPE_FUNC, "foo()")])
# enum as prefix in value name
assert_array(_parser.parse_arguments("func get_value( type := ENUM_A) -> int:"))\
.contains_exactly([GdFunctionArgument.new("type", TYPE_STRING, "ENUM_A")])
assert_array(_parser.parse_arguments("func create_timer(timeout :float) -> Timer:")) \
.contains_exactly([
GdFunctionArgument.new("timeout", TYPE_FLOAT)])
# array argument
assert_array(_parser.parse_arguments("func foo(a :int, b :int, parameters = [[1, 2], [3, 4], [5, 6]]):")) \
.contains_exactly([
GdFunctionArgument.new("a", TYPE_INT),
GdFunctionArgument.new("b", TYPE_INT),
GdFunctionArgument.new("parameters", TYPE_ARRAY, "[[1, 2], [3, 4], [5, 6]]")])
assert_array(_parser.parse_arguments("func test_values(a:Vector2, b:Vector2, expected:Vector2, test_parameters:=[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]):"))\
.contains_exactly([
GdFunctionArgument.new("a", TYPE_VECTOR2),
GdFunctionArgument.new("b", TYPE_VECTOR2),
GdFunctionArgument.new("expected", TYPE_VECTOR2),
GdFunctionArgument.new("test_parameters", TYPE_ARRAY, "[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]"),
])
func test_parse_arguments_with_super_constructor():
assert_array(_parser.parse_arguments('func foo().foo("abc"):')).is_empty()
assert_array(_parser.parse_arguments('func foo(arg1 = "arg").foo("abc", arg1):'))\
.contains_exactly([GdFunctionArgument.new("arg1", TYPE_STRING, '"arg"')])
func test_parse_arguments_default_build_in_type_String():
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2="default"):')) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2 :="default"):')) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2 :String ="default"):')) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
func test_parse_arguments_default_build_in_type_Boolean():
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=false):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=false):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :bool=false):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
func test_parse_arguments_default_build_in_type_Real():
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=3.14):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=3.14):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :float=3.14):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
func test_parse_arguments_default_build_in_type_Array():
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[]):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[]")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=Array()):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_ARRAY, "Array()")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3]):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=[1, 2, 3]):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=[]):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[]")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3], arg3 := false):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]"),
GdFunctionArgument.new("arg3", TYPE_BOOL, "false")])
func test_parse_arguments_default_build_in_type_Color():
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=Color.RED):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=Color.RED):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Color=Color.RED):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
func test_parse_arguments_default_build_in_type_Vector():
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 =Vector3.FORWARD):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :=Vector3.FORWARD):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :Vector3=Vector3.FORWARD):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
func test_parse_arguments_default_build_in_type_AABB():
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 := AABB()):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_AABB, "AABB()")])
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :AABB=AABB()):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_AABB, "AABB()")])
func test_parse_arguments_default_build_in_types():
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 := Vector3.FORWARD, aabb := AABB()):")) \
.contains_exactly([
GdFunctionArgument.new("arg1", TYPE_STRING),
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD"),
GdFunctionArgument.new("aabb", TYPE_AABB, "AABB()")])
func test_parse_arguments_fuzzers() -> void:
assert_array(_parser.parse_arguments("func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(), fuzzer_c :Fuzzer = fuzz_c(), fuzzer_iterations = 234, fuzzer_seed = 100):")) \
.contains_exactly([
GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "fuzz_a()"),
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "fuzz_b()"),
GdFunctionArgument.new("fuzzer_c", GdObjects.TYPE_FUZZER, "fuzz_c()"),
GdFunctionArgument.new("fuzzer_iterations", TYPE_INT, "234"),
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, "100"),])
func test_parse_arguments_no_function():
assert_array(_parser.parse_arguments("var x:=10")) \
.has_size(0)
class TestObject:
var x
func test_parse_function_return_type():
assert_that(_parser.parse_func_return_type("func foo():")).is_equal(TYPE_NIL)
assert_that(_parser.parse_func_return_type("func foo() -> void:")).is_equal(GdObjects.TYPE_VOID)
assert_that(_parser.parse_func_return_type("func foo() -> TestObject:")).is_equal(TYPE_OBJECT)
assert_that(_parser.parse_func_return_type("func foo() -> bool:")).is_equal(TYPE_BOOL)
assert_that(_parser.parse_func_return_type("func foo() -> String:")).is_equal(TYPE_STRING)
assert_that(_parser.parse_func_return_type("func foo() -> int:")).is_equal(TYPE_INT)
assert_that(_parser.parse_func_return_type("func foo() -> float:")).is_equal(TYPE_FLOAT)
assert_that(_parser.parse_func_return_type("func foo() -> Vector2:")).is_equal(TYPE_VECTOR2)
assert_that(_parser.parse_func_return_type("func foo() -> Rect2:")).is_equal(TYPE_RECT2)
assert_that(_parser.parse_func_return_type("func foo() -> Vector3:")).is_equal(TYPE_VECTOR3)
assert_that(_parser.parse_func_return_type("func foo() -> Transform2D:")).is_equal(TYPE_TRANSFORM2D)
assert_that(_parser.parse_func_return_type("func foo() -> Plane:")).is_equal(TYPE_PLANE)
assert_that(_parser.parse_func_return_type("func foo() -> Quaternion:")).is_equal(TYPE_QUATERNION)
assert_that(_parser.parse_func_return_type("func foo() -> AABB:")).is_equal(TYPE_AABB)
assert_that(_parser.parse_func_return_type("func foo() -> Basis:")).is_equal(TYPE_BASIS)
assert_that(_parser.parse_func_return_type("func foo() -> Transform3D:")).is_equal(TYPE_TRANSFORM3D)
assert_that(_parser.parse_func_return_type("func foo() -> Color:")).is_equal(TYPE_COLOR)
assert_that(_parser.parse_func_return_type("func foo() -> NodePath:")).is_equal(TYPE_NODE_PATH)
assert_that(_parser.parse_func_return_type("func foo() -> RID:")).is_equal(TYPE_RID)
assert_that(_parser.parse_func_return_type("func foo() -> Dictionary:")).is_equal(TYPE_DICTIONARY)
assert_that(_parser.parse_func_return_type("func foo() -> Array:")).is_equal(TYPE_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedByteArray:")).is_equal(TYPE_PACKED_BYTE_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedInt32Array:")).is_equal(TYPE_PACKED_INT32_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedFloat32Array:")).is_equal(TYPE_PACKED_FLOAT32_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedStringArray:")).is_equal(TYPE_PACKED_STRING_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedVector2Array:")).is_equal(TYPE_PACKED_VECTOR2_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedVector3Array:")).is_equal(TYPE_PACKED_VECTOR3_ARRAY)
assert_that(_parser.parse_func_return_type("func foo() -> PackedColorArray:")).is_equal(TYPE_PACKED_COLOR_ARRAY)
func test_parse_func_name():
assert_str(_parser.parse_func_name("func foo():")).is_equal("foo")
assert_str(_parser.parse_func_name("static func foo():")).is_equal("foo")
assert_str(_parser.parse_func_name("func a() -> String:")).is_equal("a")
# function name contains tokens e.g func or class
assert_str(_parser.parse_func_name("func foo_func_class():")).is_equal("foo_func_class")
# should fail
assert_str(_parser.parse_func_name("#func foo():")).is_empty()
assert_str(_parser.parse_func_name("var x")).is_empty()
func test_extract_source_code():
var path := GdObjects.extract_class_path(AdvancedTestClass)
var rows = _parser.extract_source_code(path)
var file_content := resource_as_array(path[0])
assert_array(rows).contains_exactly(file_content)
func test_extract_source_code_inner_class_AtmosphereData():
var path := GdObjects.extract_class_path(AdvancedTestClass.AtmosphereData)
var rows = _parser.extract_source_code(path)
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/AtmosphereData.txt")
assert_array(rows).contains_exactly(file_content)
func test_extract_source_code_inner_class_SoundData():
var path := GdObjects.extract_class_path(AdvancedTestClass.SoundData)
var rows = _parser.extract_source_code(path)
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/SoundData.txt")
assert_array(rows).contains_exactly(file_content)
func test_extract_source_code_inner_class_Area4D():
var path := GdObjects.extract_class_path(AdvancedTestClass.Area4D)
var rows = _parser.extract_source_code(path)
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/Area4D.txt")
assert_array(rows).contains_exactly(file_content)
func test_extract_function_signature() -> void:
var path := GdObjects.extract_class_path("res://addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd")
var rows = _parser.extract_source_code(path)
assert_that(_parser.extract_func_signature(rows, 12))\
.is_equal("""
func a1(set_name:String, path:String="", load_on_init:bool=false,
set_auto_save:bool=false, set_network_sync:bool=false
) -> void:""".dedent().trim_prefix("\n"))
assert_that(_parser.extract_func_signature(rows, 19))\
.is_equal("""
func a2(set_name:String, path:String="", load_on_init:bool=false,
set_auto_save:bool=false, set_network_sync:bool=false
) -> void:""".dedent().trim_prefix("\n"))
assert_that(_parser.extract_func_signature(rows, 26))\
.is_equal("""
func a3(set_name:String, path:String="", load_on_init:bool=false,
set_auto_save:bool=false, set_network_sync:bool=false
) :""".dedent().trim_prefix("\n"))
assert_that(_parser.extract_func_signature(rows, 33))\
.is_equal("""
func a4(set_name:String,
path:String="",
load_on_init:bool=false,
set_auto_save:bool=false,
set_network_sync:bool=false
):""".dedent().trim_prefix("\n"))
assert_that(_parser.extract_func_signature(rows, 43))\
.is_equal("""
func a5(
value : Array,
expected : String,
test_parameters : Array = [
[ ["a"], "a" ],
[ ["a", "very", "long", "argument"], "a very long argument" ],
]
):""".dedent().trim_prefix("\n"))
func test_strip_leading_spaces():
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("")).is_empty()
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_empty()
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_empty()
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_equal(" ")
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("var x=")).is_equal("var x=")
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("class foo")).is_equal("class foo")
func test_extract_clazz_name():
assert_str(_parser.extract_clazz_name("classSoundData:\n")).is_equal("SoundData")
assert_str(_parser.extract_clazz_name("classSoundDataextendsNode:\n")).is_equal("SoundData")
func test_is_virtual_func() -> void:
# checked non virtual func
assert_bool(_parser.is_virtual_func("UnknownClass", [""], "")).is_false()
assert_bool(_parser.is_virtual_func("Node", [""], "")).is_false()
assert_bool(_parser.is_virtual_func("Node", [""], "func foo():")).is_false()
# checked virtual func
assert_bool(_parser.is_virtual_func("Node", [""], "_exit_tree")).is_true()
assert_bool(_parser.is_virtual_func("Node", [""], "_ready")).is_true()
assert_bool(_parser.is_virtual_func("Node", [""], "_init")).is_true()
func test_is_static_func():
assert_bool(_parser.is_static_func("")).is_false()
assert_bool(_parser.is_static_func("var a=0")).is_false()
assert_bool(_parser.is_static_func("func foo():")).is_false()
assert_bool(_parser.is_static_func("func foo() -> void:")).is_false()
assert_bool(_parser.is_static_func("static func foo():")).is_true()
assert_bool(_parser.is_static_func("static func foo() -> void:")).is_true()
func test_parse_func_description():
var fd := _parser.parse_func_description("func foo():", "clazz_name", [""], 10)
assert_str(fd.name()).is_equal("foo")
assert_bool(fd.is_static()).is_false()
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
assert_array(fd.args()).is_empty()
assert_str(fd.typeless()).is_equal("func foo() -> Variant:")
# static function
fd = _parser.parse_func_description("static func foo(arg1 :int, arg2:=false) -> String:", "clazz_name", [""], 22)
assert_str(fd.name()).is_equal("foo")
assert_bool(fd.is_static()).is_true()
assert_int(fd.return_type()).is_equal(TYPE_STRING)
assert_array(fd.args()).contains_exactly([
GdFunctionArgument.new("arg1", TYPE_INT),
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")
])
assert_str(fd.typeless()).is_equal("static func foo(arg1, arg2=false) -> String:")
# static function without return type
fd = _parser.parse_func_description("static func foo(arg1 :int, arg2:=false):", "clazz_name", [""], 23)
assert_str(fd.name()).is_equal("foo")
assert_bool(fd.is_static()).is_true()
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
assert_array(fd.args()).contains_exactly([
GdFunctionArgument.new("arg1", TYPE_INT),
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")
])
assert_str(fd.typeless()).is_equal("static func foo(arg1, arg2=false) -> Variant:")
func test_parse_func_description_return_type_enum():
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
assert_result(result).is_success()
var fd := _parser.parse_func_description("func get_enum() -> TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
assert_that(fd.name()).is_equal("get_enum")
assert_that(fd.is_static()).is_false()
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
assert_that(fd._return_class).is_equal("ClassWithEnumReturnTypes.TEST_ENUM")
assert_that(fd.args()).is_empty()
func test_parse_func_description_return_type_internal_class_enum():
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
assert_result(result).is_success()
var fd := _parser.parse_func_description("func get_inner_class_enum() -> InnerClass.TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
assert_that(fd.name()).is_equal("get_inner_class_enum")
assert_that(fd.is_static()).is_false()
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
assert_that(fd._return_class).is_equal("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")
assert_that(fd.args()).is_empty()
func test_parse_func_description_return_type_external_class_enum():
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
assert_result(result).is_success()
var fd := _parser.parse_func_description("func get_external_class_enum() -> CustomEnums.TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
assert_that(fd.name()).is_equal("get_external_class_enum")
assert_that(fd.is_static()).is_false()
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
assert_that(fd._return_class).is_equal("CustomEnums.TEST_ENUM")
assert_that(fd.args()).is_empty()
func test_parse_class_inherits():
var clazz_path := GdObjects.extract_class_path(CustomClassExtendsCustomClass)
var clazz_name := GdObjects.extract_class_name_from_class_path(clazz_path)
var result := _parser.parse(clazz_name, clazz_path)
assert_result(result).is_success()
# verify class extraction
var clazz_desccriptor :GdClassDescriptor = result.value()
assert_object(clazz_desccriptor).is_not_null()
assert_str(clazz_desccriptor.name()).is_equal("CustomClassExtendsCustomClass")
assert_bool(clazz_desccriptor.is_inner_class()).is_false()
assert_array(clazz_desccriptor.functions()).contains_exactly([
GdFunctionDescriptor.new("foo2", 5, false, false, false, GdObjects.TYPE_VARIANT, "", []),
GdFunctionDescriptor.new("bar2", 8, false, false, false, TYPE_STRING, "", [])
])
# extends from CustomResourceTestClass
clazz_desccriptor = clazz_desccriptor.parent()
assert_object(clazz_desccriptor).is_not_null()
assert_str(clazz_desccriptor.name()).is_equal("CustomResourceTestClass")
assert_bool(clazz_desccriptor.is_inner_class()).is_false()
assert_array(clazz_desccriptor.functions()).contains_exactly([
GdFunctionDescriptor.new("foo", 4, false, false, false, TYPE_STRING, "", []),
GdFunctionDescriptor.new("foo2", 7, false, false, false, GdObjects.TYPE_VARIANT, "", []),
GdFunctionDescriptor.new("foo_void", 10, false, false, false, GdObjects.TYPE_VOID, "", []),
GdFunctionDescriptor.new("bar", 13, false, false, false, TYPE_STRING, "", [
GdFunctionArgument.new("arg1", TYPE_INT),
GdFunctionArgument.new("arg2", TYPE_INT, "23"),
GdFunctionArgument.new("name", TYPE_STRING, '"test"'),
]),
GdFunctionDescriptor.new("foo5", 16, false, false, false, GdObjects.TYPE_VARIANT, "", []),
])
# no other class extends
clazz_desccriptor = clazz_desccriptor.parent()
assert_object(clazz_desccriptor).is_null()
func test_get_class_name_pascal_case() -> void:
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd")))\
.is_equal("PascalCaseWithClassName")
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd")))\
.is_equal("PascalCaseWithoutClassName")
func test_get_class_name_snake_case() -> void:
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd")))\
.is_equal("SnakeCaseWithClassName")
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd")))\
.is_equal("SnakeCaseWithoutClassName")
func test_is_func_end() -> void:
assert_bool(_parser.is_func_end("")).is_false()
assert_bool(_parser.is_func_end("func test_a():")).is_true()
assert_bool(_parser.is_func_end("func test_a() -> void:")).is_true()
assert_bool(_parser.is_func_end("func test_a(arg1) :")).is_true()
assert_bool(_parser.is_func_end("func test_a(arg1 ): ")).is_true()
assert_bool(_parser.is_func_end("func test_a(arg1 ): ")).is_true()
assert_bool(_parser.is_func_end(" ):")).is_true()
assert_bool(_parser.is_func_end(" ):")).is_true()
assert_bool(_parser.is_func_end(" -> void:")).is_true()
assert_bool(_parser.is_func_end(" ) -> void :")).is_true()
assert_bool(_parser.is_func_end("func test_a(arg1, arg2 = {1:2} ):")).is_true()
func test_extract_func_signature_multiline() -> void:
var source_code = """
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
[1, 2, 3, 6],
[3, 4, 5, 11],
[6, 7, 8, 21] ]):
assert_that(a+b+c).is_equal(expected)
""".dedent().split("\n")
var fs = _parser.extract_func_signature(source_code, 0)
assert_that(fs).is_equal("""
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
[1, 2, 3, 6],
[3, 4, 5, 11],
[6, 7, 8, 21] ]):"""
.dedent()
.trim_prefix("\n")
)
func test_parse_func_description_paramized_test():
var fd = _parser.parse_func_description("functest_parameterized(a:int,b:int,c:int,expected:int,parameters=[[1,2,3,6],[3,4,5,11],[6,7,8,21]]):", "class", ["path"], 22)
assert_that(fd).is_equal(GdFunctionDescriptor.new("test_parameterized", 22, false, false, false, GdObjects.TYPE_VARIANT, "", [
GdFunctionArgument.new("a", TYPE_INT),
GdFunctionArgument.new("b", TYPE_INT),
GdFunctionArgument.new("c", TYPE_INT),
GdFunctionArgument.new("expected", TYPE_INT),
GdFunctionArgument.new("parameters", TYPE_ARRAY, "[[1,2,3,6],[3,4,5,11],[6,7,8,21]]"),
]))
func test_parse_func_description_paramized_test_with_comments() -> void:
var source_code = """
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
# before data set
[1, 2, 3, 6], # after data set
# between data sets
[3, 4, 5, 11],
[6, 7, 'string #ABCD', 21], # dataset with [comment] singn
[6, 7, "string #ABCD", 21] # dataset with "#comment" singn
#eof
]):
pass
""".dedent().split("\n")
var fs = _parser.extract_func_signature(source_code, 0)
assert_that(fs).is_equal("""
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
[1, 2, 3, 6],
[3, 4, 5, 11],
[6, 7, 'string #ABCD', 21],
[6, 7, "string #ABCD", 21]
]):"""
.dedent()
.trim_prefix("\n")
)
func test_parse_func_descriptor_with_fuzzers():
var source_code := """
func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(),
fuzzer_c :Fuzzer = fuzz_c(),
fuzzer = Fuzzers.random_rangei(-23, 22),
fuzzer_iterations = 234,
fuzzer_seed = 100):
""".split("\n")
var fs = _parser.extract_func_signature(source_code, 0)
var fd = _parser.parse_func_description(fs, "class", ["path"], 22)
assert_that(fd).is_equal(GdFunctionDescriptor.new("test_foo", 22, false, false, false, GdObjects.TYPE_VARIANT, "", [
GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "fuzz_a()"),
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "fuzz_b()"),
GdFunctionArgument.new("fuzzer_c", GdObjects.TYPE_FUZZER, "fuzz_c()"),
GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.random_rangei(-23, 22)"),
GdFunctionArgument.new("fuzzer_iterations", TYPE_INT, "234"),
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, "100")
]))
func test_is_class_enum_type() -> void:
var parser := GdScriptParser.new()
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")).is_true()
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.InnerClass")).is_false()
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.TEST_ENUM")).is_true()
assert_that(parser.is_class_enum_type("CustomEnums.TEST_ENUM")).is_true()
assert_that(parser.is_class_enum_type("CustomEnums")).is_false()
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.NOT_AN_ENUM")).is_false()

View file

@ -0,0 +1,65 @@
# GdUnit generated TestSuite
class_name GdUnitExpressionsTest
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
@warning_ignore('return_value_discarded')
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitExpressionRunner.gd'
const TestFuzzers := preload("res://addons/gdUnit4/test/fuzzers/TestFuzzers.gd")
func test_create_fuzzer_argument_default():
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(-10, 22)")
assert_that(fuzzer).is_not_null()
assert_that(fuzzer).is_instanceof(Fuzzer)
assert_int(fuzzer.next_value()).is_between(-10, 22)
func test_create_fuzzer_argument_with_constants():
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
assert_that(fuzzer).is_not_null()
assert_that(fuzzer).is_instanceof(Fuzzer)
assert_int(fuzzer.next_value()).is_between(-10, 22)
func test_create_fuzzer_argument_with_custom_function():
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "get_fuzzer()")
assert_that(fuzzer).is_not_null()
assert_that(fuzzer).is_instanceof(Fuzzer)
assert_int(fuzzer.next_value()).is_between(TestFuzzers.MIN_VALUE, TestFuzzers.MAX_VALUE)
func test_create_fuzzer_do_fail():
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "non_fuzzer()")
assert_that(fuzzer).is_null()
func test_create_nested_fuzzer_do_fail():
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "NestedFuzzer.new()")
assert_that(fuzzer).is_not_null()
assert_that(fuzzer is Fuzzer).is_true()
assert_bool(fuzzer is TestFuzzers.NestedFuzzer).is_true()
func test_create_external_fuzzer():
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "TestExternalFuzzer.new()")
assert_that(fuzzer).is_not_null()
assert_that(fuzzer is Fuzzer).is_true()
assert_bool(fuzzer is TestExternalFuzzer).is_true()
func test_create_multipe_fuzzers():
var fuzzer_a := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
var fuzzer_b := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(10, 20)")
assert_that(fuzzer_a).is_not_null()
assert_that(fuzzer_a).is_instanceof(IntFuzzer)
var a :IntFuzzer = fuzzer_a
assert_int(a._from).is_equal(-10)
assert_int(a._to).is_equal(TestFuzzers.MAX_VALUE)
assert_that(fuzzer_b).is_not_null()
assert_that(fuzzer_b).is_instanceof(IntFuzzer)
var b :IntFuzzer = fuzzer_b
assert_int(b._from).is_equal(10)
assert_int(b._to).is_equal(20)

View file

@ -0,0 +1,222 @@
# GdUnit generated TestSuite
extends GdUnitTestSuite
# TestSuite generated from
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd'
var _test_param1 := 10
var _test_param2 := 20
func before():
_test_param1 = 11
func test_before():
_test_param2 = 22
@warning_ignore("unused_parameter")
func test_example_a(a: int, b: int, test_parameters=[[1, 2], [3,4]]) -> void:
pass
@warning_ignore("unused_parameter")
func test_example_b(a: Vector2, b: Vector2, test_parameters=[
[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]] ) -> void:
pass
@warning_ignore("unused_parameter")
func test_example_c(a: Object, b: Object, test_parameters=[
[Resource.new(), Resource.new()],
[Resource.new(), null]
] ) -> void:
pass
@warning_ignore("unused_parameter")
func test_resolve_parameters_static(a: int, b: int, test_parameters=[
[1, 10],
[2, 20]
]) -> void:
pass
@warning_ignore("unused_parameter")
func test_resolve_parameters_at_runtime(a: int, b: int, test_parameters=[
[1, _test_param1],
[2, _test_param2],
[3, 30]
]) -> void:
pass
@warning_ignore("unused_parameter")
func test_parameterized_with_comments(a: int, b :int, c :String, expected :int, test_parameters = [
# before data set
[1, 2, '3', 6], # after data set
# between data sets
[3, 4, '5', 11],
[6, 7, 'string #ABCD', 21], # dataset with [comment] singn
[6, 7, "string #ABCD", 21] # dataset with "comment" singn
#eof
]):
pass
func build_param(value: float) -> Vector3:
return Vector3(value, value, value)
@warning_ignore("unused_parameter")
func test_example_d(a: Vector3, b: Vector3, test_parameters=[
[build_param(1), build_param(3)],
[Vector3.BACK, Vector3.UP]
] ) -> void:
pass
class TestObj extends RefCounted:
var _value: String
func _init(value: String):
_value = value
func _to_string() -> String:
return _value
@warning_ignore("unused_parameter")
func test_example_e(a: Object, b: Object, expected: String, test_parameters:=[
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]):
pass
# verify the used 'test_parameters' is completly resolved
func test_load_parameter_sets() -> void:
var tc := get_test_case("test_example_a")
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([[1, 2], [3, 4]])
tc = get_test_case("test_example_b")
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]])
tc = get_test_case("test_example_c")
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([[Resource.new(), Resource.new()], [Resource.new(), null]])
tc = get_test_case("test_example_d")
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([[Vector3(1, 1, 1), Vector3(3, 3, 3)], [Vector3.BACK, Vector3.UP]])
tc = get_test_case("test_example_e")
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([[TestObj.new("abc"), TestObj.new("def"), "abcdef"]])
func test_load_parameter_sets_at_runtime() -> void:
var tc := get_test_case("test_resolve_parameters_at_runtime")
assert_that(tc).is_not_null()
# check the parameters resolved at runtime
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([
# the value `_test_param1` is changed from 10 to 11 on `before` stage
[1, 11],
# the value `_test_param2` is changed from 20 to 2 on `test_before` stage
[2, 22],
# the value is static initial `30`
[3, 30]])
func test_load_parameter_with_comments() -> void:
var tc := get_test_case("test_parameterized_with_comments")
assert_that(tc).is_not_null()
# check the parameters resolved at runtime
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
.is_equal([
[1, 2, '3', 6],
[3, 4, '5', 11],
[6, 7, 'string #ABCD', 21],
[6, 7, "string #ABCD", 21]])
func test_build_test_case_names_on_static_parameter_set() -> void:
var test_case := get_test_case("test_resolve_parameters_static")
var resolver := test_case.parameter_set_resolver()
assert_array(resolver.build_test_case_names(test_case))\
.contains_exactly([
"test_resolve_parameters_static:0 [1, 10]",
"test_resolve_parameters_static:1 [2, 20]"])
assert_that(resolver.is_parameter_sets_static()).is_true()
assert_that(resolver.is_parameter_set_static(0)).is_true()
assert_that(resolver.is_parameter_set_static(1)).is_true()
func test_build_test_case_names_on_runtime_parameter_set() -> void:
var test_case := get_test_case("test_resolve_parameters_at_runtime")
var resolver := test_case.parameter_set_resolver()
assert_array(resolver.build_test_case_names(test_case))\
.contains_exactly([
"test_resolve_parameters_at_runtime:0 [1, _test_param1]",
"test_resolve_parameters_at_runtime:1 [2, _test_param2]",
"test_resolve_parameters_at_runtime:2 [3, 30]"])
assert_that(resolver.is_parameter_sets_static()).is_false()
assert_that(resolver.is_parameter_set_static(0)).is_false()
assert_that(resolver.is_parameter_set_static(1)).is_false()
assert_that(resolver.is_parameter_set_static(2)).is_false()
func test_validate_test_parameter_set():
var test_suite :GdUnitTestSuite = auto_free(GdUnitTestResourceLoader.load_test_suite("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource"))
assert_is_not_skipped(test_suite, "test_no_parameters")
assert_is_not_skipped(test_suite, "test_parameterized_success")
assert_is_not_skipped(test_suite, "test_parameterized_failed")
assert_is_skipped(test_suite, "test_parameterized_to_less_args")\
.contains("The parameter set at index [0] does not match the expected input parameters!")\
.contains("The test case requires [3] input parameters, but the set contains [4]")
assert_is_skipped(test_suite, "test_parameterized_to_many_args")\
.contains("The parameter set at index [0] does not match the expected input parameters!")\
.contains("The test case requires [5] input parameters, but the set contains [4]")
assert_is_skipped(test_suite, "test_parameterized_to_less_args_at_index_1")\
.contains("The parameter set at index [1] does not match the expected input parameters!")\
.contains("The test case requires [3] input parameters, but the set contains [4]")
assert_is_skipped(test_suite, "test_parameterized_invalid_struct")\
.contains("The parameter set at index [1] does not match the expected input parameters!")\
.contains("The test case requires [3] input parameters, but the set contains [1]")
assert_is_skipped(test_suite, "test_parameterized_invalid_args")\
.contains("The parameter set at index [1] does not match the expected input parameters!")\
.contains("The value '4' does not match the required input parameter <b:int>.")
func assert_is_not_skipped(test_suite :GdUnitTestSuite, test_case :String) -> void:
# set actual execution context for this test suite
test_suite.__execution_context = GdUnitExecutionContext.new(test_suite.get_name())
var test :_TestCase = test_suite.find_child(test_case, true, false)
if test.is_parameterized():
# to load parameter set and force validate
var resolver := test.parameter_set_resolver()
resolver.build_test_case_names(test)
resolver.load_parameter_sets(test, true)
assert_that(test.is_skipped()).is_false()
func assert_is_skipped(test_suite :GdUnitTestSuite, test_case :String) -> GdUnitStringAssert:
# set actual execution context for this test suite
test_suite.__execution_context = GdUnitExecutionContext.new(test_suite.get_name())
var test :_TestCase = test_suite.find_child(test_case, true, false)
if test.is_parameterized():
# to load parameter set and force validate
var resolver := test.parameter_set_resolver()
resolver.build_test_case_names(test)
resolver.load_parameter_sets(test, true)
assert_that(test.is_skipped()).is_true()
return assert_str(test.skip_info())
func get_test_case(name: String) -> _TestCase:
return find_child(name, true, false)

View file

@ -0,0 +1,17 @@
class Area4D extends Resource:
const SOUND := 1
const ATMOSPHERE := 2
var _meta := Dictionary()
func _init(_x :int, atmospere :AtmosphereData = null):
_meta[ATMOSPHERE] = atmospere
func get_sound() -> SoundData:
# sounds are optional
if _meta.has(SOUND):
return _meta[SOUND] as SoundData
return null
func get_atmoshere() -> AtmosphereData:
return _meta[ATMOSPHERE] as AtmosphereData

View file

@ -0,0 +1,22 @@
class AtmosphereData:
enum {
WATER,
AIR,
SMOKY,
}
var _toxigen :float
var _type :int
func _init(type := AIR, toxigen := 0.0):
_type = type
_toxigen = toxigen
# some comment, and an row staring with an space to simmulate invalid formatting
# seter func with default values
func set_data(type := AIR, toxigen := 0.0) :
_type = type
_toxigen = toxigen
static func to_atmosphere(_value :Dictionary) -> AtmosphereData:
return null

View file

@ -0,0 +1,5 @@
class SoundData:
@warning_ignore("unused_private_class_variable")
var _sample :String
@warning_ignore("unused_private_class_variable")
var _randomnes :float

View file

@ -0,0 +1 @@
xxx

View file

@ -0,0 +1 @@
xxx

View file

@ -0,0 +1 @@
xxx

View file

@ -0,0 +1 @@
xxx

View file

@ -0,0 +1,7 @@
class_name PascalCaseWithClassName
extends Resource
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

View file

@ -0,0 +1,6 @@
extends RefCounted
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

View file

@ -0,0 +1,7 @@
class_name SnakeCaseWithClassName
extends Resource
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

View file

@ -0,0 +1,6 @@
extends RefCounted
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

View file

@ -0,0 +1,22 @@
class_name BaseTest
extends GdUnitTestSuite
func before():
pass
func after():
pass
func before_test():
pass
func after_test():
pass
func test_foo1() -> void:
pass

View file

@ -0,0 +1,14 @@
class_name ExtendedTest
extends BaseTest
func before_test():
pass
func after_test():
pass
func test_foo2() -> void:
pass

View file

@ -0,0 +1,4 @@
extends ExtendedTest
func test_foo3() -> void:
pass

View file

@ -0,0 +1,4 @@
extends GdUnitTestSuite
func test_foo1() -> void:
pass

View file

@ -0,0 +1,4 @@
extends "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/BaseTest.gd"
func test_foo2() -> void:
pass

View file

@ -0,0 +1,4 @@
extends "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/ExtendedTest.gd"
func test_foo3() -> void:
pass

View file

@ -0,0 +1,41 @@
extends PanelContainer
# Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data.
# Returns null if there is no data to drag.
# Controls that want to receive drop data should implement can_drop_data() and drop_data().
# position is local to this control. Drag may be forced with force_drag().
func _get_drag_data(_position: Vector2) -> Variant:
var x :TextureRect = $TextureRect
var data: = {texture = x.texture}
var drag_texture := x.duplicate()
drag_texture.size = x.size
drag_texture.position = x.global_position * -0.2
# set drag preview
var control := Panel.new()
control.add_child(drag_texture)
# center texture relative to mouse pos
set_drag_preview(control)
return data
# Godot calls this method to test if data from a control's get_drag_data() can be dropped at position. position is local to this control.
func _can_drop_data(_position: Vector2, data :Variant) -> bool:
return typeof(data) == TYPE_DICTIONARY and data.has("texture")
# Godot calls this method to pass you the data from a control's get_drag_data() result.
# Godot first calls can_drop_data() to test if data is allowed to drop at position where position is local to this control.
func _drop_data(_position: Vector2, data :Variant) -> void:
var drag_texture :Texture = data["texture"]
if drag_texture != null:
$TextureRect.texture = drag_texture
# Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See accept_event().
func _gui_input(_event):
#prints("Panel _gui_input", _event.as_text())
#if _event is InputEventMouseButton:
# prints("Panel _gui_input", _event.as_text())
pass

View file

@ -0,0 +1,16 @@
[gd_scene load_steps=2 format=3 uid="uid://ca2rr3dan4vvw"]
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropControl.gd" id="1"]
[node name="Panel" type="PanelContainer"]
offset_left = 245.0
offset_top = 232.0
offset_right = 350.0
offset_bottom = 337.0
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("1")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 2
expand_mode = 1

View file

@ -0,0 +1,18 @@
extends Control
@onready var texture = preload("res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/icon.png")
func _ready():
# set initial drag texture
$left/TextureRect.texture = texture
# Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See accept_event().
func _gui_input(_event):
#prints("Game _gui_input", _event.as_text())
pass
func _on_Button_button_down():
# print("BUTTON DOWN")
pass

View file

@ -0,0 +1,43 @@
[gd_scene load_steps=3 format=3 uid="uid://skueh3d5qn46"]
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropTestScene.gd" id="1"]
[ext_resource type="PackedScene" uid="uid://ca2rr3dan4vvw" path="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropControl.tscn" id="2_u5ccv"]
[node name="DragAndDropScene" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 3
script = ExtResource("1")
[node name="left" parent="." instance=ExtResource("2_u5ccv")]
layout_mode = 0
offset_left = 250.0
offset_top = 240.0
offset_right = 355.0
offset_bottom = 345.0
auto_translate = false
localize_numeral_system = false
metadata/_edit_use_anchors_ = true
[node name="right" parent="." instance=ExtResource("2_u5ccv")]
layout_mode = 0
offset_left = 370.0
offset_top = 240.0
offset_right = 475.0
offset_bottom = 345.0
[node name="Button" type="Button" parent="."]
layout_mode = 0
offset_left = 243.0
offset_top = 40.0
offset_right = 479.0
offset_bottom = 200.0
text = "BUTTON"
metadata/_edit_use_anchors_ = true
[connection signal="button_down" from="Button" to="." method="_on_Button_button_down"]

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://di6ovw8bnk7wg"
path="res://.godot/imported/icon.png-50a1939c45a5f06328a9e414b58963b1.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/icon.png"
dest_files=["res://.godot/imported/icon.png-50a1939c45a5f06328a9e414b58963b1.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1

View file

@ -0,0 +1,15 @@
extends Control
var _player_jump_action_released := false
# enable for manual testing
func __init():
var event := InputEventKey.new()
event.keycode = KEY_SPACE
InputMap.add_action("player_jump")
InputMap.action_add_event("player_jump", event)
func _input(event):
_player_jump_action_released = Input.is_action_just_released("player_jump", true)
#prints("_input2:player_jump", Input.is_action_just_released("player_jump"), Input.is_action_just_released("player_jump", true))

View file

@ -0,0 +1,12 @@
[gd_scene load_steps=2 format=3 uid="uid://cvklb72mxqh1h"]
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/input_actions/InputEventTestScene.gd" id="1_wslmn"]
[node name="InputEventTestScene" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_wslmn")

View file

@ -0,0 +1,15 @@
extends Node2D
class Player extends Node:
var position :Vector3 = Vector3.ZERO
func _init():
set_name("Player")
func is_on_floor() -> bool:
return true
func _ready():
add_child(Player.new(), true)

View file

@ -0,0 +1,11 @@
[gd_scene load_steps=3 format=3 uid="uid://cn8ucy2rheu0f"]
[ext_resource type="Texture2D" uid="uid://t80a6k3vyrrd" path="res://icon.png" id="1"]
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/simple_scene.gd" id="2"]
[node name="Node2D" type="Node2D"]
script = ExtResource("2")
[node name="Sprite2D" type="Sprite2D" parent="."]
position = Vector2(504, 252)
texture = ExtResource("1")

View file

@ -0,0 +1,6 @@
class_name ScriptWithClassName
extends Resource
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

View file

@ -0,0 +1,5 @@
extends RefCounted
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.

View file

@ -0,0 +1,17 @@
extends RefCounted
var _first_name :String
var _last_name :String
func _init(first_name_ :String,last_name_ :String):
_first_name = first_name_
_last_name = last_name_
func first_name() -> String:
return _first_name
func last_name() -> String:
return _last_name
func fully_name() -> String:
return _first_name + " " + _last_name

View file

@ -0,0 +1,49 @@
extends Node
func test_no_args():
pass
@warning_ignore("unused_parameter")
func test_with_timeout(timeout=2000):
pass
@warning_ignore("unused_parameter")
func test_with_fuzzer(fuzzer := Fuzzers.rangei(-10, 22)):
pass
@warning_ignore("unused_parameter")
func test_with_fuzzer_iterations(fuzzer := Fuzzers.rangei(-10, 22), fuzzer_iterations = 10):
pass
@warning_ignore("unused_parameter")
func test_with_multible_fuzzers(fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42), fuzzer_iterations = 10):
pass
@warning_ignore("unused_parameter")
func test_multiline_arguments_a(fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42),
fuzzer_iterations = 42):
pass
@warning_ignore("unused_parameter")
func test_multiline_arguments_b(
fuzzer_a := Fuzzers.rangei(-10, 22),
fuzzer_b := Fuzzers.rangei(23, 42),
fuzzer_iterations = 23
):
pass
@warning_ignore("unused_parameter")
func test_multiline_arguments_c(
timeout=2000,
fuzzer_a := Fuzzers.rangei(-10, 22),
fuzzer_b := Fuzzers.rangei(23, 42),
fuzzer_iterations = 33
) -> void:
pass

View file

@ -0,0 +1,48 @@
# this test suite simulates long running test cases
extends GdUnitTestSuite
@warning_ignore('unused_parameter')
var _stack : Array
func before():
# init the stack
_stack = []
func before_test():
# clean the stack before every test run
_stack.clear()
@warning_ignore('unused_parameter')
func test_multi_yielding_with_fuzzer(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 10):
# verify the used stack is cleaned by 'before_test'
assert_array(_stack).is_empty()
_stack.push_back(1)
prints("test iteration %d" % fuzzer.iteration_index())
prints("4")
await get_tree().process_frame
prints("3")
await get_tree().process_frame
prints("2")
await get_tree().process_frame
prints("1")
await get_tree().process_frame
prints("Go")
@warning_ignore('unused_parameter')
func test_multi_yielding_with_fuzzer_fail_after_3_iterations(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 10):
prints("test iteration %d" % fuzzer.iteration_index())
# should never be greater than 3 because we interuppted after three iterations
assert_int(fuzzer.iteration_index()).is_less_equal(3)
prints("4")
await get_tree().process_frame
prints("3")
await get_tree().process_frame
prints("2")
await get_tree().process_frame
prints("1")
await get_tree().process_frame
prints("Go")
if fuzzer.iteration_index() >= 3:
assert_bool(true).is_false()

View file

@ -0,0 +1,14 @@
namespace GdUnit4.Tests.Resources
{
using static Assertions;
// will be ignored because of missing `[TestSuite]` anotation
public partial class NotATestSuite
{
[TestCase]
public void TestFoo()
{
AssertBool(true).IsEqual(false);
}
}
}

Some files were not shown because too many files have changed in this diff Show more