Add dozens of new integration tests to the GDScript test suite

This also ignores `.out` files in the file format static checks.
This commit is contained in:
Hugo Locurcio 2021-04-19 20:50:52 +02:00
parent a9b600bac0
commit c0083c0f90
No known key found for this signature in database
GPG Key ID: 39E8F8BE30B0A49C
190 changed files with 1788 additions and 17 deletions

View File

@ -20,6 +20,9 @@ while IFS= read -rd '' f; do
continue
elif [[ "$f" == *"sln" ]]; then
continue
elif [[ "$f" == *".out" ]]; then
# GDScript integration testing files.
continue
elif [[ "$f" == *"patch" ]]; then
continue
elif [[ "$f" == *"pot" ]]; then

View File

@ -0,0 +1,3 @@
func test():
# Error here.
print(2.2 << 4)

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands to operator <<, float and int.

View File

@ -0,0 +1,3 @@
func test():
# Error here.
print(2 << 4.4)

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands to operator <<, int and float.

View File

@ -0,0 +1,5 @@
const CONSTANT = 25
func test():
CONSTANT(123)

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Member "CONSTANT" is not a function.

View File

@ -0,0 +1,7 @@
enum Size {
# Error here. Enum values must be integers.
S = 0.0,
}
func test():
pass

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Enum values must be integers.

View File

@ -0,0 +1,7 @@
enum Size {
# Error here. Enum values must be integers.
S = "hello",
}
func test():
pass

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Enum values must be integers.

View File

@ -0,0 +1,6 @@
func function():
pass
func test():
function = 25

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a new value to a constant.

View File

@ -0,0 +1,3 @@
func test():
# Error here. Array indices must be integers.
print([0, 1][true])

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid index type "bool" for a base of type "Array".

View File

@ -0,0 +1,2 @@
func test():
print(true + true)

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands to operator +, bool and bool.

View File

@ -0,0 +1,2 @@
func test():
print({"hello": "world"} + {"godot": "engine"})

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands "Dictionary" and "Dictionary" for "+" operator.

View File

@ -0,0 +1,2 @@
func test():
print("hello" + ["world"])

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands "String" and "Array" for "+" operator.

View File

@ -0,0 +1,5 @@
func test():
var i = 12
# Constants must be made of a constant, deterministic expression.
# A constant that depends on a variable's value is not a constant expression.
const TEST = 13 + i

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Assigned value for constant "TEST" isn't a constant expression.

View File

@ -0,0 +1,3 @@
func test():
# Number separators may not be placed at the beginning of a number.
var __ = _123

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Identifier "_123" not declared in the current scope.

View File

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

View File

@ -0,0 +1,4 @@
var property = 25
func test():
property()

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Member "property" is not a function.

View File

@ -0,0 +1,7 @@
# See also `parser-warnings/shadowed-constant.gd`.
const TEST = 25
func test():
# Error here (trying to set a new value to a constant).
TEST = 50

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a new value to a constant.

View File

@ -0,0 +1,5 @@
func test():
const TEST = 25
# Error here (can't assign a new value to a constant).
TEST = 50

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a new value to a constant.

View File

@ -0,0 +1,11 @@
# `class` extends RefCounted by default.
class Say:
func say():
super()
print("say something")
func test():
# RefCounted doesn't have a `say()` method, so the `super()` call in the method
# definition will cause a run-time error.
Say.new().say()

View File

@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Function "say()" not found in base RefCounted.

View File

@ -0,0 +1,16 @@
func test():
var some_bool = 5 as bool
var some_int = 5 as int
var some_float = 5 as float
print(typeof(some_bool))
print(typeof(some_int))
print(typeof(some_float))
print()
var some_bool_typed := 5 as bool
var some_int_typed := 5 as int
var some_float_typed := 5 as float
print(typeof(some_bool_typed))
print(typeof(some_int_typed))
print(typeof(some_float_typed))

View File

@ -0,0 +1,8 @@
GDTEST_OK
1
2
3
1
2
3

View File

@ -0,0 +1,3 @@
func test():
# Arrays with consecutive commas are not allowed.
var array = ["arrays",,,,]

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected expression as array element.

View File

@ -0,0 +1,2 @@
func test():
var hello == "world"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected end of statement after variable declaration, found "==" instead.

View File

@ -0,0 +1,2 @@
func test():
var hello === "world"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected end of statement after variable declaration, found "==" instead.

View File

@ -0,0 +1,4 @@
func test():
# Error here.
if foo = 25:
print(foo)

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Assignment is not allowed inside an expression.

View File

@ -0,0 +1,2 @@
func test():
var hello = "world" = "test"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Assignment is not allowed inside an expression.

View File

@ -0,0 +1,4 @@
func test():
# Error here.
if var foo = 25:
print(foo)

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected conditional expression after "if".

View File

@ -0,0 +1,2 @@
func test():
var = "world"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".

View File

@ -0,0 +1,6 @@
# Error here. `class_name` should be used *before* annotations, not after.
@icon("res://path/to/optional/icon.svg")
class_name HelloWorld
func test():
pass

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
"class_name" should be used before annotations.

View File

@ -0,0 +1,3 @@
func test():
var TEST = 50
const TEST = 25

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a variable named "TEST" declared in this scope.

View File

@ -0,0 +1,7 @@
func hello(arg1):
print(arg1)
func test():
# Error here.
hello(arg1 = 25)

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Assignment is not allowed inside an expression.

View File

@ -0,0 +1,5 @@
const test = 25
func test():
pass

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Function "test" has the same name as a previously declared constant.

View File

@ -0,0 +1,7 @@
func test():
pass
# Error here. The difference with `variable-conflicts-function.gd` is that here,
# the function is defined *before* the variable.
var test = 25

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Variable "test" has the same name as a previously declared function.

View File

@ -0,0 +1,3 @@
func test():
# Error here.
var 23test = "is not a valid identifier"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".

View File

@ -0,0 +1,3 @@
func test():
# Error here.
var "yes" = "is not a valid identifier"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,3 @@
func test():
# Number separators may not be placed right next to each other.
var __ = 1__23

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Only one underscore can be used as a numeric separator.

View File

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

View File

@ -0,0 +1,2 @@
func test():
var while = "it's been a while"

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".

View File

@ -0,0 +1,5 @@
func test():
const TEST = 25
# Error here (can't redeclare a constant on the same scope).
const TEST = 50

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a constant named "TEST" declared in this scope.

View File

@ -0,0 +1,3 @@
func test():
const TEST = 25
var TEST = 50

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a constant named "TEST" declared in this scope.

View File

@ -0,0 +1,6 @@
var test = 25
# Error here. The difference with `variable-conflicts-function.gd` is that here,
# the function is defined *before* the variable.
func test():
pass

View File

@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Function "test" has the same name as a previously declared variable.

View File

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

View File

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

View File

@ -0,0 +1,16 @@
func test():
# Indexing from the beginning:
print([1, 2, 3][0])
print([1, 2, 3][1])
print([1, 2, 3][2])
# Indexing from the end:
print([1, 2, 3][-1])
print([1, 2, 3][-2])
print([1, 2, 3][-3])
# Float indices are currently allowed, but should probably be an error?
print([1, 2, 3][0.4])
print([1, 2, 3][0.8])
print([1, 2, 3][1.0])
print([1, 2, 3][-1.0])

View File

@ -0,0 +1,11 @@
GDTEST_OK
1
2
3
3
2
1
1
1
2
3

View File

@ -0,0 +1,50 @@
enum Flags {
FIRE = 1 << 1,
ICE = 1 << 2,
SLIPPERY = 1 << 3,
STICKY = 1 << 4,
NONSOLID = 1 << 5,
ALL = FIRE | ICE | SLIPPERY | STICKY | NONSOLID,
}
func test():
var flags = Flags.FIRE | Flags.SLIPPERY
print(flags)
flags = Flags.FIRE & Flags.SLIPPERY
print(flags)
flags = Flags.FIRE ^ Flags.SLIPPERY
print(flags)
flags = Flags.ALL & (Flags.FIRE | Flags.ICE)
print(flags)
flags = (Flags.ALL & Flags.FIRE) | Flags.ICE
print(flags)
flags = Flags.ALL & Flags.FIRE | Flags.ICE
print(flags)
# Enum value must be casted to an integer. Otherwise, a parser error is emitted.
flags &= int(Flags.ICE)
print(flags)
flags ^= int(Flags.ICE)
print(flags)
flags |= int(Flags.STICKY | Flags.SLIPPERY)
print(flags)
print()
var num = 2 << 4
print(num)
num <<= 2
print(num)
num >>= 2
print(num)

View File

@ -0,0 +1,14 @@
GDTEST_OK
10
0
10
6
6
6
4
0
24
32
128
32

View File

@ -0,0 +1,25 @@
# Test non-nested/slightly nested class architecture.
class Test:
var number = 25
var string = "hello"
class TestSub extends Test:
var other_string = "bye"
class TestConstructor:
func _init(argument = 10):
print(str("constructor with argument ", argument))
func test():
var test_instance = Test.new()
test_instance.number = 42
var test_sub = TestSub.new()
assert(test_sub.number == 25) # From Test.
assert(test_sub.other_string == "bye") # From TestSub.
TestConstructor.new()
TestConstructor.new(500)

View File

@ -0,0 +1,3 @@
GDTEST_OK
constructor with argument 10
constructor with argument 500

View File

@ -0,0 +1,33 @@
# Test deeply nested class architectures.
class Test:
var depth = 1
class Nested:
var depth_nested = 10
class Test2 extends Test:
var depth2 = 2
class Test3 extends Test2:
var depth3 = 3
class Test4 extends Test3:
var depth4 = 4
class Nested2:
var depth4_nested = 100
func test():
print(Test.new().depth)
print(Test2.new().depth)
print(Test2.new().depth2)
print(Test3.new().depth)
print(Test3.new().depth3)
print(Test4.new().depth)
print(Test4.new().depth4)
print(Test.Nested.new().depth_nested)
print(Test4.Nested2.new().depth4_nested)

View File

@ -0,0 +1,10 @@
GDTEST_OK
1
1
2
1
3
1
4
10
100

View File

@ -0,0 +1,5 @@
class_name HelloWorld
@icon("res://path/to/optional/icon.svg")
func test():
pass

View File

@ -0,0 +1 @@
GDTEST_OK

View File

@ -0,0 +1,4 @@
func test():
print(20 + 20)
print("hello" + "world")
print([1, 2] + [3, 4])

View File

@ -0,0 +1,4 @@
GDTEST_OK
40
helloworld
[1, 2, 3, 4]

View File

@ -0,0 +1,11 @@
func test():
const _TEST = 12 + 34 - 56 * 78
const _STRING = "yes"
const _VECTOR = Vector2(5, 6)
const _ARRAY = []
const _DICTIONARY = {"this": "dictionary"}
# Create user constants from built-in constants.
const _HELLO = PI + TAU
const _INFINITY = INF
const _NOT_A_NUMBER = NAN

View File

@ -0,0 +1,33 @@
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'

View File

@ -0,0 +1,37 @@
func test():
# Non-string keys are valid.
print({ 12: "world" }[12])
var contents = {
0: "zero",
0.0: "zero point zero",
null: "null",
false: "false",
[]: "empty array",
Vector2i(): "zero Vector2i",
15: {
22: {
4: ["nesting", "arrays"],
},
},
}
print(contents[0.0])
# Making sure declaration order doesn't affect things...
print({ 0.0: "zero point zero", 0: "zero", null: "null", false: "false", []: "empty array" }[0])
print({ 0.0: "zero point zero", 0: "zero", null: "null", false: "false", []: "empty array" }[0.0])
print(contents[null])
print(contents[false])
print(contents[[]])
print(contents[Vector2i()])
print(contents[15])
print(contents[15][22])
print(contents[15][22][4])
print(contents[15][22][4][0])
print(contents[15][22][4][1])
# Currently fails with "invalid get index 'hello' on base Dictionary".
# Both syntaxes are valid however.
#print({ "hello": "world" }["hello"])
#print({ "hello": "world" }.hello)

View File

@ -0,0 +1,14 @@
GDTEST_OK
world
zero point zero
zero
zero point zero
null
false
empty array
zero Vector2i
{22:{4:[nesting, arrays]}}
{4:[nesting, arrays]}
[nesting, arrays]
nesting
arrays

View File

@ -0,0 +1,12 @@
func test():
# Mixing Python-style and Lua-style syntax in the same dictionary declaration
# is allowed.
var dict = {
"hello": {
world = {
"is": "beautiful",
},
},
}
print(dict)

View File

@ -0,0 +1,2 @@
GDTEST_OK
{hello:{world:{is:beautiful}}}

Some files were not shown because too many files have changed in this diff Show More