From c1322d41e6b48d9a957418cc20045cf6e4f79cd4 Mon Sep 17 00:00:00 2001 From: Danil Alexeev Date: Wed, 28 Aug 2024 17:41:52 +0300 Subject: [PATCH] GDScript: Replace `assert()` with `Utils.check()` in tests --- .../features/assymetric_assignment_good.gd | 9 +- .../analyzer/features/const_conversions.gd | 25 ++- .../analyzer/features/enums_in_range_call.gd | 2 +- .../features/export_enum_as_dictionary.gd | 2 - .../analyzer/features/for_range_usage.gd | 2 +- ..._parent_signature_with_extra_parameters.gd | 4 +- .../analyzer/features/return_conversions.gd | 24 +-- .../analyzer/features/ternary_hard_infer.gd | 4 +- .../analyzer/features/type_test_usage.gd | 193 +++++++++--------- .../analyzer/features/typed_array_usage.gd | 159 +++++++-------- .../scripts/parser/features/annotations.gd | 2 - .../tests/scripts/parser/features/class.gd | 4 +- .../scripts/parser/features/export_arrays.gd | 2 - .../scripts/parser/features/export_enum.gd | 2 - .../parser/features/export_variable.gd | 1 - .../features/good_continue_in_lambda.gd | 2 +- .../scripts/parser/features/truthiness.gd | 40 ++-- .../scripts/parser/features/truthiness.out | 65 +----- .../array_string_stringname_equivalent.gd | 2 +- .../features/constants_are_read_only.gd | 9 +- .../conversions_from_native_members.gd | 4 +- .../features/default_set_beforehand.gd | 14 +- ..._group_no_name_conflict_with_properties.gd | 2 - .../features/match_with_pattern_guards.gd | 2 +- .../scripts/runtime/features/member_info.gd | 2 - .../features/member_info_inheritance.gd | 2 - .../scripts/runtime/features/metatypes.gd | 1 - .../runtime/features/set_does_not_leak.gd | 4 +- .../features/single_underscore_node_name.gd | 2 +- .../standalone_calls_do_not_write_to_nil.gd | 14 +- ...yped_array_init_with_untyped_in_literal.gd | 4 +- .../gdscript/tests/scripts/utils.notest.gd | 18 +- 32 files changed, 275 insertions(+), 347 deletions(-) diff --git a/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd b/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd index efd8ad6edb3..60bcde4b8ca 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd @@ -3,14 +3,13 @@ const const_color: Color = 'red' func func_color(arg_color: Color = 'blue') -> bool: return arg_color == Color.BLUE -@warning_ignore("assert_always_true") func test(): - assert(const_color == Color.RED) + Utils.check(const_color == Color.RED) - assert(func_color() == true) - assert(func_color('blue') == true) + Utils.check(func_color() == true) + Utils.check(func_color('blue') == true) var var_color: Color = 'green' - assert(var_color == Color.GREEN) + Utils.check(var_color == Color.GREEN) print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd b/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd index bed9dd0e96c..5318d11f33c 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd @@ -5,20 +5,19 @@ const const_float_cast: float = 76 as float const const_packed_empty: PackedFloat64Array = [] const const_packed_ints: PackedFloat64Array = [52] -@warning_ignore("assert_always_true") func test(): - assert(typeof(const_float_int) == TYPE_FLOAT) - assert(str(const_float_int) == '19') - assert(typeof(const_float_plus) == TYPE_FLOAT) - assert(str(const_float_plus) == '34') - assert(typeof(const_float_cast) == TYPE_FLOAT) - assert(str(const_float_cast) == '76') + Utils.check(typeof(const_float_int) == TYPE_FLOAT) + Utils.check(str(const_float_int) == '19') + Utils.check(typeof(const_float_plus) == TYPE_FLOAT) + Utils.check(str(const_float_plus) == '34') + Utils.check(typeof(const_float_cast) == TYPE_FLOAT) + Utils.check(str(const_float_cast) == '76') - assert(typeof(const_packed_empty) == TYPE_PACKED_FLOAT64_ARRAY) - assert(str(const_packed_empty) == '[]') - assert(typeof(const_packed_ints) == TYPE_PACKED_FLOAT64_ARRAY) - assert(str(const_packed_ints) == '[52]') - assert(typeof(const_packed_ints[0]) == TYPE_FLOAT) - assert(str(const_packed_ints[0]) == '52') + Utils.check(typeof(const_packed_empty) == TYPE_PACKED_FLOAT64_ARRAY) + Utils.check(str(const_packed_empty) == '[]') + Utils.check(typeof(const_packed_ints) == TYPE_PACKED_FLOAT64_ARRAY) + Utils.check(str(const_packed_ints) == '[52]') + Utils.check(typeof(const_packed_ints[0]) == TYPE_FLOAT) + Utils.check(str(const_packed_ints[0]) == '52') print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/enums_in_range_call.gd b/modules/gdscript/tests/scripts/analyzer/features/enums_in_range_call.gd index d2d9d04508c..a569488d3ca 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/enums_in_range_call.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/enums_in_range_call.gd @@ -5,5 +5,5 @@ func test(): for value in range(E.E0, E.E3): var inferable := value total += inferable - assert(total == 0 + 1 + 2) + Utils.check(total == 0 + 1 + 2) print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/export_enum_as_dictionary.gd b/modules/gdscript/tests/scripts/analyzer/features/export_enum_as_dictionary.gd index 39f490c4b3e..ec892263283 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/export_enum_as_dictionary.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/export_enum_as_dictionary.gd @@ -2,8 +2,6 @@ class_name TestExportEnumAsDictionary enum MyEnum {A, B, C} -const Utils = preload("../../utils.notest.gd") - @export var test_1 = MyEnum @export var test_2 = MyEnum.A @export var test_3 := MyEnum diff --git a/modules/gdscript/tests/scripts/analyzer/features/for_range_usage.gd b/modules/gdscript/tests/scripts/analyzer/features/for_range_usage.gd index 4a7f10f1ee8..9ce0782d5cc 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/for_range_usage.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/for_range_usage.gd @@ -3,5 +3,5 @@ func test(): var result := '' for i in range(array.size(), 0, -1): result += str(array[i - 1]) - assert(result == '963') + Utils.check(result == '963') print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd index d678f3acfc0..e0cbdacb38b 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/function_match_parent_signature_with_extra_parameters.gd @@ -2,11 +2,11 @@ func test(): var instance := Parent.new() var result := instance.my_function(1) print(result) - assert(result == 1) + Utils.check(result == 1) instance = Child.new() result = instance.my_function(2) print(result) - assert(result == 0) + Utils.check(result == 0) class Parent: func my_function(par1: int) -> int: diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd index 0b1576e66e3..cbe8e9da34a 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd @@ -8,27 +8,27 @@ func convert_var_array_to_packed() -> PackedStringArray: var array := ['79']; re func test(): var converted_literal_int := convert_literal_int_to_float() - assert(typeof(converted_literal_int) == TYPE_FLOAT) - assert(converted_literal_int == 76.0) + Utils.check(typeof(converted_literal_int) == TYPE_FLOAT) + Utils.check(converted_literal_int == 76.0) var converted_arg_int := convert_arg_int_to_float(36) - assert(typeof(converted_arg_int) == TYPE_FLOAT) - assert(converted_arg_int == 36.0) + Utils.check(typeof(converted_arg_int) == TYPE_FLOAT) + Utils.check(converted_arg_int == 36.0) var converted_var_int := convert_var_int_to_float() - assert(typeof(converted_var_int) == TYPE_FLOAT) - assert(converted_var_int == 59.0) + Utils.check(typeof(converted_var_int) == TYPE_FLOAT) + Utils.check(converted_var_int == 59.0) var converted_literal_array := convert_literal_array_to_packed() - assert(typeof(converted_literal_array) == TYPE_PACKED_STRING_ARRAY) - assert(str(converted_literal_array) == '["46"]') + Utils.check(typeof(converted_literal_array) == TYPE_PACKED_STRING_ARRAY) + Utils.check(str(converted_literal_array) == '["46"]') var converted_arg_array := convert_arg_array_to_packed(['91']) - assert(typeof(converted_arg_array) == TYPE_PACKED_STRING_ARRAY) - assert(str(converted_arg_array) == '["91"]') + Utils.check(typeof(converted_arg_array) == TYPE_PACKED_STRING_ARRAY) + Utils.check(str(converted_arg_array) == '["91"]') var converted_var_array := convert_var_array_to_packed() - assert(typeof(converted_var_array) == TYPE_PACKED_STRING_ARRAY) - assert(str(converted_var_array) == '["79"]') + Utils.check(typeof(converted_var_array) == TYPE_PACKED_STRING_ARRAY) + Utils.check(str(converted_var_array) == '["79"]') print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/ternary_hard_infer.gd b/modules/gdscript/tests/scripts/analyzer/features/ternary_hard_infer.gd index 44ca5f4dd05..d49acaacd30 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/ternary_hard_infer.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/ternary_hard_infer.gd @@ -2,7 +2,7 @@ func test(): var left_hard_int := 1 var right_hard_int := 2 var result_hard_int := left_hard_int if true else right_hard_int - assert(result_hard_int == 1) + Utils.check(result_hard_int == 1) @warning_ignore("inference_on_variant") var left_hard_variant := 1 as Variant @@ -10,6 +10,6 @@ func test(): var right_hard_variant := 2.0 as Variant @warning_ignore("inference_on_variant") var result_hard_variant := left_hard_variant if true else right_hard_variant - assert(result_hard_variant == 1) + Utils.check(result_hard_variant == 1) print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/type_test_usage.gd b/modules/gdscript/tests/scripts/analyzer/features/type_test_usage.gd index 12dc0b93df0..ee30f01dfb8 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/type_test_usage.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/type_test_usage.gd @@ -4,124 +4,123 @@ class A extends RefCounted: class B extends A: pass -@warning_ignore("assert_always_true") func test(): var builtin: Variant = 3 - assert((builtin is Variant) == true) - assert((builtin is int) == true) - assert(is_instance_of(builtin, TYPE_INT) == true) - assert((builtin is float) == false) - assert(is_instance_of(builtin, TYPE_FLOAT) == false) + Utils.check((builtin is Variant) == true) + Utils.check((builtin is int) == true) + Utils.check(is_instance_of(builtin, TYPE_INT) == true) + Utils.check((builtin is float) == false) + Utils.check(is_instance_of(builtin, TYPE_FLOAT) == false) const const_builtin: Variant = 3 - assert((const_builtin is Variant) == true) - assert((const_builtin is int) == true) - assert(is_instance_of(const_builtin, TYPE_INT) == true) - assert((const_builtin is float) == false) - assert(is_instance_of(const_builtin, TYPE_FLOAT) == false) + Utils.check((const_builtin is Variant) == true) + Utils.check((const_builtin is int) == true) + Utils.check(is_instance_of(const_builtin, TYPE_INT) == true) + Utils.check((const_builtin is float) == false) + Utils.check(is_instance_of(const_builtin, TYPE_FLOAT) == false) var int_array: Variant = [] as Array[int] - assert((int_array is Variant) == true) - assert((int_array is Array) == true) - assert(is_instance_of(int_array, TYPE_ARRAY) == true) - assert((int_array is Array[int]) == true) - assert((int_array is Array[float]) == false) - assert((int_array is int) == false) - assert(is_instance_of(int_array, TYPE_INT) == false) + Utils.check((int_array is Variant) == true) + Utils.check((int_array is Array) == true) + Utils.check(is_instance_of(int_array, TYPE_ARRAY) == true) + Utils.check((int_array is Array[int]) == true) + Utils.check((int_array is Array[float]) == false) + Utils.check((int_array is int) == false) + Utils.check(is_instance_of(int_array, TYPE_INT) == false) var const_int_array: Variant = [] as Array[int] - assert((const_int_array is Variant) == true) - assert((const_int_array is Array) == true) - assert(is_instance_of(const_int_array, TYPE_ARRAY) == true) - assert((const_int_array is Array[int]) == true) - assert((const_int_array is Array[float]) == false) - assert((const_int_array is int) == false) - assert(is_instance_of(const_int_array, TYPE_INT) == false) + Utils.check((const_int_array is Variant) == true) + Utils.check((const_int_array is Array) == true) + Utils.check(is_instance_of(const_int_array, TYPE_ARRAY) == true) + Utils.check((const_int_array is Array[int]) == true) + Utils.check((const_int_array is Array[float]) == false) + Utils.check((const_int_array is int) == false) + Utils.check(is_instance_of(const_int_array, TYPE_INT) == false) var b_array: Variant = [] as Array[B] - assert((b_array is Variant) == true) - assert((b_array is Array) == true) - assert(is_instance_of(b_array, TYPE_ARRAY) == true) - assert((b_array is Array[B]) == true) - assert((b_array is Array[A]) == false) - assert((b_array is Array[int]) == false) - assert((b_array is int) == false) - assert(is_instance_of(b_array, TYPE_INT) == false) + Utils.check((b_array is Variant) == true) + Utils.check((b_array is Array) == true) + Utils.check(is_instance_of(b_array, TYPE_ARRAY) == true) + Utils.check((b_array is Array[B]) == true) + Utils.check((b_array is Array[A]) == false) + Utils.check((b_array is Array[int]) == false) + Utils.check((b_array is int) == false) + Utils.check(is_instance_of(b_array, TYPE_INT) == false) var const_b_array: Variant = [] as Array[B] - assert((const_b_array is Variant) == true) - assert((const_b_array is Array) == true) - assert(is_instance_of(const_b_array, TYPE_ARRAY) == true) - assert((const_b_array is Array[B]) == true) - assert((const_b_array is Array[A]) == false) - assert((const_b_array is Array[int]) == false) - assert((const_b_array is int) == false) - assert(is_instance_of(const_b_array, TYPE_INT) == false) + Utils.check((const_b_array is Variant) == true) + Utils.check((const_b_array is Array) == true) + Utils.check(is_instance_of(const_b_array, TYPE_ARRAY) == true) + Utils.check((const_b_array is Array[B]) == true) + Utils.check((const_b_array is Array[A]) == false) + Utils.check((const_b_array is Array[int]) == false) + Utils.check((const_b_array is int) == false) + Utils.check(is_instance_of(const_b_array, TYPE_INT) == false) var native: Variant = RefCounted.new() - assert((native is Variant) == true) - assert((native is Object) == true) - assert(is_instance_of(native, TYPE_OBJECT) == true) - assert(is_instance_of(native, Object) == true) - assert((native is RefCounted) == true) - assert(is_instance_of(native, RefCounted) == true) - assert((native is Node) == false) - assert(is_instance_of(native, Node) == false) - assert((native is int) == false) - assert(is_instance_of(native, TYPE_INT) == false) + Utils.check((native is Variant) == true) + Utils.check((native is Object) == true) + Utils.check(is_instance_of(native, TYPE_OBJECT) == true) + Utils.check(is_instance_of(native, Object) == true) + Utils.check((native is RefCounted) == true) + Utils.check(is_instance_of(native, RefCounted) == true) + Utils.check((native is Node) == false) + Utils.check(is_instance_of(native, Node) == false) + Utils.check((native is int) == false) + Utils.check(is_instance_of(native, TYPE_INT) == false) var a_script: Variant = A.new() - assert((a_script is Variant) == true) - assert((a_script is Object) == true) - assert(is_instance_of(a_script, TYPE_OBJECT) == true) - assert(is_instance_of(a_script, Object) == true) - assert((a_script is RefCounted) == true) - assert(is_instance_of(a_script, RefCounted) == true) - assert((a_script is A) == true) - assert(is_instance_of(a_script, A) == true) - assert((a_script is B) == false) - assert(is_instance_of(a_script, B) == false) - assert((a_script is Node) == false) - assert(is_instance_of(a_script, Node) == false) - assert((a_script is int) == false) - assert(is_instance_of(a_script, TYPE_INT) == false) + Utils.check((a_script is Variant) == true) + Utils.check((a_script is Object) == true) + Utils.check(is_instance_of(a_script, TYPE_OBJECT) == true) + Utils.check(is_instance_of(a_script, Object) == true) + Utils.check((a_script is RefCounted) == true) + Utils.check(is_instance_of(a_script, RefCounted) == true) + Utils.check((a_script is A) == true) + Utils.check(is_instance_of(a_script, A) == true) + Utils.check((a_script is B) == false) + Utils.check(is_instance_of(a_script, B) == false) + Utils.check((a_script is Node) == false) + Utils.check(is_instance_of(a_script, Node) == false) + Utils.check((a_script is int) == false) + Utils.check(is_instance_of(a_script, TYPE_INT) == false) var b_script: Variant = B.new() - assert((b_script is Variant) == true) - assert((b_script is Object) == true) - assert(is_instance_of(b_script, TYPE_OBJECT) == true) - assert(is_instance_of(b_script, Object) == true) - assert((b_script is RefCounted) == true) - assert(is_instance_of(b_script, RefCounted) == true) - assert((b_script is A) == true) - assert(is_instance_of(b_script, A) == true) - assert((b_script is B) == true) - assert(is_instance_of(b_script, B) == true) - assert((b_script is Node) == false) - assert(is_instance_of(b_script, Node) == false) - assert((b_script is int) == false) - assert(is_instance_of(b_script, TYPE_INT) == false) + Utils.check((b_script is Variant) == true) + Utils.check((b_script is Object) == true) + Utils.check(is_instance_of(b_script, TYPE_OBJECT) == true) + Utils.check(is_instance_of(b_script, Object) == true) + Utils.check((b_script is RefCounted) == true) + Utils.check(is_instance_of(b_script, RefCounted) == true) + Utils.check((b_script is A) == true) + Utils.check(is_instance_of(b_script, A) == true) + Utils.check((b_script is B) == true) + Utils.check(is_instance_of(b_script, B) == true) + Utils.check((b_script is Node) == false) + Utils.check(is_instance_of(b_script, Node) == false) + Utils.check((b_script is int) == false) + Utils.check(is_instance_of(b_script, TYPE_INT) == false) var var_null: Variant = null - assert((var_null is Variant) == true) - assert((var_null is int) == false) - assert(is_instance_of(var_null, TYPE_INT) == false) - assert((var_null is Object) == false) - assert(is_instance_of(var_null, TYPE_OBJECT) == false) - assert((var_null is RefCounted) == false) - assert(is_instance_of(var_null, RefCounted) == false) - assert((var_null is A) == false) - assert(is_instance_of(var_null, A) == false) + Utils.check((var_null is Variant) == true) + Utils.check((var_null is int) == false) + Utils.check(is_instance_of(var_null, TYPE_INT) == false) + Utils.check((var_null is Object) == false) + Utils.check(is_instance_of(var_null, TYPE_OBJECT) == false) + Utils.check((var_null is RefCounted) == false) + Utils.check(is_instance_of(var_null, RefCounted) == false) + Utils.check((var_null is A) == false) + Utils.check(is_instance_of(var_null, A) == false) const const_null: Variant = null - assert((const_null is Variant) == true) - assert((const_null is int) == false) - assert(is_instance_of(const_null, TYPE_INT) == false) - assert((const_null is Object) == false) - assert(is_instance_of(const_null, TYPE_OBJECT) == false) - assert((const_null is RefCounted) == false) - assert(is_instance_of(const_null, RefCounted) == false) - assert((const_null is A) == false) - assert(is_instance_of(const_null, A) == false) + Utils.check((const_null is Variant) == true) + Utils.check((const_null is int) == false) + Utils.check(is_instance_of(const_null, TYPE_INT) == false) + Utils.check((const_null is Object) == false) + Utils.check(is_instance_of(const_null, TYPE_OBJECT) == false) + Utils.check((const_null is RefCounted) == false) + Utils.check(is_instance_of(const_null, RefCounted) == false) + Utils.check((const_null is A) == false) + Utils.check(is_instance_of(const_null, A) == false) print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd b/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd index b000c827179..fe0274c27b8 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd @@ -10,206 +10,205 @@ class Members: var two: Array[int] = one func check_passing() -> bool: - assert(str(one) == '[104]') - assert(str(two) == '[104]') + Utils.check(str(one) == '[104]') + Utils.check(str(two) == '[104]') two.push_back(582) - assert(str(one) == '[104, 582]') - assert(str(two) == '[104, 582]') + Utils.check(str(one) == '[104, 582]') + Utils.check(str(two) == '[104, 582]') two = [486] - assert(str(one) == '[104, 582]') - assert(str(two) == '[486]') + Utils.check(str(one) == '[104, 582]') + Utils.check(str(two) == '[486]') return true @warning_ignore("unsafe_method_access") -@warning_ignore("assert_always_true") @warning_ignore("return_value_discarded") func test(): var untyped_basic = [459] - assert(str(untyped_basic) == '[459]') - assert(untyped_basic.get_typed_builtin() == TYPE_NIL) + Utils.check(str(untyped_basic) == '[459]') + Utils.check(untyped_basic.get_typed_builtin() == TYPE_NIL) var inferred_basic := [366] - assert(str(inferred_basic) == '[366]') - assert(inferred_basic.get_typed_builtin() == TYPE_NIL) + Utils.check(str(inferred_basic) == '[366]') + Utils.check(inferred_basic.get_typed_builtin() == TYPE_NIL) var typed_basic: Array = [521] - assert(str(typed_basic) == '[521]') - assert(typed_basic.get_typed_builtin() == TYPE_NIL) + Utils.check(str(typed_basic) == '[521]') + Utils.check(typed_basic.get_typed_builtin() == TYPE_NIL) var empty_floats: Array[float] = [] - assert(str(empty_floats) == '[]') - assert(empty_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(empty_floats) == '[]') + Utils.check(empty_floats.get_typed_builtin() == TYPE_FLOAT) untyped_basic = empty_floats - assert(untyped_basic.get_typed_builtin() == TYPE_FLOAT) + Utils.check(untyped_basic.get_typed_builtin() == TYPE_FLOAT) inferred_basic = empty_floats - assert(inferred_basic.get_typed_builtin() == TYPE_FLOAT) + Utils.check(inferred_basic.get_typed_builtin() == TYPE_FLOAT) typed_basic = empty_floats - assert(typed_basic.get_typed_builtin() == TYPE_FLOAT) + Utils.check(typed_basic.get_typed_builtin() == TYPE_FLOAT) empty_floats.push_back(705.0) untyped_basic.push_back(430.0) inferred_basic.push_back(263.0) typed_basic.push_back(518.0) - assert(str(empty_floats) == '[705, 430, 263, 518]') - assert(str(untyped_basic) == '[705, 430, 263, 518]') - assert(str(inferred_basic) == '[705, 430, 263, 518]') - assert(str(typed_basic) == '[705, 430, 263, 518]') + Utils.check(str(empty_floats) == '[705, 430, 263, 518]') + Utils.check(str(untyped_basic) == '[705, 430, 263, 518]') + Utils.check(str(inferred_basic) == '[705, 430, 263, 518]') + Utils.check(str(typed_basic) == '[705, 430, 263, 518]') const constant_float := 950.0 const constant_int := 170 var typed_float := 954.0 var filled_floats: Array[float] = [constant_float, constant_int, typed_float, empty_floats[1] + empty_floats[2]] - assert(str(filled_floats) == '[950, 170, 954, 693]') - assert(filled_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(filled_floats) == '[950, 170, 954, 693]') + Utils.check(filled_floats.get_typed_builtin() == TYPE_FLOAT) var casted_floats := [empty_floats[2] * 2] as Array[float] - assert(str(casted_floats) == '[526]') - assert(casted_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(casted_floats) == '[526]') + Utils.check(casted_floats.get_typed_builtin() == TYPE_FLOAT) var returned_floats = (func () -> Array[float]: return [554]).call() - assert(str(returned_floats) == '[554]') - assert(returned_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(returned_floats) == '[554]') + Utils.check(returned_floats.get_typed_builtin() == TYPE_FLOAT) var passed_floats = floats_identity([663.0 if randf() > 0.5 else 663.0]) - assert(str(passed_floats) == '[663]') - assert(passed_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(passed_floats) == '[663]') + Utils.check(passed_floats.get_typed_builtin() == TYPE_FLOAT) var default_floats = (func (floats: Array[float] = [364.0]): return floats).call() - assert(str(default_floats) == '[364]') - assert(default_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(default_floats) == '[364]') + Utils.check(default_floats.get_typed_builtin() == TYPE_FLOAT) var typed_int := 556 var converted_floats: Array[float] = [typed_int] converted_floats.push_back(498) - assert(str(converted_floats) == '[556, 498]') - assert(converted_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(converted_floats) == '[556, 498]') + Utils.check(converted_floats.get_typed_builtin() == TYPE_FLOAT) const constant_basic = [228] - assert(str(constant_basic) == '[228]') - assert(constant_basic.get_typed_builtin() == TYPE_NIL) + Utils.check(str(constant_basic) == '[228]') + Utils.check(constant_basic.get_typed_builtin() == TYPE_NIL) const constant_floats: Array[float] = [constant_float - constant_basic[0] - constant_int] - assert(str(constant_floats) == '[552]') - assert(constant_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(constant_floats) == '[552]') + Utils.check(constant_floats.get_typed_builtin() == TYPE_FLOAT) var source_floats: Array[float] = [999.74] untyped_basic = source_floats var destination_floats: Array[float] = untyped_basic destination_floats[0] -= 0.74 - assert(str(source_floats) == '[999]') - assert(str(untyped_basic) == '[999]') - assert(str(destination_floats) == '[999]') - assert(destination_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(source_floats) == '[999]') + Utils.check(str(untyped_basic) == '[999]') + Utils.check(str(destination_floats) == '[999]') + Utils.check(destination_floats.get_typed_builtin() == TYPE_FLOAT) var duplicated_floats := empty_floats.duplicate().slice(2, 3) duplicated_floats[0] *= 3 - assert(str(duplicated_floats) == '[789]') - assert(duplicated_floats.get_typed_builtin() == TYPE_FLOAT) + Utils.check(str(duplicated_floats) == '[789]') + Utils.check(duplicated_floats.get_typed_builtin() == TYPE_FLOAT) var b_objects: Array[B] = [B.new(), B.new() as A, null] - assert(b_objects.size() == 3) - assert(b_objects.get_typed_builtin() == TYPE_OBJECT) - assert(b_objects.get_typed_script() == B) + Utils.check(b_objects.size() == 3) + Utils.check(b_objects.get_typed_builtin() == TYPE_OBJECT) + Utils.check(b_objects.get_typed_script() == B) var a_objects: Array[A] = [A.new(), B.new(), null, b_objects[0]] - assert(a_objects.size() == 4) - assert(a_objects.get_typed_builtin() == TYPE_OBJECT) - assert(a_objects.get_typed_script() == A) + Utils.check(a_objects.size() == 4) + Utils.check(a_objects.get_typed_builtin() == TYPE_OBJECT) + Utils.check(a_objects.get_typed_script() == A) var a_passed = (func check_a_passing(p_objects: Array[A]): return p_objects.size()).call(a_objects) - assert(a_passed == 4) + Utils.check(a_passed == 4) var b_passed = (func check_b_passing(basic: Array): return basic[0] != null).call(b_objects) - assert(b_passed == true) + Utils.check(b_passed == true) var empty_strings: Array[String] = [] var empty_bools: Array[bool] = [] var empty_basic_one := [] var empty_basic_two := [] - assert(empty_strings == empty_bools) - assert(empty_basic_one == empty_basic_two) - assert(empty_strings.hash() == empty_bools.hash()) - assert(empty_basic_one.hash() == empty_basic_two.hash()) + Utils.check(empty_strings == empty_bools) + Utils.check(empty_basic_one == empty_basic_two) + Utils.check(empty_strings.hash() == empty_bools.hash()) + Utils.check(empty_basic_one.hash() == empty_basic_two.hash()) var assign_source: Array[int] = [527] var assign_target: Array[int] = [] assign_target.assign(assign_source) - assert(str(assign_source) == '[527]') - assert(str(assign_target) == '[527]') + Utils.check(str(assign_source) == '[527]') + Utils.check(str(assign_target) == '[527]') assign_source.push_back(657) - assert(str(assign_source) == '[527, 657]') - assert(str(assign_target) == '[527]') + Utils.check(str(assign_source) == '[527, 657]') + Utils.check(str(assign_target) == '[527]') var defaults_passed = (func check_defaults_passing(one: Array[int] = [], two := one): one.push_back(887) two.push_back(198) - assert(str(one) == '[887, 198]') - assert(str(two) == '[887, 198]') + Utils.check(str(one) == '[887, 198]') + Utils.check(str(two) == '[887, 198]') two = [130] - assert(str(one) == '[887, 198]') - assert(str(two) == '[130]') + Utils.check(str(one) == '[887, 198]') + Utils.check(str(two) == '[130]') return true ).call() - assert(defaults_passed == true) + Utils.check(defaults_passed == true) var members := Members.new() var members_passed := members.check_passing() - assert(members_passed == true) + Utils.check(members_passed == true) var resized_basic: Array = [] resized_basic.resize(1) - assert(typeof(resized_basic[0]) == TYPE_NIL) - assert(resized_basic[0] == null) + Utils.check(typeof(resized_basic[0]) == TYPE_NIL) + Utils.check(resized_basic[0] == null) var resized_ints: Array[int] = [] resized_ints.resize(1) - assert(typeof(resized_ints[0]) == TYPE_INT) - assert(resized_ints[0] == 0) + Utils.check(typeof(resized_ints[0]) == TYPE_INT) + Utils.check(resized_ints[0] == 0) var resized_arrays: Array[Array] = [] resized_arrays.resize(1) - assert(typeof(resized_arrays[0]) == TYPE_ARRAY) + Utils.check(typeof(resized_arrays[0]) == TYPE_ARRAY) resized_arrays[0].resize(1) resized_arrays[0][0] = 523 - assert(str(resized_arrays) == '[[523]]') + Utils.check(str(resized_arrays) == '[[523]]') var resized_objects: Array[Object] = [] resized_objects.resize(1) - assert(typeof(resized_objects[0]) == TYPE_NIL) - assert(resized_objects[0] == null) + Utils.check(typeof(resized_objects[0]) == TYPE_NIL) + Utils.check(resized_objects[0] == null) var typed_enums: Array[E] = [] typed_enums.resize(1) - assert(str(typed_enums) == '[0]') + Utils.check(str(typed_enums) == '[0]') typed_enums[0] = E.E0 - assert(str(typed_enums) == '[391]') - assert(typed_enums.get_typed_builtin() == TYPE_INT) + Utils.check(str(typed_enums) == '[391]') + Utils.check(typed_enums.get_typed_builtin() == TYPE_INT) const const_enums: Array[E] = [] - assert(const_enums.get_typed_builtin() == TYPE_INT) - assert(const_enums.get_typed_class_name() == &'') + Utils.check(const_enums.get_typed_builtin() == TYPE_INT) + Utils.check(const_enums.get_typed_class_name() == &'') var a := A.new() var typed_natives: Array[RefCounted] = [a] var typed_scripts = Array(typed_natives, TYPE_OBJECT, "RefCounted", A) - assert(typed_scripts[0] == a) + Utils.check(typed_scripts[0] == a) print('ok') diff --git a/modules/gdscript/tests/scripts/parser/features/annotations.gd b/modules/gdscript/tests/scripts/parser/features/annotations.gd index 7a7d6d953e9..1e5d3fdcade 100644 --- a/modules/gdscript/tests/scripts/parser/features/annotations.gd +++ b/modules/gdscript/tests/scripts/parser/features/annotations.gd @@ -1,7 +1,5 @@ extends Node -const Utils = preload("../../utils.notest.gd") - @export_enum("A", "B", "C") var test_1 @export_enum("A", "B", "C",) var test_2 diff --git a/modules/gdscript/tests/scripts/parser/features/class.gd b/modules/gdscript/tests/scripts/parser/features/class.gd index af24b32322a..482d04a63b3 100644 --- a/modules/gdscript/tests/scripts/parser/features/class.gd +++ b/modules/gdscript/tests/scripts/parser/features/class.gd @@ -18,8 +18,8 @@ func test(): test_instance.number = 42 var test_sub = TestSub.new() - assert(test_sub.number == 25) # From Test. - assert(test_sub.other_string == "bye") # From TestSub. + Utils.check(test_sub.number == 25) # From Test. + Utils.check(test_sub.other_string == "bye") # From TestSub. var _test_constructor = TestConstructor.new() _test_constructor = TestConstructor.new(500) diff --git a/modules/gdscript/tests/scripts/parser/features/export_arrays.gd b/modules/gdscript/tests/scripts/parser/features/export_arrays.gd index 0d97135a7b8..cfda255905f 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_arrays.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_arrays.gd @@ -1,5 +1,3 @@ -const Utils = preload("../../utils.notest.gd") - @export_dir var test_dir: Array[String] @export_dir var test_dir_packed: PackedStringArray @export_file var test_file: Array[String] diff --git a/modules/gdscript/tests/scripts/parser/features/export_enum.gd b/modules/gdscript/tests/scripts/parser/features/export_enum.gd index 7f0737f4db7..d50f0b25283 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_enum.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_enum.gd @@ -1,5 +1,3 @@ -const Utils = preload("../../utils.notest.gd") - @export_enum("Red", "Green", "Blue") var test_untyped @export_enum("Red:10", "Green:20", "Blue:30") var test_with_values diff --git a/modules/gdscript/tests/scripts/parser/features/export_variable.gd b/modules/gdscript/tests/scripts/parser/features/export_variable.gd index 8bcb2bcb9a5..1e134d0e0e6 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_variable.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_variable.gd @@ -1,7 +1,6 @@ class_name ExportVariableTest extends Node -const Utils = preload("../../utils.notest.gd") const PreloadedGlobalClass = preload("./export_variable_global.notest.gd") const PreloadedUnnamedClass = preload("./export_variable_unnamed.notest.gd") diff --git a/modules/gdscript/tests/scripts/parser/features/good_continue_in_lambda.gd b/modules/gdscript/tests/scripts/parser/features/good_continue_in_lambda.gd index 2fa45c1d7df..0ec118b6b74 100644 --- a/modules/gdscript/tests/scripts/parser/features/good_continue_in_lambda.gd +++ b/modules/gdscript/tests/scripts/parser/features/good_continue_in_lambda.gd @@ -9,5 +9,5 @@ func test(): j_string += str(j) return j_string i_string += lambda.call() - assert(i_string == '0202') + Utils.check(i_string == '0202') print('ok') diff --git a/modules/gdscript/tests/scripts/parser/features/truthiness.gd b/modules/gdscript/tests/scripts/parser/features/truthiness.gd index 9c67a152f50..736cda7f741 100644 --- a/modules/gdscript/tests/scripts/parser/features/truthiness.gd +++ b/modules/gdscript/tests/scripts/parser/features/truthiness.gd @@ -1,30 +1,32 @@ func test(): - # The assertions below should all evaluate to `true` for this test to pass. - assert(true) - assert(not false) - assert(500) - assert(not 0) - assert(500.5) - assert(not 0.0) - assert("non-empty string") - assert(["non-empty array"]) - assert({"non-empty": "dictionary"}) - assert(Vector2(1, 0)) - assert(Vector2i(-1, -1)) - assert(Vector3(0, 0, 0.0001)) - assert(Vector3i(0, 0, 10000)) + # The checks below should all evaluate to `true` for this test to pass. + Utils.check(true) + Utils.check(not false) + Utils.check(500) + Utils.check(not 0) + Utils.check(500.5) + Utils.check(not 0.0) + Utils.check("non-empty string") + Utils.check(["non-empty array"]) + Utils.check({"non-empty": "dictionary"}) + Utils.check(Vector2(1, 0)) + Utils.check(Vector2i(-1, -1)) + Utils.check(Vector3(0, 0, 0.0001)) + Utils.check(Vector3i(0, 0, 10000)) # Zero position is `true` only if the Rect2's size is non-zero. - assert(Rect2(0, 0, 0, 1)) + Utils.check(Rect2(0, 0, 0, 1)) # Zero size is `true` only if the position is non-zero. - assert(Rect2(1, 1, 0, 0)) + Utils.check(Rect2(1, 1, 0, 0)) # Zero position is `true` only if the Rect2's size is non-zero. - assert(Rect2i(0, 0, 0, 1)) + Utils.check(Rect2i(0, 0, 0, 1)) # Zero size is `true` only if the position is non-zero. - assert(Rect2i(1, 1, 0, 0)) + Utils.check(Rect2i(1, 1, 0, 0)) # A fully black color is only truthy if its alpha component is not equal to `1`. - assert(Color(0, 0, 0, 0.5)) + Utils.check(Color(0, 0, 0, 0.5)) + + print("ok") diff --git a/modules/gdscript/tests/scripts/parser/features/truthiness.out b/modules/gdscript/tests/scripts/parser/features/truthiness.out index 705524857bc..1b47ed10dc0 100644 --- a/modules/gdscript/tests/scripts/parser/features/truthiness.out +++ b/modules/gdscript/tests/scripts/parser/features/truthiness.out @@ -1,65 +1,2 @@ GDTEST_OK ->> WARNING ->> Line: 3 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 4 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 5 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 6 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 7 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 8 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 9 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 12 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 13 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 14 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 15 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 18 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 21 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 24 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 27 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. ->> WARNING ->> Line: 30 ->> ASSERT_ALWAYS_TRUE ->> Assert statement is redundant because the expression is always true. +ok diff --git a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd index bd38259cec5..6eec37d64d3 100644 --- a/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd +++ b/modules/gdscript/tests/scripts/runtime/features/array_string_stringname_equivalent.gd @@ -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") diff --git a/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.gd b/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.gd index d1746979beb..6aa863c05f7 100644 --- a/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.gd +++ b/modules/gdscript/tests/scripts/runtime/features/constants_are_read_only.gd @@ -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') diff --git a/modules/gdscript/tests/scripts/runtime/features/conversions_from_native_members.gd b/modules/gdscript/tests/scripts/runtime/features/conversions_from_native_members.gd index a778fb1a946..0f2526667d7 100644 --- a/modules/gdscript/tests/scripts/runtime/features/conversions_from_native_members.gd +++ b/modules/gdscript/tests/scripts/runtime/features/conversions_from_native_members.gd @@ -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(): diff --git a/modules/gdscript/tests/scripts/runtime/features/default_set_beforehand.gd b/modules/gdscript/tests/scripts/runtime/features/default_set_beforehand.gd index 0851d939dc1..9e67e75140f 100644 --- a/modules/gdscript/tests/scripts/runtime/features/default_set_beforehand.gd +++ b/modules/gdscript/tests/scripts/runtime/features/default_set_beforehand.gd @@ -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") diff --git a/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.gd b/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.gd index 0133d7fcfcc..90df98e05bd 100644 --- a/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.gd +++ b/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.gd @@ -1,5 +1,3 @@ -const Utils = preload("../../utils.notest.gd") - # GH-73843 @export_group("Resource") diff --git a/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd b/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd index 4cb51f8512d..48a9349bf88 100644 --- a/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd +++ b/modules/gdscript/tests/scripts/runtime/features/match_with_pattern_guards.gd @@ -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(): diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info.gd b/modules/gdscript/tests/scripts/runtime/features/member_info.gd index 42b29eee435..91d5a501c8f 100644 --- a/modules/gdscript/tests/scripts/runtime/features/member_info.gd +++ b/modules/gdscript/tests/scripts/runtime/features/member_info.gd @@ -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 diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd b/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd index ee5c1e12678..4ddbeaec0be 100644 --- a/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd +++ b/modules/gdscript/tests/scripts/runtime/features/member_info_inheritance.gd @@ -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 diff --git a/modules/gdscript/tests/scripts/runtime/features/metatypes.gd b/modules/gdscript/tests/scripts/runtime/features/metatypes.gd index fd23ea0db58..d6847768e67 100644 --- a/modules/gdscript/tests/scripts/runtime/features/metatypes.gd +++ b/modules/gdscript/tests/scripts/runtime/features/metatypes.gd @@ -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 diff --git a/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd index e1aba835072..dee36d3ae04 100644 --- a/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd +++ b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd @@ -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) diff --git a/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd b/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd index b07c40b6da4..11a670a7fb8 100644 --- a/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd +++ b/modules/gdscript/tests/scripts/runtime/features/single_underscore_node_name.gd @@ -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) diff --git a/modules/gdscript/tests/scripts/runtime/features/standalone_calls_do_not_write_to_nil.gd b/modules/gdscript/tests/scripts/runtime/features/standalone_calls_do_not_write_to_nil.gd index 691b611574e..d72662736e1 100644 --- a/modules/gdscript/tests/scripts/runtime/features/standalone_calls_do_not_write_to_nil.gd +++ b/modules/gdscript/tests/scripts/runtime/features/standalone_calls_do_not_write_to_nil.gd @@ -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`. diff --git a/modules/gdscript/tests/scripts/runtime/features/typed_array_init_with_untyped_in_literal.gd b/modules/gdscript/tests/scripts/runtime/features/typed_array_init_with_untyped_in_literal.gd index ec444b4ffa8..859bfd79874 100644 --- a/modules/gdscript/tests/scripts/runtime/features/typed_array_init_with_untyped_in_literal.gd +++ b/modules/gdscript/tests/scripts/runtime/features/typed_array_init_with_untyped_in_literal.gd @@ -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') diff --git a/modules/gdscript/tests/scripts/utils.notest.gd b/modules/gdscript/tests/scripts/utils.notest.gd index 7fdd6556ece..5d615d85577 100644 --- a/modules/gdscript/tests/scripts/utils.notest.gd +++ b/modules/gdscript/tests/scripts/utils.notest.gd @@ -1,3 +1,13 @@ +class_name Utils + + +# `assert()` is not evaluated in non-debug builds. Do not use `assert()` +# for anything other than testing the `assert()` itself. +static func check(condition: Variant) -> void: + if not condition: + printerr("Check failed.") + + static func get_type(property: Dictionary, is_return: bool = false) -> String: match property.type: TYPE_NIL: @@ -46,7 +56,7 @@ static func get_human_readable_hint_string(property: Dictionary) -> String: while true: if not hint_string.contains(":"): - push_error("Invalid PROPERTY_HINT_TYPE_STRING format.") + printerr("Invalid PROPERTY_HINT_TYPE_STRING format.") var elem_type_hint: String = hint_string.get_slice(":", 0) hint_string = hint_string.substr(elem_type_hint.length() + 1) @@ -58,7 +68,7 @@ static func get_human_readable_hint_string(property: Dictionary) -> String: type_hint_prefixes += "<%s>:" % type_string(elem_type) else: if elem_type_hint.count("/") != 1: - push_error("Invalid PROPERTY_HINT_TYPE_STRING format.") + printerr("Invalid PROPERTY_HINT_TYPE_STRING format.") elem_type = elem_type_hint.get_slice("/", 0).to_int() elem_hint = elem_type_hint.get_slice("/", 1).to_int() type_hint_prefixes += "<%s>/<%s>:" % [ @@ -188,7 +198,7 @@ static func get_property_hint_name(hint: PropertyHint) -> String: return "PROPERTY_HINT_HIDE_QUATERNION_EDIT" PROPERTY_HINT_PASSWORD: return "PROPERTY_HINT_PASSWORD" - push_error("Argument `hint` is invalid. Use `PROPERTY_HINT_*` constants.") + printerr("Argument `hint` is invalid. Use `PROPERTY_HINT_*` constants.") return "" @@ -240,7 +250,7 @@ static func get_property_usage_string(usage: int) -> String: usage &= ~flag[0] if usage != PROPERTY_USAGE_NONE: - push_error("Argument `usage` is invalid. Use `PROPERTY_USAGE_*` constants.") + printerr("Argument `usage` is invalid. Use `PROPERTY_USAGE_*` constants.") return "" return result.left(-1)