1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-22 15:06:45 +00:00

GDScript: Replace assert() with Utils.check() in tests

This commit is contained in:
Danil Alexeev
2024-08-28 17:41:52 +03:00
parent f648de1a83
commit c1322d41e6
32 changed files with 275 additions and 347 deletions

View File

@@ -25,7 +25,7 @@ func test():
print("String in Array[StringName]: ", "abc" in stringname_array)
var packed_string_array: PackedStringArray = []
assert(!packed_string_array.push_back("abc"))
Utils.check(!packed_string_array.push_back("abc"))
print("StringName in PackedStringArray: ", &"abc" in packed_string_array)
string_array.push_back("abc")

View File

@@ -1,10 +1,9 @@
const array: Array = [0]
const dictionary := {1: 2}
@warning_ignore("assert_always_true")
func test():
assert(array.is_read_only() == true)
assert(str(array) == '[0]')
assert(dictionary.is_read_only() == true)
assert(str(dictionary) == '{ 1: 2 }')
Utils.check(array.is_read_only() == true)
Utils.check(str(array) == '[0]')
Utils.check(dictionary.is_read_only() == true)
Utils.check(str(dictionary) == '{ 1: 2 }')
print('ok')

View File

@@ -2,8 +2,8 @@ class Foo extends Node:
func _init():
name = 'f'
var string: String = name
assert(typeof(string) == TYPE_STRING)
assert(string == 'f')
Utils.check(typeof(string) == TYPE_STRING)
Utils.check(string == 'f')
print('ok')
func test():

View File

@@ -6,15 +6,15 @@ extends Node
@onready var later_untyped = [1]
func test():
assert(typeof(later_inferred) == TYPE_ARRAY)
assert(later_inferred.size() == 0)
Utils.check(typeof(later_inferred) == TYPE_ARRAY)
Utils.check(later_inferred.size() == 0)
assert(typeof(later_static) == TYPE_ARRAY)
assert(later_static.size() == 0)
Utils.check(typeof(later_static) == TYPE_ARRAY)
Utils.check(later_static.size() == 0)
assert(typeof(later_static_with_init) == TYPE_ARRAY)
assert(later_static_with_init.size() == 0)
Utils.check(typeof(later_static_with_init) == TYPE_ARRAY)
Utils.check(later_static_with_init.size() == 0)
assert(typeof(later_untyped) == TYPE_NIL)
Utils.check(typeof(later_untyped) == TYPE_NIL)
print("ok")

View File

@@ -1,5 +1,3 @@
const Utils = preload("../../utils.notest.gd")
# GH-73843
@export_group("Resource")

View File

@@ -62,7 +62,7 @@ func test():
0 when side_effect():
print("will run the side effect call, but not this")
_:
assert(global == 1)
Utils.check(global == 1)
print("side effect only ran once")
func side_effect():

View File

@@ -5,8 +5,6 @@ class MyClass:
enum MyEnum {}
const Utils = preload("../../utils.notest.gd")
static var test_static_var_untyped
static var test_static_var_weak_null = null
static var test_static_var_weak_int = 1

View File

@@ -1,7 +1,5 @@
# GH-82169
const Utils = preload("../../utils.notest.gd")
class A:
static var test_static_var_a1
static var test_static_var_a2

View File

@@ -3,7 +3,6 @@ class MyClass:
enum MyEnum {A, B, C}
const Utils = preload("../../utils.notest.gd")
const Other = preload("./metatypes.notest.gd")
var test_native := JSON

View File

@@ -6,6 +6,6 @@ class MyObj:
func test():
var obj_1 = MyObj.new()
var obj_2 = MyObj.new()
assert(obj_2.get_reference_count() == 1)
Utils.check(obj_2.get_reference_count() == 1)
obj_1.set(&"obj", obj_2)
assert(obj_2.get_reference_count() == 1)
Utils.check(obj_2.get_reference_count() == 1)

View File

@@ -12,4 +12,4 @@ func test() -> void:
node1.add_child(node2)
add_child(node3)
assert(get_node("_/Child") == $_/Child)
Utils.check(get_node("_/Child") == $_/Child)

View File

@@ -14,33 +14,33 @@ func test():
func test_construct(v, f):
@warning_ignore("unsafe_call_argument")
Vector2(v, v) # Built-in type construct.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.
func test_utility(v, f):
abs(v) # Utility function.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.
func test_builtin_call(v, f):
@warning_ignore("unsafe_method_access")
v.angle() # Built-in method call.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.
func test_builtin_call_validated(v: Vector2, f):
@warning_ignore("return_value_discarded")
v.abs() # Built-in method call validated.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.
func test_object_call(v, f):
@warning_ignore("unsafe_method_access")
v.get_reference_count() # Native type method call.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.
func test_object_call_method_bind(v: Resource, f):
@warning_ignore("return_value_discarded")
v.duplicate() # Native type method call with MethodBind.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.
func test_object_call_method_bind_validated(v: RefCounted, f):
@warning_ignore("return_value_discarded")
v.get_reference_count() # Native type method call with validated MethodBind.
assert(not f) # Test unary operator reading from `nil`.
Utils.check(not f) # Test unary operator reading from `nil`.

View File

@@ -1,6 +1,6 @@
func test():
var untyped: Variant = 32
var typed: Array[int] = [untyped]
assert(typed.get_typed_builtin() == TYPE_INT)
assert(str(typed) == '[32]')
Utils.check(typed.get_typed_builtin() == TYPE_INT)
Utils.check(str(typed) == '[32]')
print('ok')