diff options
Diffstat (limited to 'modules/gdscript/tests')
134 files changed, 855 insertions, 80 deletions
diff --git a/modules/gdscript/tests/README.md b/modules/gdscript/tests/README.md index 72b5316532..714e38397f 100644 --- a/modules/gdscript/tests/README.md +++ b/modules/gdscript/tests/README.md @@ -13,6 +13,12 @@ The `script/completion` folder contains test for the GDScript autocompletion. Each test case consists of at least one `.gd` file, which contains the code, and one `.cfg` file, which contains expected results and configuration. Inside of the GDScript file the character `➡` represents the cursor position, at which autocompletion is invoked. +The script files won't be parsable GDScript since it contains an invalid char and and often the code is not complete during autocompletion. To allow for a valid base when used with a scene, the +runner will remove the line which contains `➡`. Therefore the scripts need to be valid if this line is removed, otherwise the test might behave in unexpected ways. This may for example require +adding an additional `pass` statement. + +This also means, that the runner will add the script to its owner node, so the script should not be loaded through the scene file. + The config file contains two section: `[input]` contains keys that configure the test environment. The following keys are possible: @@ -20,6 +26,7 @@ The config file contains two section: - `cs: boolean = false`: If `true`, the test will be skipped when running a non C# build. - `use_single_quotes: boolean = false`: Configures the corresponding editor setting for the test. - `scene: String`: Allows to specify a scene which is opened while autocompletion is performed. If this is not set the test runner will search for a `.tscn` file with the same basename as the GDScript file. If that isn't found either, autocompletion will behave as if no scene was opened. +- `node_path: String`: The node path of the node which holds the current script inside of the scene. Defaults to the scene root node. `[output]` specifies the expected results for the test. The following key are supported: diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index a0329eb8d2..e3d16eaf42 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -300,14 +300,23 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) { #endif String out_file = next.get_basename() + ".out"; - if (!is_generating && !dir->file_exists(out_file)) { - ERR_FAIL_V_MSG(false, "Could not find output file for " + next); - } - GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir); - if (binary_tokens) { - test.set_tokenizer_mode(GDScriptTest::TOKENIZER_BUFFER); + ERR_FAIL_COND_V_MSG(!is_generating && !dir->file_exists(out_file), false, "Could not find output file for " + next); + + if (next.ends_with(".bin.gd")) { + // Test text mode first. + GDScriptTest text_test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir); + tests.push_back(text_test); + // Test binary mode even without `--use-binary-tokens`. + GDScriptTest bin_test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir); + bin_test.set_tokenizer_mode(GDScriptTest::TOKENIZER_BUFFER); + tests.push_back(bin_test); + } else { + GDScriptTest test(current_dir.path_join(next), current_dir.path_join(out_file), source_dir); + if (binary_tokens) { + test.set_tokenizer_mode(GDScriptTest::TOKENIZER_BUFFER); + } + tests.push_back(test); } - tests.push_back(test); } } diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.gd b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.gd new file mode 100644 index 0000000000..b53e814eea --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.gd @@ -0,0 +1,3 @@ +func test(): + var integer := 1 + print(integer as Array) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.out new file mode 100644 index 0000000000..e3e82c2b7e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_array.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Invalid cast. Cannot convert from "int" to "Array". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.gd b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.gd new file mode 100644 index 0000000000..323e367f8e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.gd @@ -0,0 +1,3 @@ +func test(): + var integer := 1 + print(integer as Node) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.out new file mode 100644 index 0000000000..7de40418bf --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_int_to_object.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Invalid cast. Cannot convert from "int" to "Node". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.gd b/modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.gd new file mode 100644 index 0000000000..f6cd5e217e --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.gd @@ -0,0 +1,3 @@ +func test(): + var object := RefCounted.new() + print(object as int) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.out b/modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.out new file mode 100644 index 0000000000..8af0847577 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/cast_object_to_int.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Invalid cast. Cannot convert from "RefCounted" to "int". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static.gd new file mode 100644 index 0000000000..e041aeb914 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static.gd @@ -0,0 +1,10 @@ +# GH-91403 + +static func static_func(): + print(non_static_func) + +func non_static_func(): + pass + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static.out new file mode 100644 index 0000000000..d8d6c8bc1b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot access non-static function "non_static_func" from the static function "static_func()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static_in_lambda_param.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static_in_lambda_param.gd new file mode 100644 index 0000000000..36bc9dbf15 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static_in_lambda_param.gd @@ -0,0 +1,15 @@ +# GH-91403 + +func non_static_func(): + pass + +static func static_func( + f := func (): + var g := func (): + print(non_static_func) + g.call() +): + f.call() + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static_in_lambda_param.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static_in_lambda_param.out new file mode 100644 index 0000000000..d8d6c8bc1b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_access_non_static_in_lambda_param.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot access non-static function "non_static_func" from the static function "static_func()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out index b78f131345..c094c08cd8 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot call non-static function "non_static_func()" from static function "static_func()". +Cannot call non-static function "non_static_func()" from the static function "static_func()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out index b78f131345..c094c08cd8 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot call non-static function "non_static_func()" from static function "static_func()". +Cannot call non-static function "non_static_func()" from the static function "static_func()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out index b78f131345..c094c08cd8 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_func_call_non_static_in_lambda_param.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot call non-static function "non_static_func()" from static function "static_func()". +Cannot call non-static function "non_static_func()" from the static function "static_func()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda.gd new file mode 100644 index 0000000000..7ae5bea7d7 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda.gd @@ -0,0 +1,14 @@ +# GH-91403 + +func non_static_func(): + pass + +static var static_var = func (): + var f := func (): + var g := func (): + print(non_static_func) + g.call() + f.call() + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda.out new file mode 100644 index 0000000000..153e81b405 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot access non-static function "non_static_func" from a static variable initializer. diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda_setter.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda_setter.gd new file mode 100644 index 0000000000..7479afc532 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda_setter.gd @@ -0,0 +1,15 @@ +# GH-91403 + +func non_static_func(): + pass + +static var static_var: + set(_value): + var f := func (): + var g := func (): + print(non_static_func) + g.call() + f.call() + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda_setter.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda_setter.out new file mode 100644 index 0000000000..de43f2d3c4 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_access_non_static_in_lambda_setter.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot access non-static function "non_static_func" from the static function "@static_var_setter()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out index cdf3ab2aeb..a285b80025 100644 --- a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_call_non_static_in_lambda_setter.out @@ -1,2 +1,2 @@ GDTEST_ANALYZER_ERROR -Cannot call non-static function "non_static_func()" from static function "@static_var_setter()". +Cannot call non-static function "non_static_func()" from the static function "@static_var_setter()". diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_access.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_access.gd new file mode 100644 index 0000000000..a21b2c4470 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_access.gd @@ -0,0 +1,11 @@ +# GH-91403 + +@static_unload + +func non_static(): + return "non static" + +static var static_var = Callable(non_static) + +func test(): + print("does not run") diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_access.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_access.out new file mode 100644 index 0000000000..a95069dc4f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_access.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Cannot access non-static function "non_static" from a static variable initializer. diff --git a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd index 73d0f9096c..18675e5725 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.gd @@ -345,3 +345,12 @@ func test(): prints(x and true) prints(x or false) prints(x or true) + + # TYPE_PACKED_VECTOR4_ARRAY + x = PackedVector4Array([Vector4.ONE]) + prints("TYPE_PACKED_VECTOR4_ARRAY") + prints(not x) + prints(x and false) + prints(x and true) + prints(x or false) + prints(x or true) diff --git a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out index e2945c910a..47f9d7548b 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out +++ b/modules/gdscript/tests/scripts/analyzer/features/boolean_operators_for_all_types.out @@ -227,3 +227,9 @@ false true true true +TYPE_PACKED_VECTOR4_ARRAY +false +false +true +true +true diff --git a/modules/gdscript/tests/scripts/analyzer/features/cast_enum_to_int.gd b/modules/gdscript/tests/scripts/analyzer/features/cast_enum_to_int.gd new file mode 100644 index 0000000000..77ef9e2073 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/cast_enum_to_int.gd @@ -0,0 +1,9 @@ +# GH-85882 + +enum Foo { A, B, C } + +func test(): + var a := Foo.A + var b := a as int + 1 + print(b) + diff --git a/modules/gdscript/tests/scripts/analyzer/features/cast_enum_to_int.out b/modules/gdscript/tests/scripts/analyzer/features/cast_enum_to_int.out new file mode 100644 index 0000000000..a7f1357bb2 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/cast_enum_to_int.out @@ -0,0 +1,2 @@ +GDTEST_OK +1 diff --git a/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd b/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd index 1c4b19d8e0..0444051831 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/enum_typecheck_inner_class.gd @@ -11,6 +11,7 @@ class InnerClass: var e2: InnerClass.MyEnum var e3: EnumTypecheckOuterClass.InnerClass.MyEnum + @warning_ignore("unassigned_variable") print("Self ", e1, e2, e3) e1 = MyEnum.V1 e2 = MyEnum.V1 @@ -48,6 +49,7 @@ func test_outer_from_outer(): var e1: MyEnum var e2: EnumTypecheckOuterClass.MyEnum + @warning_ignore("unassigned_variable") print("Self ", e1, e2) e1 = MyEnum.V1 e2 = MyEnum.V1 @@ -66,6 +68,7 @@ func test_inner_from_outer(): var e1: InnerClass.MyEnum var e2: EnumTypecheckOuterClass.InnerClass.MyEnum + @warning_ignore("unassigned_variable") print("Inner ", e1, e2) e1 = InnerClass.MyEnum.V1 e2 = InnerClass.MyEnum.V1 diff --git a/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd new file mode 100644 index 0000000000..c83a3a8a14 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.gd @@ -0,0 +1,6 @@ +# GH-88082 + +func test(): + var x = 1 + var message := "value: %s" % x + print(message) diff --git a/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out new file mode 100644 index 0000000000..cf6464a4c3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/infer_type_on_string_format.out @@ -0,0 +1,2 @@ +GDTEST_OK +value: 1 diff --git a/modules/gdscript/tests/scripts/analyzer/features/static_non_static_access.gd b/modules/gdscript/tests/scripts/analyzer/features/static_non_static_access.gd new file mode 100644 index 0000000000..80ceb6d1a9 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/static_non_static_access.gd @@ -0,0 +1,75 @@ +@static_unload + +static var static_var +var non_static_var + +signal my_signal() + +static func static_func(): + pass + +func non_static_func(): + pass + +static var test_static_var_lambda = func (): + static_func() + print(static_func) + static_var = 1 + print(static_var) + +var test_non_static_var_lambda = func (): + static_func() + print(static_func) + static_var = 1 + print(static_var) + + non_static_func() + print(non_static_func) + non_static_var = 1 + print(non_static_var) + my_signal.emit() + print(my_signal) + +static var test_static_var_setter: + set(_value): + static_func() + print(static_func) + static_var = 1 + print(static_var) + +var test_non_static_var_setter: + set(_value): + static_func() + print(static_func) + static_var = 1 + print(static_var) + + non_static_func() + print(non_static_func) + non_static_var = 1 + print(non_static_var) + my_signal.emit() + print(my_signal) + +static func test_static_func(): + static_func() + print(static_func) + static_var = 1 + print(static_var) + +func test_non_static_func(): + static_func() + print(static_func) + static_var = 1 + print(static_var) + + non_static_func() + print(non_static_func) + non_static_var = 1 + print(non_static_var) + my_signal.emit() + print(my_signal) + +func test(): + test_static_var_lambda = null + test_non_static_var_lambda = null diff --git a/modules/gdscript/tests/scripts/analyzer/features/static_non_static_access.out b/modules/gdscript/tests/scripts/analyzer/features/static_non_static_access.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/static_non_static_access.out @@ -0,0 +1 @@ +GDTEST_OK diff --git a/modules/gdscript/tests/scripts/analyzer/features/unassigned_builtin_typed.gd b/modules/gdscript/tests/scripts/analyzer/features/unassigned_builtin_typed.gd new file mode 100644 index 0000000000..8099b366f3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/unassigned_builtin_typed.gd @@ -0,0 +1,7 @@ +# GH-88117, GH-85796 + +func test(): + var array: Array + # Should not emit unassigned warning because the Array type has a default value. + array.assign([1, 2, 3]) + print(array) diff --git a/modules/gdscript/tests/scripts/analyzer/features/unassigned_builtin_typed.out b/modules/gdscript/tests/scripts/analyzer/features/unassigned_builtin_typed.out new file mode 100644 index 0000000000..6d85a6cc07 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/unassigned_builtin_typed.out @@ -0,0 +1,2 @@ +GDTEST_OK +[1, 2, 3] diff --git a/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_warnings.gd b/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_warnings.gd index 8a1ab6f406..333950d64e 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_warnings.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/warning_ignore_warnings.gd @@ -31,8 +31,8 @@ func int_func() -> int: func test_warnings(unused_private_class_variable): var t = 1 - @warning_ignore("unassigned_variable") var unassigned_variable + @warning_ignore("unassigned_variable") print(unassigned_variable) var _unassigned_variable_op_assign diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd new file mode 100644 index 0000000000..13e3edf93f --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.gd @@ -0,0 +1,9 @@ +enum HasZero { A = 0, B = 1 } +enum HasNoZero { A = 1, B = 2 } +var has_zero: HasZero # No warning, because the default `0` is valid. +var has_no_zero: HasNoZero # Warning, because there is no `0` in the enum. + + +func test(): + print(has_zero) + print(has_no_zero) diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out new file mode 100644 index 0000000000..ae40e0bc8c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/enum_without_default_value.out @@ -0,0 +1,7 @@ +GDTEST_OK +>> WARNING +>> Line: 4 +>> ENUM_VARIABLE_WITHOUT_DEFAULT +>> The variable "has_no_zero" has an enum type and does not set an explicit default value. The default will be set to "0". +0 +0 diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.gd b/modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.gd new file mode 100644 index 0000000000..1a6d10f8f7 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.gd @@ -0,0 +1,24 @@ +# We don't want to execute it because of errors, just analyze. +func no_exec_test(): + var weak_int = 1 + print(weak_int as Variant) # No warning. + print(weak_int as int) + print(weak_int as Node) + + var weak_node = Node.new() + print(weak_node as Variant) # No warning. + print(weak_node as int) + print(weak_node as Node) + + var weak_variant = null + print(weak_variant as Variant) # No warning. + print(weak_variant as int) + print(weak_variant as Node) + + var hard_variant: Variant = null + print(hard_variant as Variant) # No warning. + print(hard_variant as int) + print(hard_variant as Node) + +func test(): + pass diff --git a/modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.out b/modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.out new file mode 100644 index 0000000000..c1e683d942 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/warnings/unsafe_cast.out @@ -0,0 +1,33 @@ +GDTEST_OK +>> WARNING +>> Line: 5 +>> UNSAFE_CAST +>> Casting "Variant" to "int" is unsafe. +>> WARNING +>> Line: 6 +>> UNSAFE_CAST +>> Casting "Variant" to "Node" is unsafe. +>> WARNING +>> Line: 10 +>> UNSAFE_CAST +>> Casting "Variant" to "int" is unsafe. +>> WARNING +>> Line: 11 +>> UNSAFE_CAST +>> Casting "Variant" to "Node" is unsafe. +>> WARNING +>> Line: 15 +>> UNSAFE_CAST +>> Casting "Variant" to "int" is unsafe. +>> WARNING +>> Line: 16 +>> UNSAFE_CAST +>> Casting "Variant" to "Node" is unsafe. +>> WARNING +>> Line: 20 +>> UNSAFE_CAST +>> Casting "Variant" to "int" is unsafe. +>> WARNING +>> Line: 21 +>> UNSAFE_CAST +>> Casting "Variant" to "Node" is unsafe. diff --git a/modules/gdscript/tests/scripts/completion/argument_options/argument_options.tscn b/modules/gdscript/tests/scripts/completion/argument_options/argument_options.tscn new file mode 100644 index 0000000000..d3dea6b12b --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/argument_options/argument_options.tscn @@ -0,0 +1,3 @@ +[gd_scene load_steps=1 format=3 uid="uid://dl28pdkxcjvym"] + +[node name="GetNode" type="Node"] diff --git a/modules/gdscript/tests/scripts/completion/argument_options/connect.cfg b/modules/gdscript/tests/scripts/completion/argument_options/connect.cfg new file mode 100644 index 0000000000..8c3fbf90da --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/argument_options/connect.cfg @@ -0,0 +1,8 @@ +[input] +scene="res://completion/argument_options/argument_options.tscn" +[output] +include=[ + ; Node + {"display": "\"signal_a\""}, + {"display": "\"child_entered_tree\""}, +] diff --git a/modules/gdscript/tests/scripts/completion/argument_options/connect.gd b/modules/gdscript/tests/scripts/completion/argument_options/connect.gd new file mode 100644 index 0000000000..1137070c4e --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/argument_options/connect.gd @@ -0,0 +1,7 @@ +extends Node + +signal signal_a() + +func _ready(): + connect(➡) + pass diff --git a/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_autocomplete.cfg b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_autocomplete.cfg new file mode 100644 index 0000000000..7c7b465f26 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_autocomplete.cfg @@ -0,0 +1,9 @@ +[output] +include=[ + {"display": "DrawMode", + "location": 256}, + {"display": "Anchor", + "location": 257}, + {"display": "TextureRepeat", + "location": 258}, +] diff --git a/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_autocomplete.gd b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_autocomplete.gd new file mode 100644 index 0000000000..83f4b17a86 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_autocomplete.gd @@ -0,0 +1,4 @@ +extends Control + +func _ready(): + var t = BaseButton.➡ diff --git a/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_values_autocompletion.cfg b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_values_autocompletion.cfg new file mode 100644 index 0000000000..7ccfa550e2 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_values_autocompletion.cfg @@ -0,0 +1,5 @@ +[output] +include=[ + {"display": "HEURISTIC_MAX"}, + {"display": "HEURISTIC_OCTILE"}, +] diff --git a/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_values_autocompletion.gd b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_values_autocompletion.gd new file mode 100644 index 0000000000..99e38be6b9 --- /dev/null +++ b/modules/gdscript/tests/scripts/completion/builtin_enum/builtin_enum_values_autocompletion.gd @@ -0,0 +1,4 @@ +extends Control + +func _ready(): + AStarGrid2D.Heuristic.➡ diff --git a/modules/gdscript/tests/scripts/completion/get_node/literal/dollar.gd b/modules/gdscript/tests/scripts/completion/get_node/literal/dollar.gd index df458a9435..dc7cc99554 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/literal/dollar.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/literal/dollar.gd @@ -2,3 +2,4 @@ extends Node func a(): %AnimationPlayer.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/literal/percent.gd b/modules/gdscript/tests/scripts/completion/get_node/literal/percent.gd index 7050761b86..5586317938 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/literal/percent.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/literal/percent.gd @@ -2,3 +2,4 @@ extends Node func a(): $UniqueAnimationPlayer.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_class_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_class_scene.gd index a84283a1de..69fcac4471 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_class_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_class_scene.gd @@ -2,3 +2,4 @@ extends Node func a(): $A.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_native_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_native_scene.gd index 6e3fee1696..0b13a207ff 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_native_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/dollar_native_scene.gd @@ -2,3 +2,4 @@ extends Node func a(): $AnimationPlayer.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_class_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_class_scene.gd index 27f059c944..48945db38e 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_class_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_class_scene.gd @@ -2,3 +2,4 @@ extends Node func a(): %UniqueA.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_native_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_native_scene.gd index 07068fc5a4..3684edc73b 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_native_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/literal_scene/percent_native_scene.gd @@ -2,3 +2,4 @@ extends Node func a(): %UniqueAnimationPlayer.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local/local.gd b/modules/gdscript/tests/scripts/completion/get_node/local/local.gd index 596ad80ef2..dcd232d82d 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local/local.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local/local.gd @@ -3,3 +3,4 @@ extends Node func a(): var test = $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_interfered/local_interfered.gd b/modules/gdscript/tests/scripts/completion/get_node/local_interfered/local_interfered.gd index 6f87af3c85..7710c2d13b 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_interfered/local_interfered.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_interfered/local_interfered.gd @@ -3,3 +3,4 @@ extends Node func a(): var test := $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/class_local_interfered_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/class_local_interfered_scene.gd index a710c8bbd7..6b29bf5526 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/class_local_interfered_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/class_local_interfered_scene.gd @@ -3,3 +3,4 @@ extends Node func a(): var test := $A test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/native_local_interfered_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/native_local_interfered_scene.gd index 6f87af3c85..7710c2d13b 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/native_local_interfered_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_interfered_scene/native_local_interfered_scene.gd @@ -3,3 +3,4 @@ extends Node func a(): var test := $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_scene/class_local_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/local_scene/class_local_scene.gd index 2fc88f93dd..02c0d2dceb 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_scene/class_local_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_scene/class_local_scene.gd @@ -3,3 +3,4 @@ extends Node func a(): var test = $A test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_scene/native_local_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/local_scene/native_local_scene.gd index 596ad80ef2..dcd232d82d 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_scene/native_local_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_scene/native_local_scene.gd @@ -3,3 +3,4 @@ extends Node func a(): var test = $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint/class_local_typehint.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint/class_local_typehint.gd index b6d2074939..3277beccab 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint/class_local_typehint.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint/class_local_typehint.gd @@ -5,3 +5,4 @@ const A := preload("res://completion/class_a.notest.gd") func a(): var test: A = $A test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint/native_local_typehint.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint/native_local_typehint.gd index 13b541a35d..e6d22af296 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint/native_local_typehint.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint/native_local_typehint.gd @@ -3,3 +3,4 @@ extends Node func a(): var test: AnimationPlayer = $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/class_local_typehint_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/class_local_typehint_scene.gd index b6d2074939..3277beccab 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/class_local_typehint_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/class_local_typehint_scene.gd @@ -5,3 +5,4 @@ const A := preload("res://completion/class_a.notest.gd") func a(): var test: A = $A test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/native_local_typehint_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/native_local_typehint_scene.gd index 13b541a35d..e6d22af296 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/native_local_typehint_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene/native_local_typehint_scene.gd @@ -3,3 +3,4 @@ extends Node func a(): var test: AnimationPlayer = $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/class_local_typehint_scene_broad.notest.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/class_local_typehint_scene_broad.notest.gd index 5c785b3ddc..3266679a6a 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/class_local_typehint_scene_broad.notest.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/class_local_typehint_scene_broad.notest.gd @@ -4,3 +4,4 @@ extends Node func a(): var test: Node = $A test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/native_local_typehint_scene_broad.notest.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/native_local_typehint_scene_broad.notest.gd index 57f4e16e3c..f637fc3d0f 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/native_local_typehint_scene_broad.notest.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_broad/native_local_typehint_scene_broad.notest.gd @@ -4,3 +4,4 @@ extends Node func a(): var test: Node = $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/class_local_typehint_scene_incompatible.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/class_local_typehint_scene_incompatible.gd index c6adfe0dd3..8ce75d9996 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/class_local_typehint_scene_incompatible.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/class_local_typehint_scene_incompatible.gd @@ -3,3 +3,4 @@ extends Node func a(): var test: Area2D = $A test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/native_local_typehint_scene_incompatible.gd b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/native_local_typehint_scene_incompatible.gd index f53fce9bfe..2b39e3ada7 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/native_local_typehint_scene_incompatible.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/local_typehint_scene_incompatible/native_local_typehint_scene_incompatible.gd @@ -3,3 +3,4 @@ extends Node func a(): var test: Area2D = $AnimationPlayer test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member/member.gd b/modules/gdscript/tests/scripts/completion/get_node/member/member.gd index 6bcc0a0298..80b4943953 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member/member.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member/member.gd @@ -4,3 +4,4 @@ var test = $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_interfered/member_interfered.gd b/modules/gdscript/tests/scripts/completion/get_node/member_interfered/member_interfered.gd index 542197e643..97b288334e 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_interfered/member_interfered.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_interfered/member_interfered.gd @@ -4,3 +4,4 @@ var test := $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/class_member_interfered_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/class_member_interfered_scene.gd index da0b1b11d4..402fd1d275 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/class_member_interfered_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/class_member_interfered_scene.gd @@ -4,3 +4,4 @@ var test := $A func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/native_member_interfered_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/native_member_interfered_scene.gd index 542197e643..97b288334e 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/native_member_interfered_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_interfered_scene/native_member_interfered_scene.gd @@ -4,3 +4,4 @@ var test := $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_scene/class_member_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/member_scene/class_member_scene.gd index 4a35661e94..6188a6e843 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_scene/class_member_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_scene/class_member_scene.gd @@ -4,3 +4,4 @@ var test = $A func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_scene/native_member_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/member_scene/native_member_scene.gd index 6bcc0a0298..80b4943953 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_scene/native_member_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_scene/native_member_scene.gd @@ -4,3 +4,4 @@ var test = $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint/class_member_typehint.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint/class_member_typehint.gd index e4edc3a4e4..01b7c76dbf 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint/class_member_typehint.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint/class_member_typehint.gd @@ -6,3 +6,4 @@ var test: A = $A func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint/native_member_typehint.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint/native_member_typehint.gd index eda94ae34d..7f2cb4e8cc 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint/native_member_typehint.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint/native_member_typehint.gd @@ -4,3 +4,4 @@ var test: AnimationPlayer = $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/class_member_typehint_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/class_member_typehint_scene.gd index 8f68f54072..43d8b666ab 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/class_member_typehint_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/class_member_typehint_scene.gd @@ -6,3 +6,4 @@ const A := preload("res://completion/class_a.notest.gd") func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/native_member_typehint_scene.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/native_member_typehint_scene.gd index eda94ae34d..7f2cb4e8cc 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/native_member_typehint_scene.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene/native_member_typehint_scene.gd @@ -4,3 +4,4 @@ var test: AnimationPlayer = $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/class_member_typehint_scene_broad.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/class_member_typehint_scene_broad.gd index 7b0ed4ecd8..aac450be9f 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/class_member_typehint_scene_broad.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/class_member_typehint_scene_broad.gd @@ -4,3 +4,4 @@ var test: Node = $A func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/native_member_typehint_scene_broad.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/native_member_typehint_scene_broad.gd index 87342f9a21..9eb10e4933 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/native_member_typehint_scene_broad.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_broad/native_member_typehint_scene_broad.gd @@ -4,3 +4,4 @@ var test: Node = $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/class_member_typehint_scene_incompatible.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/class_member_typehint_scene_incompatible.gd index 5f78bcdf04..ff8214c463 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/class_member_typehint_scene_incompatible.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/class_member_typehint_scene_incompatible.gd @@ -4,3 +4,4 @@ var test: Area2D = $A func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/native_member_typehint_scene_incompatible.gd b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/native_member_typehint_scene_incompatible.gd index c14df5cd1b..30cd7d6a21 100644 --- a/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/native_member_typehint_scene_incompatible.gd +++ b/modules/gdscript/tests/scripts/completion/get_node/member_typehint_scene_incompatible/native_member_typehint_scene_incompatible.gd @@ -4,3 +4,4 @@ var test: Area2D = $AnimationPlayer func a(): test.➡ + pass diff --git a/modules/gdscript/tests/scripts/parser/features/constants.out b/modules/gdscript/tests/scripts/parser/features/constants.out index 7ec33470d3..d73c5eb7cd 100644 --- a/modules/gdscript/tests/scripts/parser/features/constants.out +++ b/modules/gdscript/tests/scripts/parser/features/constants.out @@ -1,33 +1 @@ GDTEST_OK ->> WARNING ->> Line: 2 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_TEST" is declared but never used in the block. If this is intended, prefix it with an underscore: "__TEST". ->> WARNING ->> Line: 3 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_STRING" is declared but never used in the block. If this is intended, prefix it with an underscore: "__STRING". ->> WARNING ->> Line: 4 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_VECTOR" is declared but never used in the block. If this is intended, prefix it with an underscore: "__VECTOR". ->> WARNING ->> Line: 5 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_ARRAY" is declared but never used in the block. If this is intended, prefix it with an underscore: "__ARRAY". ->> WARNING ->> Line: 6 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_DICTIONARY" is declared but never used in the block. If this is intended, prefix it with an underscore: "__DICTIONARY". ->> WARNING ->> Line: 9 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_HELLO" is declared but never used in the block. If this is intended, prefix it with an underscore: "__HELLO". ->> WARNING ->> Line: 10 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INFINITY" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INFINITY". ->> WARNING ->> Line: 11 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_NOT_A_NUMBER" is declared but never used in the block. If this is intended, prefix it with an underscore: "__NOT_A_NUMBER". diff --git a/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.gd b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.gd new file mode 100644 index 0000000000..cb0bc94d2e --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.gd @@ -0,0 +1,12 @@ +# GH-89403 + +func test(): + var x := 1 + if x == 0 \ + # Comment. + # Comment. + and (x < 1 or x > 2) \ + # Comment. + and x != 3: + pass + print("Ok") diff --git a/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.out b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.out new file mode 100644 index 0000000000..0e9f482af4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/continuation_lines_comments.bin.out @@ -0,0 +1,2 @@ +GDTEST_OK +Ok diff --git a/modules/gdscript/tests/scripts/parser/features/export_arrays.gd b/modules/gdscript/tests/scripts/parser/features/export_arrays.gd index ddfb186aa4..0d97135a7b 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_arrays.gd +++ b/modules/gdscript/tests/scripts/parser/features/export_arrays.gd @@ -63,6 +63,7 @@ var temp_packed_float64_array: PackedFloat64Array var temp_packed_color_array: PackedColorArray var temp_packed_vector2_array: PackedVector2Array var temp_packed_vector3_array: PackedVector3Array +var temp_packed_vector4_array: PackedVector4Array @export var test_weak_packed_byte_array = temp_packed_byte_array @export var test_weak_packed_int32_array = temp_packed_int32_array @@ -72,6 +73,7 @@ var temp_packed_vector3_array: PackedVector3Array @export var test_weak_packed_color_array = temp_packed_color_array @export var test_weak_packed_vector2_array = temp_packed_vector2_array @export var test_weak_packed_vector3_array = temp_packed_vector3_array +@export var test_weak_packed_vector4_array = temp_packed_vector4_array @export_range(1, 10) var test_range_weak_packed_byte_array = temp_packed_byte_array @export_range(1, 10) var test_range_weak_packed_int32_array = temp_packed_int32_array diff --git a/modules/gdscript/tests/scripts/parser/features/export_arrays.out b/modules/gdscript/tests/scripts/parser/features/export_arrays.out index 00e75fcc43..acbf389645 100644 --- a/modules/gdscript/tests/scripts/parser/features/export_arrays.out +++ b/modules/gdscript/tests/scripts/parser/features/export_arrays.out @@ -123,6 +123,8 @@ var test_weak_packed_vector2_array: PackedVector2Array hint=TYPE_STRING hint_string="Vector2:Vector2" usage=DEFAULT|SCRIPT_VARIABLE var test_weak_packed_vector3_array: PackedVector3Array hint=TYPE_STRING hint_string="Vector3:Vector3" usage=DEFAULT|SCRIPT_VARIABLE +var test_weak_packed_vector4_array: PackedVector4Array + hint=TYPE_STRING hint_string="Vector4:Vector4" usage=DEFAULT|SCRIPT_VARIABLE var test_range_weak_packed_byte_array: PackedByteArray hint=TYPE_STRING hint_string="int/RANGE:1,10" usage=DEFAULT|SCRIPT_VARIABLE var test_range_weak_packed_int32_array: PackedInt32Array diff --git a/modules/gdscript/tests/scripts/parser/features/match_array.gd b/modules/gdscript/tests/scripts/parser/features/match_array.gd new file mode 100644 index 0000000000..9103092cb4 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_array.gd @@ -0,0 +1,33 @@ +func foo(x): + match x: + ["value1"]: + print('["value1"]') + ["value1", "value2"]: + print('["value1", "value2"]') + +func bar(x): + match x: + [ + "value1" + ]: + print('multiline ["value1"]') + [ + "value1", + "value2", + ]: + print('multiline ["value1", "value2",]') + [ + "value1", + [ + "value2", + .., + ], + ]: + print('multiline ["value1", ["value2", ..,],]') + +func test(): + foo(["value1"]) + foo(["value1", "value2"]) + bar(["value1"]) + bar(["value1", "value2"]) + bar(["value1", ["value2", "value3"]]) diff --git a/modules/gdscript/tests/scripts/parser/features/match_array.out b/modules/gdscript/tests/scripts/parser/features/match_array.out new file mode 100644 index 0000000000..d0111f07b1 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/features/match_array.out @@ -0,0 +1,6 @@ +GDTEST_OK +["value1"] +["value1", "value2"] +multiline ["value1"] +multiline ["value1", "value2",] +multiline ["value1", ["value2", ..,],] diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd index 75857fb8ff..7685622e5a 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.gd @@ -26,6 +26,24 @@ func bar(x): _: print("wildcard") +func baz(x): + match x: + { + "key1": "value1" + }: + print('multiline {"key1": "value1"}') + { + "key2": "value2", + }: + print('multiline {"key2": "value2",}') + { + "key3": { + "key1", + .., + }, + }: + print('multiline {"key3": {"key1", ..,},}') + func test(): foo({"key1": "value1", "key2": "value2"}) foo({"key1": "value1", "key2": ""}) @@ -41,3 +59,6 @@ func test(): bar({1: "1"}) bar({2: "2"}) bar({3: "3"}) + baz({"key1": "value1"}) + baz({"key2": "value2"}) + baz({"key3": {"key1": "value1", "key2": "value2"}}) diff --git a/modules/gdscript/tests/scripts/parser/features/match_dictionary.out b/modules/gdscript/tests/scripts/parser/features/match_dictionary.out index 4dee886927..f9adcbd331 100644 --- a/modules/gdscript/tests/scripts/parser/features/match_dictionary.out +++ b/modules/gdscript/tests/scripts/parser/features/match_dictionary.out @@ -13,3 +13,6 @@ wildcard 1 2 wildcard +multiline {"key1": "value1"} +multiline {"key2": "value2",} +multiline {"key3": {"key1", ..,},} diff --git a/modules/gdscript/tests/scripts/parser/features/static_typing.out b/modules/gdscript/tests/scripts/parser/features/static_typing.out index 40a8f97416..d73c5eb7cd 100644 --- a/modules/gdscript/tests/scripts/parser/features/static_typing.out +++ b/modules/gdscript/tests/scripts/parser/features/static_typing.out @@ -1,21 +1 @@ GDTEST_OK ->> WARNING ->> Line: 11 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER". ->> WARNING ->> Line: 12 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_TYPED" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_TYPED". ->> WARNING ->> Line: 13 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_TYPED2" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_TYPED2". ->> WARNING ->> Line: 14 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_INFERRED" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_INFERRED". ->> WARNING ->> Line: 15 ->> UNUSED_LOCAL_CONSTANT ->> The local constant "_INTEGER_REDUNDANT_INFERRED2" is declared but never used in the block. If this is intended, prefix it with an underscore: "__INTEGER_REDUNDANT_INFERRED2". diff --git a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd index afb5059eea..b38cffb754 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd +++ b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.gd @@ -1,2 +1,11 @@ func test(): - var __ + var unassigned + print(unassigned) + unassigned = "something" # Assigned only after use. + + var a + print(a) # Unassigned, warn. + if a: # Still unassigned, warn. + a = 1 + print(a) # Assigned (dead code), don't warn. + print(a) # "Maybe" assigned, don't warn. diff --git a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out index 10f89be132..36db304ef4 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out +++ b/modules/gdscript/tests/scripts/parser/warnings/unassigned_variable.out @@ -1,5 +1,16 @@ GDTEST_OK >> WARNING ->> Line: 2 +>> Line: 3 >> UNASSIGNED_VARIABLE ->> The variable "__" was used but never assigned a value. +>> The variable "unassigned" was used before being assigned a value. +>> WARNING +>> Line: 7 +>> UNASSIGNED_VARIABLE +>> The variable "a" was used before being assigned a value. +>> WARNING +>> Line: 8 +>> UNASSIGNED_VARIABLE +>> The variable "a" was used before being assigned a value. +<null> +<null> +<null> diff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd new file mode 100644 index 0000000000..3d355197e1 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.gd @@ -0,0 +1,4 @@ +func test(): + const UNUSED = "not used" + + const _UNUSED = "not used, but no warning since the constant name starts with an underscore" diff --git a/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out new file mode 100644 index 0000000000..99ced48433 --- /dev/null +++ b/modules/gdscript/tests/scripts/parser/warnings/unused_constant.out @@ -0,0 +1,5 @@ +GDTEST_OK +>> WARNING +>> Line: 2 +>> UNUSED_LOCAL_CONSTANT +>> The local constant "UNUSED" is declared but never used in the block. If this is intended, prefix it with an underscore: "_UNUSED". diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.gd b/modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.gd new file mode 100644 index 0000000000..6b766f4d3d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.gd @@ -0,0 +1,4 @@ +func test(): + var node := Node.new() + node.free() + print(node as Node2D) diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.out b/modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.out new file mode 100644 index 0000000000..90d81dd9a1 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_freed_object.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/cast_freed_object.gd +>> 4 +>> Trying to cast a freed object. diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.gd b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.gd new file mode 100644 index 0000000000..00817c588f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.gd @@ -0,0 +1,4 @@ +func test(): + var integer: Variant = 1 + @warning_ignore("unsafe_cast") + print(integer as Array) diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.out b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.out new file mode 100644 index 0000000000..545d7a4906 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_array.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/cast_int_to_array.gd +>> 4 +>> Invalid cast: could not convert value to 'Array'. diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.gd b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.gd new file mode 100644 index 0000000000..44673a4513 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.gd @@ -0,0 +1,4 @@ +func test(): + var integer: Variant = 1 + @warning_ignore("unsafe_cast") + print(integer as Node) diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.out b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.out new file mode 100644 index 0000000000..7c39b46396 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_int_to_object.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/cast_int_to_object.gd +>> 4 +>> Invalid cast: can't convert a non-object value to an object type. diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.gd b/modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.gd new file mode 100644 index 0000000000..830d0c0c4a --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.gd @@ -0,0 +1,4 @@ +func test(): + var object: Variant = RefCounted.new() + @warning_ignore("unsafe_cast") + print(object as int) diff --git a/modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.out b/modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.out new file mode 100644 index 0000000000..f922199fb3 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/cast_object_to_int.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/cast_object_to_int.gd +>> 4 +>> Invalid cast: could not convert value to 'int'. diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out index c524a1ae6b..350d5d1d45 100644 --- a/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_array_is_deep.out @@ -3,4 +3,4 @@ GDTEST_RUNTIME_ERROR >> on function: test() >> runtime/errors/constant_array_is_deep.gd >> 6 ->> Invalid assignment of property or key '0' with value of type 'int' on a base object of type 'Dictionary'. +>> Invalid assignment on read-only value (on base: 'Dictionary'). diff --git a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out index cf51b0262d..5f1f372b0a 100644 --- a/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out +++ b/modules/gdscript/tests/scripts/runtime/errors/constant_dictionary_is_deep.out @@ -3,4 +3,4 @@ GDTEST_RUNTIME_ERROR >> on function: test() >> runtime/errors/constant_dictionary_is_deep.gd >> 6 ->> Invalid assignment of index '0' (on base: 'Array') with value of type 'int'. +>> Invalid assignment on read-only value (on base: 'Array'). diff --git a/modules/gdscript/tests/scripts/runtime/errors/read_only_dictionary.gd b/modules/gdscript/tests/scripts/runtime/errors/read_only_dictionary.gd new file mode 100644 index 0000000000..2f31ecc52f --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/read_only_dictionary.gd @@ -0,0 +1,4 @@ +func test(): + var dictionary := { "a": 0 } + dictionary.make_read_only() + dictionary.a = 1 diff --git a/modules/gdscript/tests/scripts/runtime/errors/read_only_dictionary.out b/modules/gdscript/tests/scripts/runtime/errors/read_only_dictionary.out new file mode 100644 index 0000000000..f7d531e119 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/errors/read_only_dictionary.out @@ -0,0 +1,6 @@ +GDTEST_RUNTIME_ERROR +>> SCRIPT ERROR +>> on function: test() +>> runtime/errors/read_only_dictionary.gd +>> 4 +>> Invalid assignment on read-only value (on base: 'Dictionary'). diff --git a/modules/gdscript/tests/scripts/runtime/features/await_signal_with_parameters.gd b/modules/gdscript/tests/scripts/runtime/features/await_signal_with_parameters.gd new file mode 100644 index 0000000000..ff0001676d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/await_signal_with_parameters.gd @@ -0,0 +1,25 @@ +signal no_parameters() +signal one_parameter(number) +signal two_parameters(number1, number2) + +func await_no_parameters(): + var result = await no_parameters + print(result) + +func await_one_parameter(): + var result = await one_parameter + print(result) + +func await_two_parameters(): + var result = await two_parameters + print(result) + +func test(): + await_no_parameters() + no_parameters.emit() + + await_one_parameter() + one_parameter.emit(1) + + await_two_parameters() + two_parameters.emit(1, 2) diff --git a/modules/gdscript/tests/scripts/runtime/features/await_signal_with_parameters.out b/modules/gdscript/tests/scripts/runtime/features/await_signal_with_parameters.out new file mode 100644 index 0000000000..9e203c601c --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/await_signal_with_parameters.out @@ -0,0 +1,4 @@ +GDTEST_OK +<null> +1 +[1, 2] diff --git a/modules/gdscript/tests/scripts/runtime/features/call_native_static_method_validated.gd b/modules/gdscript/tests/scripts/runtime/features/call_native_static_method_validated.gd new file mode 100644 index 0000000000..35e4dbd6a0 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/call_native_static_method_validated.gd @@ -0,0 +1,7 @@ +func test(): + # Validated native static call with return value. + print(FileAccess.file_exists("some_file")) + + # Validated native static call without return value. + Node.print_orphan_nodes() + diff --git a/modules/gdscript/tests/scripts/runtime/features/call_native_static_method_validated.out b/modules/gdscript/tests/scripts/runtime/features/call_native_static_method_validated.out new file mode 100644 index 0000000000..44302c8137 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/call_native_static_method_validated.out @@ -0,0 +1,2 @@ +GDTEST_OK +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd index 809d0d28a9..5d8dafc4a1 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.gd @@ -140,3 +140,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(value == null) + + # PackedVector4Array + value = PackedVector4Array() + print(value == null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out index 27423ab8e7..e0e222eccc 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_equals_null.out @@ -34,3 +34,4 @@ false false false false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd index f46afb0f18..88286ede03 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.gd @@ -140,3 +140,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(value != null) + + # PackedVector4Array + value = PackedVector4Array() + print(value != null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out index a11c47854a..f6e72aedd5 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_builtin_not_equals_null.out @@ -34,3 +34,4 @@ true true true true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd index 7649062fda..6ca1b3e490 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.gd @@ -136,3 +136,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(null == value) + + # PackedVector4Array + value = PackedVector4Array() + print(null == value) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out index 639f6027b9..27423ab8e7 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_equals_builtin.out @@ -33,3 +33,4 @@ false false false false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd index 8d5f9df1b8..d7addfa390 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.gd @@ -136,3 +136,7 @@ func test(): # PackedColorArray value = PackedColorArray() print(null != value) + + # PackedVector4Array + value = PackedVector4Array() + print(null != value) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out index d1e332afba..a11c47854a 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare_null_not_equals_builtin.out @@ -33,3 +33,4 @@ true true true true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/emit_after_await.gd b/modules/gdscript/tests/scripts/runtime/features/emit_after_await.gd new file mode 100644 index 0000000000..21fd526acc --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/emit_after_await.gd @@ -0,0 +1,12 @@ +# https://github.com/godotengine/godot/issues/89439 +extends Node + +signal my_signal + +func async_func(): + await my_signal + my_signal.emit() + +func test(): + async_func() + my_signal.emit() diff --git a/modules/gdscript/tests/scripts/runtime/features/emit_after_await.out b/modules/gdscript/tests/scripts/runtime/features/emit_after_await.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/emit_after_await.out @@ -0,0 +1 @@ +GDTEST_OK diff --git a/modules/gdscript/tests/scripts/runtime/features/emit_one_shot_is_non_recursive.gd b/modules/gdscript/tests/scripts/runtime/features/emit_one_shot_is_non_recursive.gd new file mode 100644 index 0000000000..5c328dcfcd --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/emit_one_shot_is_non_recursive.gd @@ -0,0 +1,22 @@ +# https://github.com/godotengine/godot/issues/89439 + +signal my_signal + +func foo(): + print("Foo") + my_signal.emit() + +func bar(): + print("Bar") + +func baz(): + print("Baz") + +func test(): + @warning_ignore("return_value_discarded") + my_signal.connect(foo, CONNECT_ONE_SHOT) + @warning_ignore("return_value_discarded") + my_signal.connect(bar, CONNECT_ONE_SHOT) + @warning_ignore("return_value_discarded") + my_signal.connect(baz) + my_signal.emit() diff --git a/modules/gdscript/tests/scripts/runtime/features/emit_one_shot_is_non_recursive.out b/modules/gdscript/tests/scripts/runtime/features/emit_one_shot_is_non_recursive.out new file mode 100644 index 0000000000..3399e08878 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/emit_one_shot_is_non_recursive.out @@ -0,0 +1,5 @@ +GDTEST_OK +Foo +Baz +Bar +Baz diff --git a/modules/gdscript/tests/scripts/runtime/features/member_info.gd b/modules/gdscript/tests/scripts/runtime/features/member_info.gd index d7485f49e6..42b29eee43 100644 --- a/modules/gdscript/tests/scripts/runtime/features/member_info.gd +++ b/modules/gdscript/tests/scripts/runtime/features/member_info.gd @@ -23,6 +23,7 @@ var test_var_hard_int: int var test_var_hard_variant_type: Variant.Type @export var test_var_hard_variant_type_exported: Variant.Type var test_var_hard_node_process_mode: Node.ProcessMode +@warning_ignore("enum_variable_without_default") var test_var_hard_my_enum: MyEnum var test_var_hard_array: Array var test_var_hard_array_int: Array[int] diff --git a/modules/gdscript/tests/scripts/runtime/features/object_iterators.gd b/modules/gdscript/tests/scripts/runtime/features/object_iterators.gd new file mode 100644 index 0000000000..6fe28c6f78 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/object_iterators.gd @@ -0,0 +1,49 @@ +class MyIterator: + var count: int + + func _init(p_count: int) -> void: + count = p_count + + func _iter_init(arg: Array) -> bool: + prints("_iter_init", arg) + arg[0] = 0 + return arg[0] < count + + func _iter_next(arg: Array) -> bool: + prints("_iter_next", arg) + arg[0] += 1 + return arg[0] < count + + func _iter_get(arg: Variant) -> Variant: + prints("_iter_get", arg) + return arg + +func test(): + var container := PackedDataContainer.new() + var _err := container.pack([{ + id = 123, + node_path = ^"/some/path", + data = PackedByteArray(), + }]) + + for ref: PackedDataContainerRef in container: + for key: String in ref: + print(key) + + print("===") + + for ref: Variant in container: + for key: String in ref: + print(key) + + print("===") + + var hard_custom := MyIterator.new(3) + for x in hard_custom: + print(x) + + print("===") + + var weak_custom: Variant = MyIterator.new(3) + for x in weak_custom: + print(x) diff --git a/modules/gdscript/tests/scripts/runtime/features/object_iterators.out b/modules/gdscript/tests/scripts/runtime/features/object_iterators.out new file mode 100644 index 0000000000..942a2c9dd8 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/object_iterators.out @@ -0,0 +1,30 @@ +GDTEST_OK +id +node_path +data +=== +id +node_path +data +=== +_iter_init [<null>] +_iter_get 0 +0 +_iter_next [0] +_iter_get 1 +1 +_iter_next [1] +_iter_get 2 +2 +_iter_next [2] +=== +_iter_init [<null>] +_iter_get 0 +0 +_iter_next [0] +_iter_get 1 +1 +_iter_next [1] +_iter_get 2 +2 +_iter_next [2] diff --git a/modules/gdscript/tests/scripts/runtime/features/onready_base_before_subclass.gd b/modules/gdscript/tests/scripts/runtime/features/onready_base_before_subclass.gd new file mode 100644 index 0000000000..99156adb28 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/onready_base_before_subclass.gd @@ -0,0 +1,18 @@ +#GH-63329 +class A extends Node: + @onready var a := get_value("a") + + func get_value(var_name: String) -> String: + print(var_name) + return var_name + +class B extends A: + @onready var b := get_value("b") + + func _ready(): + pass + +func test(): + var node := B.new() + node._ready() + node.free() diff --git a/modules/gdscript/tests/scripts/runtime/features/onready_base_before_subclass.out b/modules/gdscript/tests/scripts/runtime/features/onready_base_before_subclass.out new file mode 100644 index 0000000000..b417ce67ca --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/onready_base_before_subclass.out @@ -0,0 +1,3 @@ +GDTEST_OK +a +b diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd b/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd index c45f8dce48..2bd5362f2a 100644 --- a/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd +++ b/modules/gdscript/tests/scripts/runtime/features/reset_unassigned_variables_in_loops.gd @@ -7,6 +7,7 @@ func test(): var b if true: var c + @warning_ignore("unassigned_variable") prints("Begin:", i, a, b, c) a = 1 b = 1 @@ -20,6 +21,7 @@ func test(): var b if true: var c + @warning_ignore("unassigned_variable") prints("Begin:", j, a, b, c) a = 1 b = 1 diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_uninit_local_vars.gd b/modules/gdscript/tests/scripts/runtime/features/reset_uninit_local_vars.gd new file mode 100644 index 0000000000..ef2d9a1d60 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/reset_uninit_local_vars.gd @@ -0,0 +1,21 @@ +# GH-89958 + +func test(): + if true: + @warning_ignore("unused_variable") + var a = 1 + @warning_ignore("unused_variable") + var b := 1 + @warning_ignore("unused_variable") + var c := 1 + + if true: + var a + @warning_ignore("unassigned_variable") + print(a) + var b + @warning_ignore("unassigned_variable") + print(b) + var c: Object + @warning_ignore("unassigned_variable") + print(c) diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_uninit_local_vars.out b/modules/gdscript/tests/scripts/runtime/features/reset_uninit_local_vars.out new file mode 100644 index 0000000000..279ea2d3b1 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/reset_uninit_local_vars.out @@ -0,0 +1,4 @@ +GDTEST_OK +<null> +<null> +<null> diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.gd b/modules/gdscript/tests/scripts/runtime/features/stringify.gd index 0dbb252b0e..8579baf876 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.gd +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.gd @@ -40,3 +40,4 @@ func test(): print(PackedVector2Array([Vector2.ONE, Vector2.ZERO])) print(PackedVector3Array([Vector3.ONE, Vector3.ZERO])) print(PackedColorArray([Color.RED, Color.BLUE, Color.GREEN])) + print(PackedVector4Array([Vector4.ONE, Vector4.ZERO])) diff --git a/modules/gdscript/tests/scripts/runtime/features/stringify.out b/modules/gdscript/tests/scripts/runtime/features/stringify.out index 1f33de00cc..7833b6e213 100644 --- a/modules/gdscript/tests/scripts/runtime/features/stringify.out +++ b/modules/gdscript/tests/scripts/runtime/features/stringify.out @@ -32,3 +32,4 @@ Node::[signal]property_list_changed [(1, 1), (0, 0)] [(1, 1, 1), (0, 0, 0)] [(1, 0, 0, 1), (0, 0, 1, 1), (0, 1, 0, 1)] +[(1, 1, 1, 1), (0, 0, 0, 0)] diff --git a/modules/gdscript/tests/scripts/runtime/features/type_casting.gd b/modules/gdscript/tests/scripts/runtime/features/type_casting.gd new file mode 100644 index 0000000000..c63ea16c32 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/type_casting.gd @@ -0,0 +1,24 @@ +func print_value(value: Variant) -> void: + if value is Object: + @warning_ignore("unsafe_method_access") + print("<%s>" % value.get_class()) + else: + print(var_to_str(value)) + +func test(): + var int_value := 1 + print_value(int_value as Variant) + print_value(int_value as int) + print_value(int_value as float) + + var node_value := Node.new() + print_value(node_value as Variant) + print_value(node_value as Object) + print_value(node_value as Node) + print_value(node_value as Node2D) + node_value.free() + + var null_value = null + print_value(null_value as Variant) + @warning_ignore("unsafe_cast") + print_value(null_value as Node) diff --git a/modules/gdscript/tests/scripts/runtime/features/type_casting.out b/modules/gdscript/tests/scripts/runtime/features/type_casting.out new file mode 100644 index 0000000000..7da5a4c0a4 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/type_casting.out @@ -0,0 +1,10 @@ +GDTEST_OK +1 +1 +1.0 +<Node> +<Node> +<Node> +null +null +null diff --git a/modules/gdscript/tests/test_completion.h b/modules/gdscript/tests/test_completion.h index ac9ffcd915..327446acee 100644 --- a/modules/gdscript/tests/test_completion.h +++ b/modules/gdscript/tests/test_completion.h @@ -33,6 +33,7 @@ #ifdef TOOLS_ENABLED +#include "core/config/project_settings.h" #include "core/io/config_file.h" #include "core/io/dir_access.h" #include "core/io/file_access.h" @@ -111,7 +112,10 @@ static void test_directory(const String &p_dir) { // For ease of reading ➡ (0x27A1) acts as sentinel char instead of 0xFFFF in the files. code = code.replace_first(String::chr(0x27A1), String::chr(0xFFFF)); // Require pointer sentinel char in scripts. - CHECK(code.find_char(0xFFFF) != -1); + int location = code.find_char(0xFFFF); + CHECK(location != -1); + + String res_path = ProjectSettings::get_singleton()->localize_path(path.path_join(next)); ConfigFile conf; if (conf.load(path.path_join(next.get_basename() + ".cfg")) != OK) { @@ -137,20 +141,46 @@ static void test_directory(const String &p_dir) { String call_hint; bool forced; - Node *owner = nullptr; + Node *scene = nullptr; if (conf.has_section_key("input", "scene")) { - Ref<PackedScene> scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP); - if (scene.is_valid()) { - owner = scene->instantiate(); + Ref<PackedScene> packed_scene = ResourceLoader::load(conf.get_value("input", "scene"), "PackedScene", ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP); + if (packed_scene.is_valid()) { + scene = packed_scene->instantiate(); } } else if (dir->file_exists(next.get_basename() + ".tscn")) { - Ref<PackedScene> scene = ResourceLoader::load(path.path_join(next.get_basename() + ".tscn"), "PackedScene"); - if (scene.is_valid()) { - owner = scene->instantiate(); + Ref<PackedScene> packed_scene = ResourceLoader::load(path.path_join(next.get_basename() + ".tscn"), "PackedScene"); + if (packed_scene.is_valid()) { + scene = packed_scene->instantiate(); + } + } + Node *owner = nullptr; + if (scene != nullptr) { + owner = scene->get_node(conf.get_value("input", "node_path", ".")); + } + + if (owner != nullptr) { + // Remove the line which contains the sentinel char, to get a valid script. + Ref<GDScript> scr; + scr.instantiate(); + int start = location; + int end = location; + for (; start >= 0; --start) { + if (code.get(start) == '\n') { + break; + } + } + for (; end < code.size(); ++end) { + if (code.get(end) == '\n') { + break; + } } + scr->set_source_code(code.erase(start, end - start)); + scr->reload(); + scr->set_path(res_path); + owner->set_script(scr); } - GDScriptLanguage::get_singleton()->complete_code(code, path.path_join(next), owner, &options, forced, call_hint); + GDScriptLanguage::get_singleton()->complete_code(code, res_path, owner, &options, forced, call_hint); String contains_excluded; for (ScriptLanguage::CodeCompletionOption &option : options) { for (const Dictionary &E : exclude) { @@ -179,8 +209,8 @@ static void test_directory(const String &p_dir) { CHECK(expected_call_hint == call_hint); CHECK(expected_forced == forced); - if (owner) { - memdelete(owner); + if (scene) { + memdelete(scene); } } next = dir->get_next(); |