diff options
Diffstat (limited to 'modules/gdscript/tests')
24 files changed, 143 insertions, 15 deletions
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd index 38c2faa859..8709b89b54 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.gd @@ -1,2 +1,2 @@ func test(): - CanvasItem.new() + InstancePlaceholder.new() diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out index 9eff912b59..36224c6b6f 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_class_instantiate.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Native class "CanvasItem" cannot be constructed as it is abstract. +Native class "InstancePlaceholder" cannot be constructed as it is abstract. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd index 118e7e8a45..be67182efb 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.gd @@ -1,4 +1,4 @@ -class A extends CanvasItem: +class A extends InstancePlaceholder: func _init(): print('no') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out index 8b956f5974..260f062555 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/abstract_script_instantiate.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Class "abstract_script_instantiate.gd::B" cannot be constructed as it is based on abstract native class "CanvasItem". +Class "abstract_script_instantiate.gd::B" cannot be constructed as it is based on abstract native class "InstancePlaceholder". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_var_self.gd b/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_var_self.gd new file mode 100644 index 0000000000..57ae41922f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_var_self.gd @@ -0,0 +1,4 @@ +var v1 = v1 + +func test(): + print(v1) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_var_self.out b/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_var_self.out new file mode 100644 index 0000000000..c337882d9c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_var_self.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Could not resolve member "v1": Cyclic reference. diff --git a/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.gd b/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.gd index a9004a346b..3e647407cd 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.gd @@ -1,7 +1,7 @@ extends Node @onready var shorthand = $Node -@onready var call = get_node(^"Node") +@onready var call_no_cast = get_node(^"Node") @onready var shorthand_with_cast = $Node as Node @onready var call_with_cast = get_node(^"Node") as Node @@ -13,6 +13,6 @@ func _init(): func test(): # Those are expected to be `null` since `_ready()` is never called on tests. prints("shorthand", shorthand) - prints("call", call) + prints("call_no_cast", call_no_cast) prints("shorthand_with_cast", shorthand_with_cast) prints("call_with_cast", call_with_cast) diff --git a/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.out b/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.out index eddc2deec0..78b830aad0 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.out +++ b/modules/gdscript/tests/scripts/analyzer/features/allow_get_node_with_onready.out @@ -1,5 +1,5 @@ GDTEST_OK shorthand <null> -call <null> +call_no_cast <null> shorthand_with_cast <null> call_with_cast <null> 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 c4108f50de..b000c82717 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/typed_array_usage.gd @@ -126,7 +126,7 @@ func test(): assert(a_objects.get_typed_builtin() == TYPE_OBJECT) assert(a_objects.get_typed_script() == A) - var a_passed = (func check_a_passing(a_objects: Array[A]): return a_objects.size()).call(a_objects) + var a_passed = (func check_a_passing(p_objects: Array[A]): return p_objects.size()).call(a_objects) assert(a_passed == 4) var b_passed = (func check_b_passing(basic: Array): return basic[0] != null).call(b_objects) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd new file mode 100644 index 0000000000..3178f8d496 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.gd @@ -0,0 +1,6 @@ +func test(): + if true: + var a = 1 + print(a) + var a = 2 + print(a) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out new file mode 100644 index 0000000000..7365072ea7 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_declaration.out @@ -0,0 +1,7 @@ +GDTEST_OK +>> WARNING +>> Line: 3 +>> CONFUSABLE_LOCAL_DECLARATION +>> The variable "a" is declared below in the parent block. +1 +2 diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd new file mode 100644 index 0000000000..4462c067bc --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.gd @@ -0,0 +1,6 @@ +var a = 1 + +func test(): + print(a) + var a = 2 + print(a) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out new file mode 100644 index 0000000000..0e0d607831 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage.out @@ -0,0 +1,11 @@ +GDTEST_OK +>> WARNING +>> Line: 4 +>> CONFUSABLE_LOCAL_USAGE +>> The identifier "a" will be shadowed below in the block. +>> WARNING +>> Line: 5 +>> SHADOWED_VARIABLE +>> The local variable "a" is shadowing an already-declared variable at line 1. +1 +2 diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd new file mode 100644 index 0000000000..eef8eb66e6 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.gd @@ -0,0 +1,6 @@ +var a = 1 + +func test(): + print(a) + var a = a + 1 + print(a) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out new file mode 100644 index 0000000000..228a510490 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_initializer.out @@ -0,0 +1,15 @@ +GDTEST_OK +>> WARNING +>> Line: 4 +>> CONFUSABLE_LOCAL_USAGE +>> The identifier "a" will be shadowed below in the block. +>> WARNING +>> Line: 5 +>> CONFUSABLE_LOCAL_USAGE +>> The identifier "a" will be shadowed below in the block. +>> WARNING +>> Line: 5 +>> SHADOWED_VARIABLE +>> The local variable "a" is shadowing an already-declared variable at line 1. +1 +2 diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd new file mode 100644 index 0000000000..1f207f27ac --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.gd @@ -0,0 +1,7 @@ +var a = 1 + +func test(): + for _i in 3: + print(a) + var a = 2 + print(a) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out new file mode 100644 index 0000000000..0d20e9f7a0 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/confusable_local_usage_loop.out @@ -0,0 +1,15 @@ +GDTEST_OK +>> WARNING +>> Line: 5 +>> CONFUSABLE_LOCAL_USAGE +>> The identifier "a" will be shadowed below in the block. +>> WARNING +>> Line: 6 +>> SHADOWED_VARIABLE +>> The local variable "a" is shadowing an already-declared variable at line 1. +1 +2 +1 +2 +1 +2 diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.gd b/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.gd index 61945c9c8f..29239a19da 100644 --- a/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.gd +++ b/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.gd @@ -1,5 +1,9 @@ var member: int = 0 +var print_debug := 'print_debug' +@warning_ignore("shadowed_global_identifier") +var print := 'print' + @warning_ignore("unused_variable") func test(): var Array := 'Array' diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.out b/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.out index 8467697a96..accc791d8a 100644 --- a/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.out +++ b/modules/gdscript/tests/scripts/analyzer/warnings/shadowning.out @@ -1,26 +1,30 @@ GDTEST_OK >> WARNING ->> Line: 5 +>> Line: 3 +>> SHADOWED_GLOBAL_IDENTIFIER +>> The variable "print_debug" has the same name as a built-in function. +>> WARNING +>> Line: 9 >> SHADOWED_GLOBAL_IDENTIFIER >> The variable "Array" has the same name as a built-in type. >> WARNING ->> Line: 6 +>> Line: 10 >> SHADOWED_GLOBAL_IDENTIFIER >> The variable "Node" has the same name as a global class. >> WARNING ->> Line: 7 +>> Line: 11 >> SHADOWED_GLOBAL_IDENTIFIER >> The variable "is_same" has the same name as a built-in function. >> WARNING ->> Line: 8 +>> Line: 12 >> SHADOWED_GLOBAL_IDENTIFIER >> The variable "sqrt" has the same name as a built-in function. >> WARNING ->> Line: 9 +>> Line: 13 >> SHADOWED_VARIABLE >> The local variable "member" is shadowing an already-declared variable at line 1. >> WARNING ->> Line: 10 +>> Line: 14 >> SHADOWED_VARIABLE_BASE_CLASS >> The local variable "reference" is shadowing an already-declared method at the base class "RefCounted". warn diff --git a/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out b/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out index 36cb699e92..f68d76d101 100644 --- a/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out +++ b/modules/gdscript/tests/scripts/parser/errors/yield_instead_of_await.out @@ -1,2 +1,2 @@ GDTEST_PARSER_ERROR -"yield" was removed in Godot 4.0. Use "await" instead. +"yield" was removed in Godot 4. Use "await" instead. 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 new file mode 100644 index 0000000000..e46f24cc5f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.gd @@ -0,0 +1,17 @@ +extends RefCounted # TODO: Fix standalone annotations parsing. + +# GH-73843 +@export_group("Resource") + +# GH-78252 +@export var prop_1: int +@export_category("prop_1") +@export var prop_2: int + +func test(): + var resource := Resource.new() + prints("Not shadowed:", resource.get_class()) + + for property in get_property_list(): + if property.name in ["prop_1", "prop_2"]: + print(property) diff --git a/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.out b/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.out new file mode 100644 index 0000000000..96ae84e986 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/export_group_no_name_conflict_with_properties.out @@ -0,0 +1,5 @@ +GDTEST_OK +Not shadowed: Resource +{ "name": "prop_1", "class_name": &"", "type": 2, "hint": 0, "hint_string": "int", "usage": 4102 } +{ "name": "prop_1", "class_name": &"", "type": 0, "hint": 0, "hint_string": "", "usage": 128 } +{ "name": "prop_2", "class_name": &"", "type": 2, "hint": 0, "hint_string": "int", "usage": 4102 } diff --git a/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.gd b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.gd new file mode 100644 index 0000000000..f17fb9823d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.gd @@ -0,0 +1,14 @@ +# GH-80157 + +extends Node + +func f(): + pass + +signal s() + +func test(): + print(f) + print(s) + print(get_child) + print(ready) diff --git a/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.out b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.out new file mode 100644 index 0000000000..e5e9ff7043 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/first_class_callable_and_signal.out @@ -0,0 +1,5 @@ +GDTEST_OK +Node::f +Node::[signal]s +Node::get_child +Node::[signal]ready |