Add runner for GDScript testing
This is meant for testing the GDScript implementation, not for testing user scripts nor testing the engine using scripts. Tests consists in a GDScript file and a .out file with the expected output. The .out file format is: expected status (based on the enum GDScriptTest::TestStatus) on the first line, followed by either an error message or the resulting output. Warnings are added after the first line, before the output (or compiler errors) if the parser pass without any error. The test script must have a function called `test()` which takes no argument. Such function will be called by the test runner. The test should not have any dependency unless it's part of the test too. Global classes (using `class_name`) are registered before the runner starts, so those should work if needed. Use the command `godot --gdscript-generate-tests godot-source/modules/gdscript/tests/scripts` to update the .out files with the current output (make sure the output are the expected values before committing). The tests themselves are part of the doctest suite so those can be executed with `godot --test`. Co-authored-by: Andrii Doroshenko (Xrayez) <xrayez@gmail.com>
This commit is contained in:
parent
47aef8e8dc
commit
5f77f38573
33 changed files with 882 additions and 78 deletions
2
modules/gdscript/tests/scripts/.gitignore
vendored
Normal file
2
modules/gdscript/tests/scripts/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
# Ignore metadata if someone open this on Godot.
|
||||
/.godot
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
func args(a, b):
|
||||
print(a)
|
||||
print(b)
|
||||
|
||||
func test():
|
||||
args(1,)
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_ANALYZER_ERROR
|
||||
Too few arguments for "args()" call. Expected at least 2 but received 1.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
func test():
|
||||
var a = ("missing paren ->"
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Expected closing ")" after grouping expression.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
func test():
|
||||
if true # Missing colon here.
|
||||
print("true")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Expected ":" after "if" condition.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
func args(a, b):
|
||||
print(a)
|
||||
print(b)
|
||||
|
||||
func test():
|
||||
args(1,2
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Expected closing ")" after call arguments.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
func test():
|
||||
print("Using spaces")
|
||||
print("Using tabs")
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Used "\t" for indentation instead " " as used before in the file.
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
extends Node
|
||||
func test():
|
||||
var a = $ # Expected some node path.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Expect node path as string or identifier after "$".
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
extends Node
|
||||
func test():
|
||||
$MyNode/23 # Can't use number here.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Expect node path after "/".
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
extends Node
|
||||
func test():
|
||||
$23 # Can't use number here.
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_PARSER_ERROR
|
||||
Expect node path as string or identifier after "$".
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
func test():
|
||||
print("A"); print("B")
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
GDTEST_OK
|
||||
A
|
||||
B
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
# See https://github.com/godotengine/godot/issues/41066.
|
||||
|
||||
func f(p, ): ## <-- no errors
|
||||
print(p)
|
||||
|
||||
func test():
|
||||
f(0, ) ## <-- no error
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
GDTEST_OK
|
||||
0
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
var a # No init.
|
||||
var b = 42 # Init.
|
||||
|
||||
func test():
|
||||
var c # No init, local.
|
||||
var d = 23 # Init, local.
|
||||
|
||||
a = 1
|
||||
c = 2
|
||||
|
||||
prints(a, b, c, d)
|
||||
print("OK")
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 5
|
||||
>> UNASSIGNED_VARIABLE
|
||||
>> The variable 'c' was used but never assigned a value.
|
||||
1 42 2 23
|
||||
OK
|
||||
|
|
@ -0,0 +1,2 @@
|
|||
func test():
|
||||
var unused = "not used"
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
GDTEST_OK
|
||||
>> WARNING
|
||||
>> Line: 2
|
||||
>> UNUSED_VARIABLE
|
||||
>> The local variable 'unused' is declared but never used in the block. If this is intended, prefix it with an underscore: '_unused'
|
||||
10
modules/gdscript/tests/scripts/project.godot
Normal file
10
modules/gdscript/tests/scripts/project.godot
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
; This is not an actual project.
|
||||
; This config only exists to properly set up the test environment.
|
||||
; It also helps for opening Godot to edit the scripts, but please don't
|
||||
; let the editor changes be saved.
|
||||
|
||||
config_version=4
|
||||
|
||||
[application]
|
||||
|
||||
config/name="GDScript Integration Test Suite"
|
||||
Loading…
Add table
Add a link
Reference in a new issue