summaryrefslogtreecommitdiffstats
path: root/modules/gdscript/tests
diff options
context:
space:
mode:
Diffstat (limited to 'modules/gdscript/tests')
-rw-r--r--modules/gdscript/tests/gdscript_test_runner.cpp2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_external.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser.gd17
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser.out3
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_base1.notest.gd1
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_base2.notest.gd2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script1.notest.gd12
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script1_base.notest.gd1
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script1c.notest.gd1
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script1d.notest.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script1e.notest.gd0
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script1f.notest.gd1
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script2.notest.gd6
-rw-r--r--modules/gdscript/tests/scripts/analyzer/features/external_parser_script3.notest.gd1
-rw-r--r--modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd9
-rw-r--r--modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out6
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.gd20
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.out1
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd11
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out1
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.gd62
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.out26
22 files changed, 186 insertions, 4 deletions
diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp
index fbfa4a0a79..025fcbd32a 100644
--- a/modules/gdscript/tests/gdscript_test_runner.cpp
+++ b/modules/gdscript/tests/gdscript_test_runner.cpp
@@ -622,7 +622,7 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
enable_stdout();
result.status = GDTEST_COMPILER_ERROR;
result.output = get_text_for_status(result.status) + "\n";
- result.output = compiler.get_error();
+ result.output += compiler.get_error() + "\n";
if (!p_is_generating) {
result.passed = check_output(result.output);
}
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_external.out b/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_external.out
index 64a6bd417d..878e827d04 100644
--- a/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_external.out
+++ b/modules/gdscript/tests/scripts/analyzer/errors/cyclic_ref_external.out
@@ -1,2 +1,2 @@
GDTEST_ANALYZER_ERROR
-Could not resolve member "v".
+Could not resolve external class member "v".
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser.gd
new file mode 100644
index 0000000000..ad265a7365
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser.gd
@@ -0,0 +1,17 @@
+extends "external_parser_base1.notest.gd"
+
+const External1 = preload("external_parser_script1.notest.gd")
+
+func baz(e1: External1) -> void:
+ print(e1.e1c.bar)
+ print(e1.baz)
+
+func test_external_base_parser_type_resolve(_v: TypeFromBase):
+ pass
+
+func test():
+ var ext := External1.new()
+ print(ext.array[0].test2)
+ print(ext.get_external2().get_external3().test3)
+ # TODO: This actually produces a runtime error, but we're testing the analyzer here
+ #baz(ext)
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser.out b/modules/gdscript/tests/scripts/analyzer/features/external_parser.out
new file mode 100644
index 0000000000..26c2527fbc
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser.out
@@ -0,0 +1,3 @@
+GDTEST_OK
+test2
+test3
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_base1.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_base1.notest.gd
new file mode 100644
index 0000000000..d27d8cef3b
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_base1.notest.gd
@@ -0,0 +1 @@
+extends "external_parser_base2.notest.gd"
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_base2.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_base2.notest.gd
new file mode 100644
index 0000000000..f8de818485
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_base2.notest.gd
@@ -0,0 +1,2 @@
+class TypeFromBase:
+ pass
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1.notest.gd
new file mode 100644
index 0000000000..e1221bb138
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1.notest.gd
@@ -0,0 +1,12 @@
+extends "external_parser_script1_base.notest.gd"
+
+const External2 = preload("external_parser_script2.notest.gd")
+const External1c = preload("external_parser_script1c.notest.gd")
+
+@export var e1c: External1c
+
+var array: Array[External2] = [ External2.new() ]
+var baz: int
+
+func get_external2() -> External2:
+ return External2.new()
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1_base.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1_base.notest.gd
new file mode 100644
index 0000000000..4249efa1f9
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1_base.notest.gd
@@ -0,0 +1 @@
+extends Resource
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1c.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1c.notest.gd
new file mode 100644
index 0000000000..34a48cba6f
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1c.notest.gd
@@ -0,0 +1 @@
+extends "external_parser_script1d.notest.gd"
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1d.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1d.notest.gd
new file mode 100644
index 0000000000..43bc6f3e53
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1d.notest.gd
@@ -0,0 +1,5 @@
+extends "external_parser_script1f.notest.gd"
+
+const External1e = preload("external_parser_script1e.notest.gd")
+
+var bar: Array[External1e]
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1e.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1e.notest.gd
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1e.notest.gd
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1f.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1f.notest.gd
new file mode 100644
index 0000000000..4249efa1f9
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script1f.notest.gd
@@ -0,0 +1 @@
+extends Resource
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script2.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script2.notest.gd
new file mode 100644
index 0000000000..885f813503
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script2.notest.gd
@@ -0,0 +1,6 @@
+const External3 = preload("external_parser_script3.notest.gd")
+
+var test2 := "test2"
+
+func get_external3() -> External3:
+ return External3.new()
diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_parser_script3.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script3.notest.gd
new file mode 100644
index 0000000000..3e62974256
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/features/external_parser_script3.notest.gd
@@ -0,0 +1 @@
+var test3 := "test3"
diff --git a/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd
new file mode 100644
index 0000000000..3724c8c713
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.gd
@@ -0,0 +1,9 @@
+# https://github.com/godotengine/godot/issues/90086
+
+class MyObj:
+ var obj: WeakRef
+
+func test():
+ var obj_1 = MyObj.new()
+ var obj_2 = MyObj.new()
+ obj_1.obj = obj_2
diff --git a/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out
new file mode 100644
index 0000000000..dfca5b1eca
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/errors/invalid_property_assignment.out
@@ -0,0 +1,6 @@
+GDTEST_RUNTIME_ERROR
+>> SCRIPT ERROR
+>> on function: test()
+>> runtime/errors/invalid_property_assignment.gd
+>> 9
+>> Invalid assignment of property or key 'obj' with value of type 'RefCounted (MyObj)' on a base object of type 'RefCounted (MyObj)'.
diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.gd b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.gd
index c774ebf83c..df639a7b4d 100644
--- a/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.gd
+++ b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.gd
@@ -1,6 +1,5 @@
# GH-77666
-
-func test():
+func test_exit_if():
var ref := RefCounted.new()
print(ref.get_reference_count())
@@ -8,3 +7,20 @@ func test():
var _temp := ref
print(ref.get_reference_count())
+
+# GH-94654
+func test_exit_while():
+ var slots_data := []
+
+ while true:
+ @warning_ignore("confusable_local_declaration")
+ var slot = 42
+ slots_data.append(slot)
+ break
+
+ var slot: int = slots_data[0]
+ print(slot)
+
+func test():
+ test_exit_if()
+ test_exit_while()
diff --git a/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.out b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.out
index 04b4638adf..164eb24963 100644
--- a/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.out
+++ b/modules/gdscript/tests/scripts/runtime/features/reset_local_var_on_exit_block.out
@@ -1,3 +1,4 @@
GDTEST_OK
1
1
+42
diff --git a/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd
new file mode 100644
index 0000000000..e1aba83507
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.gd
@@ -0,0 +1,11 @@
+# https://github.com/godotengine/godot/issues/90086
+
+class MyObj:
+ var obj : WeakRef
+
+func test():
+ var obj_1 = MyObj.new()
+ var obj_2 = MyObj.new()
+ assert(obj_2.get_reference_count() == 1)
+ obj_1.set(&"obj", obj_2)
+ assert(obj_2.get_reference_count() == 1)
diff --git a/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out
new file mode 100644
index 0000000000..d73c5eb7cd
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/set_does_not_leak.out
@@ -0,0 +1 @@
+GDTEST_OK
diff --git a/modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.gd b/modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.gd
new file mode 100644
index 0000000000..f70b521e1a
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.gd
@@ -0,0 +1,62 @@
+# GH-94667
+
+class Inner:
+ var subprop: Vector2:
+ set(value):
+ prints("subprop setter", value)
+ subprop = value
+ get:
+ print("subprop getter")
+ return subprop
+
+ func _to_string() -> String:
+ return "<Inner>"
+
+var prop1:
+ set(value):
+ prints("prop1 setter", value)
+ prop1 = value
+
+var prop2: Inner:
+ set(value):
+ prints("prop2 setter", value)
+ prop2 = value
+
+var prop3:
+ set(value):
+ prints("prop3 setter", value)
+ prop3 = value
+ get:
+ print("prop3 getter")
+ return prop3
+
+var prop4: Inner:
+ set(value):
+ prints("prop4 setter", value)
+ prop4 = value
+ get:
+ print("prop4 getter")
+ return prop4
+
+func test():
+ print("===")
+ prop1 = Vector2()
+ prop1.x = 1.0
+ print("---")
+ prop1 = Inner.new()
+ prop1.subprop.x = 1.0
+
+ print("===")
+ prop2 = Inner.new()
+ prop2.subprop.x = 1.0
+
+ print("===")
+ prop3 = Vector2()
+ prop3.x = 1.0
+ print("---")
+ prop3 = Inner.new()
+ prop3.subprop.x = 1.0
+
+ print("===")
+ prop4 = Inner.new()
+ prop4.subprop.x = 1.0
diff --git a/modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.out b/modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.out
new file mode 100644
index 0000000000..c51759f481
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/setter_chain_shared_types.out
@@ -0,0 +1,26 @@
+GDTEST_OK
+===
+prop1 setter (0, 0)
+prop1 setter (1, 0)
+---
+prop1 setter <Inner>
+subprop getter
+subprop setter (1, 0)
+===
+prop2 setter <Inner>
+subprop getter
+subprop setter (1, 0)
+===
+prop3 setter (0, 0)
+prop3 getter
+prop3 setter (1, 0)
+---
+prop3 setter <Inner>
+prop3 getter
+subprop getter
+subprop setter (1, 0)
+===
+prop4 setter <Inner>
+prop4 getter
+subprop getter
+subprop setter (1, 0)