diff options
Diffstat (limited to 'modules/gdscript/tests/scripts')
28 files changed, 124 insertions, 19 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/assymetric_assignment_bad.gd b/modules/gdscript/tests/scripts/analyzer/errors/assymetric_assignment_bad.gd new file mode 100644 index 0000000000..1b22d173c7 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/assymetric_assignment_bad.gd @@ -0,0 +1,3 @@ +func test(): + var var_color: String = Color.RED + print('not ok') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/assymetric_assignment_bad.out b/modules/gdscript/tests/scripts/analyzer/errors/assymetric_assignment_bad.out new file mode 100644 index 0000000000..cc4b1d86bf --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/assymetric_assignment_bad.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot assign a value of type "Color" as "String". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.out deleted file mode 100644 index 3a8d2a205a..0000000000 --- a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.out +++ /dev/null @@ -1,2 +0,0 @@ -GDTEST_ANALYZER_ERROR -Invalid cast. Enum "cast_enum_bad_enum.gd::MyEnum" does not have value corresponding to "MyOtherEnum.OTHER_ENUM_VALUE_3" (2). diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.out deleted file mode 100644 index bc0d8b7834..0000000000 --- a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.out +++ /dev/null @@ -1,2 +0,0 @@ -GDTEST_ANALYZER_ERROR -Invalid cast. Enum "cast_enum_bad_int.gd::MyEnum" does not have enum value 2. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out index 02c4633586..84958f1aa2 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_assign_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Value of type "enum_class_var_assign_with_wrong_enum_type.gd::MyOtherEnum" cannot be assigned to a variable of type "enum_class_var_assign_with_wrong_enum_type.gd::MyEnum". +Cannot assign a value of type "enum_class_var_assign_with_wrong_enum_type.gd::MyOtherEnum" as "enum_class_var_assign_with_wrong_enum_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out index 441cccbf7b..e294f3496a 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_class_var_init_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type enum_class_var_init_with_wrong_enum_type.gd::MyOtherEnum to variable "class_var" with specified type enum_class_var_init_with_wrong_enum_type.gd::MyEnum. +Cannot assign a value of type "enum_class_var_init_with_wrong_enum_type.gd::MyOtherEnum" as "enum_class_var_init_with_wrong_enum_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out index e85f7d6f9f..a91189e2dd 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_parameter_wrong_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Invalid argument for "enum_func()" function: argument 1 should be "enum_function_parameter_wrong_type.gd::MyEnum" but is "enum_function_parameter_wrong_type.gd::MyOtherEnum". +Cannot pass a value of type "enum_function_parameter_wrong_type.gd::MyOtherEnum" as "enum_function_parameter_wrong_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out index f7ea3267fa..6b4eba3740 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_function_return_wrong_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot return value of type "enum_function_return_wrong_type.gd::MyOtherEnum" because the function return type is "enum_function_return_wrong_type.gd::MyEnum". +Cannot return a value of type "enum_function_return_wrong_type.gd::MyOtherEnum" as "enum_function_return_wrong_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out index 38df5a0cd8..616358bb61 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_outer_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Value of type "enum_local_var_assign_outer_with_wrong_enum_type.gd::InnerClass::MyEnum" cannot be assigned to a variable of type "enum_local_var_assign_outer_with_wrong_enum_type.gd::MyEnum". +Cannot assign a value of type "enum_local_var_assign_outer_with_wrong_enum_type.gd::InnerClass::MyEnum" as "enum_local_var_assign_outer_with_wrong_enum_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out index 2adcbd9edf..af3dde663f 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_assign_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Value of type "enum_local_var_assign_with_wrong_enum_type.gd::MyOtherEnum" cannot be assigned to a variable of type "enum_local_var_assign_with_wrong_enum_type.gd::MyEnum". +Cannot assign a value of type "enum_local_var_assign_with_wrong_enum_type.gd::MyOtherEnum" as "enum_local_var_assign_with_wrong_enum_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out index 331113dd30..781b0bc85f 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_local_var_init_with_wrong_enum_type.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type enum_local_var_init_with_wrong_enum_type.gd::MyOtherEnum to variable "local_var" with specified type enum_local_var_init_with_wrong_enum_type.gd::MyEnum. +Cannot assign a value of type "enum_local_var_init_with_wrong_enum_type.gd::MyOtherEnum" as "enum_local_var_init_with_wrong_enum_type.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out index 6298c026b4..e8c7f86c4f 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_preload_unnamed_assign_to_named.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Value of type "enum_value_from_parent.gd::<anonymous enum>" cannot be assigned to a variable of type "enum_preload_unnamed_assign_to_named.gd::MyEnum". +Cannot assign a value of type "enum_value_from_parent.gd::<anonymous enum>" as "enum_preload_unnamed_assign_to_named.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out b/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out index b70121ed81..fb18c94d0b 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/enum_unnamed_assign_to_named.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot assign a value of type enum_unnamed_assign_to_named.gd::<anonymous enum> to variable "local_var" with specified type enum_unnamed_assign_to_named.gd::MyEnum. +Cannot assign a value of type "enum_unnamed_assign_to_named.gd::<anonymous enum>" as "enum_unnamed_assign_to_named.gd::MyEnum". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/lambda_wrong_return.out b/modules/gdscript/tests/scripts/analyzer/errors/lambda_wrong_return.out index 53e2b012e6..69af0984f7 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/lambda_wrong_return.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/lambda_wrong_return.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot return value of type "String" because the function return type is "int". +Cannot return a value of type "String" as "int". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out b/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out index 5e3c446bf6..08a973503f 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/preload_enum_error.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Value of type "enum_from_outer.gd::Named" cannot be assigned to a variable of type "preload_enum_error.gd::LocalNamed". +Cannot assign a value of type "enum_from_outer.gd::Named" as "preload_enum_error.gd::LocalNamed". diff --git a/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd b/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd new file mode 100644 index 0000000000..efd8ad6edb --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.gd @@ -0,0 +1,16 @@ +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) + + assert(func_color() == true) + assert(func_color('blue') == true) + + var var_color: Color = 'green' + assert(var_color == Color.GREEN) + + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.out b/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/assymetric_assignment_good.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok diff --git a/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd b/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd new file mode 100644 index 0000000000..bed9dd0e96 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/const_conversions.gd @@ -0,0 +1,24 @@ +const const_float_int: float = 19 +const const_float_plus: float = 12 + 22 +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') + + 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') + + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/const_conversions.out b/modules/gdscript/tests/scripts/analyzer/features/const_conversions.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/const_conversions.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd new file mode 100644 index 0000000000..0b1576e66e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.gd @@ -0,0 +1,34 @@ +func convert_literal_int_to_float() -> float: return 76 +func convert_arg_int_to_float(arg: int) -> float: return arg +func convert_var_int_to_float() -> float: var number := 59; return number + +func convert_literal_array_to_packed() -> PackedStringArray: return ['46'] +func convert_arg_array_to_packed(arg: Array) -> PackedStringArray: return arg +func convert_var_array_to_packed() -> PackedStringArray: var array := ['79']; return array + +func test(): + var converted_literal_int := convert_literal_int_to_float() + assert(typeof(converted_literal_int) == TYPE_FLOAT) + assert(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) + + var converted_var_int := convert_var_int_to_float() + assert(typeof(converted_var_int) == TYPE_FLOAT) + assert(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"]') + + 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"]') + + var converted_var_array := convert_var_array_to_packed() + assert(typeof(converted_var_array) == TYPE_PACKED_STRING_ARRAY) + assert(str(converted_var_array) == '["79"]') + + print('ok') diff --git a/modules/gdscript/tests/scripts/analyzer/features/return_conversions.out b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.out new file mode 100644 index 0000000000..1b47ed10dc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/return_conversions.out @@ -0,0 +1,2 @@ +GDTEST_OK +ok diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.gd b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_enum.gd index 71616ea3af..71616ea3af 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_enum.gd +++ b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_enum.gd diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_enum.out b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_enum.out new file mode 100644 index 0000000000..6e086a0918 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_enum.out @@ -0,0 +1,6 @@ +GDTEST_OK +>> WARNING +>> Line: 5 +>> INT_AS_ENUM_WITHOUT_MATCH +>> Cannot cast 2 as Enum "cast_enum_bad_enum.gd::MyEnum": no enum member has matching value. +2 diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.gd b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_int.gd index 60a31fb318..60a31fb318 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/cast_enum_bad_int.gd +++ b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_int.gd diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_int.out b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_int.out new file mode 100644 index 0000000000..c19d57f98e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/cast_enum_bad_int.out @@ -0,0 +1,6 @@ +GDTEST_OK +>> WARNING +>> Line: 4 +>> INT_AS_ENUM_WITHOUT_MATCH +>> Cannot cast 2 as Enum "cast_enum_bad_int.gd::MyEnum": no enum member has matching value. +2 diff --git a/modules/gdscript/tests/scripts/parser/warnings/enum_assign_int_without_casting.out b/modules/gdscript/tests/scripts/parser/warnings/enum_assign_int_without_casting.out index eef13bbff8..b8e243769f 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/enum_assign_int_without_casting.out +++ b/modules/gdscript/tests/scripts/parser/warnings/enum_assign_int_without_casting.out @@ -1,19 +1,19 @@ GDTEST_OK >> WARNING >> Line: 5 ->> INT_ASSIGNED_TO_ENUM +>> INT_AS_ENUM_WITHOUT_CAST >> Integer used when an enum value is expected. If this is intended cast the integer to the enum type. >> WARNING >> Line: 9 ->> INT_ASSIGNED_TO_ENUM +>> INT_AS_ENUM_WITHOUT_CAST >> Integer used when an enum value is expected. If this is intended cast the integer to the enum type. >> WARNING >> Line: 12 ->> INT_ASSIGNED_TO_ENUM +>> INT_AS_ENUM_WITHOUT_CAST >> Integer used when an enum value is expected. If this is intended cast the integer to the enum type. >> WARNING >> Line: 14 ->> INT_ASSIGNED_TO_ENUM +>> INT_AS_ENUM_WITHOUT_CAST >> Integer used when an enum value is expected. If this is intended cast the integer to the enum type. 0 1 diff --git a/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd new file mode 100644 index 0000000000..0c15701364 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.gd @@ -0,0 +1,6 @@ +# https://github.com/godotengine/godot/issues/66675 +func test(): + example(Node2D) + +func example(thing): + print(thing.has_method('asdf')) diff --git a/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out new file mode 100644 index 0000000000..3a90f98d99 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/non_static_method_call_on_native_class.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: example() +>> runtime/errors/non_static_method_call_on_native_class.gd +>> 6 +>> Invalid call. Nonexistent function 'has_method' in base 'Node2D'. |