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,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()