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:
George Marques 2021-04-07 10:12:51 -03:00
parent 47aef8e8dc
commit 5f77f38573
No known key found for this signature in database
GPG key ID: 046BD46A3201E43D
33 changed files with 882 additions and 78 deletions

View file

@ -0,0 +1,2 @@
# Ignore metadata if someone open this on Godot.
/.godot

View file

@ -0,0 +1,6 @@
func args(a, b):
print(a)
print(b)
func test():
args(1,)

View file

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Too few arguments for "args()" call. Expected at least 2 but received 1.

View file

@ -0,0 +1,2 @@
func test():
var a = ("missing paren ->"

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected closing ")" after grouping expression.

View file

@ -0,0 +1,3 @@
func test():
if true # Missing colon here.
print("true")

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected ":" after "if" condition.

View file

@ -0,0 +1,6 @@
func args(a, b):
print(a)
print(b)
func test():
args(1,2

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected closing ")" after call arguments.

View file

@ -0,0 +1,3 @@
func test():
print("Using spaces")
print("Using tabs")

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Used "\t" for indentation instead " " as used before in the file.

View file

@ -0,0 +1,3 @@
extends Node
func test():
var a = $ # Expected some node path.

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expect node path as string or identifier after "$".

View file

@ -0,0 +1,3 @@
extends Node
func test():
$MyNode/23 # Can't use number here.

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expect node path after "/".

View file

@ -0,0 +1,3 @@
extends Node
func test():
$23 # Can't use number here.

View file

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expect node path as string or identifier after "$".

View file

@ -0,0 +1,2 @@
func test():
print("A"); print("B")

View file

@ -0,0 +1,3 @@
GDTEST_OK
A
B

View file

@ -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

View file

@ -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")

View file

@ -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

View file

@ -0,0 +1,2 @@
func test():
var unused = "not used"

View file

@ -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'

View 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"