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.cpp16
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.gd5
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.out2
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.gd9
-rw-r--r--modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out2
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.gd5
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.out2
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.gd6
-rw-r--r--modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.out2
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_constructor.gd13
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_constructor.out4
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_variables.gd56
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_variables.out16
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd10
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_variables_load.out2
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd11
-rw-r--r--modules/gdscript/tests/scripts/runtime/features/static_variables_other.out2
17 files changed, 155 insertions, 8 deletions
diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp
index 6299e5d584..b8448d16c2 100644
--- a/modules/gdscript/tests/gdscript_test_runner.cpp
+++ b/modules/gdscript/tests/gdscript_test_runner.cpp
@@ -566,6 +566,14 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
ERR_FAIL_V_MSG(result, "\nCould not find test function on: '" + source_file + "'");
}
+ // Setup output handlers.
+ ErrorHandlerData error_data(&result, this);
+
+ _print_handler.userdata = &result;
+ _error_handler.userdata = &error_data;
+ add_print_handler(&_print_handler);
+ add_error_handler(&_error_handler);
+
script->reload();
// Create object instance for test.
@@ -577,14 +585,6 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {
obj->set_script(script);
GDScriptInstance *instance = static_cast<GDScriptInstance *>(obj->get_script_instance());
- // Setup output handlers.
- ErrorHandlerData error_data(&result, this);
-
- _print_handler.userdata = &result;
- _error_handler.userdata = &error_data;
- add_print_handler(&_print_handler);
- add_error_handler(&_error_handler);
-
// Call test function.
Callable::CallError call_err;
instance->callp(GDScriptTestRunner::test_function_name, nullptr, 0, call_err);
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.gd
new file mode 100644
index 0000000000..3dac751ba9
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.gd
@@ -0,0 +1,5 @@
+static func _static_init() -> int:
+ print("static init")
+
+func test():
+ print("done")
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.out b/modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.out
new file mode 100644
index 0000000000..42294b7afb
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_constructor_with_return_type.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Static constructor cannot have an explicit return type.
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.gd b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.gd
new file mode 100644
index 0000000000..1ae814ea34
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.gd
@@ -0,0 +1,9 @@
+@static_unload
+
+func non_static():
+ return "non static"
+
+static var static_var = non_static()
+
+func test():
+ print("does not run")
diff --git a/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out
new file mode 100644
index 0000000000..f1e9ec34f2
--- /dev/null
+++ b/modules/gdscript/tests/scripts/analyzer/errors/static_var_init_non_static_call.out
@@ -0,0 +1,2 @@
+GDTEST_ANALYZER_ERROR
+Cannot call non-static function "non_static()" for static variable initializer.
diff --git a/modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.gd b/modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.gd
new file mode 100644
index 0000000000..cbfa1f314f
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.gd
@@ -0,0 +1,5 @@
+func _static_init():
+ print("static init")
+
+func test():
+ print("done")
diff --git a/modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.out b/modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.out
new file mode 100644
index 0000000000..b2b8711e96
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/static_constructor_not_static.out
@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Static constructor must be declared static.
diff --git a/modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.gd b/modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.gd
new file mode 100644
index 0000000000..711243f822
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.gd
@@ -0,0 +1,6 @@
+static func _static_init():
+ print("static init")
+ return true
+
+func test():
+ print("done")
diff --git a/modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.out b/modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.out
new file mode 100644
index 0000000000..a034850e86
--- /dev/null
+++ b/modules/gdscript/tests/scripts/parser/errors/static_constructor_returning_something.out
@@ -0,0 +1,2 @@
+GDTEST_PARSER_ERROR
+Constructor cannot return a value.
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_constructor.gd b/modules/gdscript/tests/scripts/runtime/features/static_constructor.gd
new file mode 100644
index 0000000000..e08f77df12
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_constructor.gd
@@ -0,0 +1,13 @@
+@static_unload
+
+static var foo = "bar"
+
+static func _static_init():
+ print("static init called")
+ prints("foo is", foo)
+
+func test():
+ var _lambda = func _static_init():
+ print("lambda does not conflict with static constructor")
+
+ print("done")
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_constructor.out b/modules/gdscript/tests/scripts/runtime/features/static_constructor.out
new file mode 100644
index 0000000000..7f72a0ac2c
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_constructor.out
@@ -0,0 +1,4 @@
+GDTEST_OK
+static init called
+foo is bar
+done
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd
new file mode 100644
index 0000000000..e193312381
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.gd
@@ -0,0 +1,56 @@
+@static_unload
+
+static var perm := 0
+
+static var prop := "Hello!":
+ get: return prop + " suffix"
+ set(value): prop = "prefix " + str(value)
+
+static func get_data():
+ return "data"
+
+static var data = get_data()
+
+class Inner:
+ static var prop := "inner"
+ static func _static_init() -> void:
+ prints("Inner._static_init", prop)
+
+ class InnerInner:
+ static var prop := "inner inner"
+ static func _static_init() -> void:
+ prints("InnerInner._static_init", prop)
+
+func test():
+ prints("data:", data)
+
+ prints("perm:", perm)
+ prints("prop:", prop)
+
+ perm = 1
+ prop = "World!"
+
+ prints("perm:", perm)
+ prints("prop:", prop)
+
+ print("other.perm:", StaticVariablesOther.perm)
+ print("other.prop:", StaticVariablesOther.prop)
+
+ StaticVariablesOther.perm = 2
+ StaticVariablesOther.prop = "foo"
+
+ print("other.perm:", StaticVariablesOther.perm)
+ print("other.prop:", StaticVariablesOther.prop)
+
+ @warning_ignore("unsafe_method_access")
+ var path = get_script().get_path().get_base_dir()
+ var other = load(path + "/static_variables_load.gd")
+
+ print("load.perm:", other.perm)
+ print("load.prop:", other.prop)
+
+ other.perm = 3
+ other.prop = "bar"
+
+ print("load.perm:", other.perm)
+ print("load.prop:", other.prop)
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables.out b/modules/gdscript/tests/scripts/runtime/features/static_variables.out
new file mode 100644
index 0000000000..d2491aef5e
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_variables.out
@@ -0,0 +1,16 @@
+GDTEST_OK
+Inner._static_init inner
+InnerInner._static_init inner inner
+data: data
+perm: 0
+prop: prefix Hello! suffix
+perm: 1
+prop: prefix World! suffix
+other.perm:0
+other.prop:prefix Hello! suffix
+other.perm:2
+other.prop:prefix foo suffix
+load.perm:0
+load.prop:prefix Hello! suffix
+load.perm:3
+load.prop:prefix bar suffix
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd
new file mode 100644
index 0000000000..8913b02756
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.gd
@@ -0,0 +1,10 @@
+@static_unload
+
+static var perm := 0
+
+static var prop := "Hello!":
+ get: return prop + " suffix"
+ set(value): prop = "prefix " + str(value)
+
+func test():
+ print("ok")
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_load.out b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.out
new file mode 100644
index 0000000000..1b47ed10dc
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_load.out
@@ -0,0 +1,2 @@
+GDTEST_OK
+ok
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd
new file mode 100644
index 0000000000..7a3b0acca6
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.gd
@@ -0,0 +1,11 @@
+@static_unload
+class_name StaticVariablesOther
+
+static var perm := 0
+
+static var prop := "Hello!":
+ get: return prop + " suffix"
+ set(value): prop = "prefix " + str(value)
+
+func test():
+ print("ok")
diff --git a/modules/gdscript/tests/scripts/runtime/features/static_variables_other.out b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.out
new file mode 100644
index 0000000000..1b47ed10dc
--- /dev/null
+++ b/modules/gdscript/tests/scripts/runtime/features/static_variables_other.out
@@ -0,0 +1,2 @@
+GDTEST_OK
+ok