Skip to content

Commit

Permalink
Merge pull request #48029 from Calinou/gdscript-add-integration-tests
Browse files Browse the repository at this point in the history
Add dozens of new integration tests to the GDScript test suite
  • Loading branch information
akien-mga authored Sep 15, 2021
2 parents d169087 + c0083c0 commit 32f8f74
Show file tree
Hide file tree
Showing 190 changed files with 1,788 additions and 17 deletions.
3 changes: 3 additions & 0 deletions misc/scripts/file_format.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Error here.
print(2.2 << 4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands to operator <<, float and int.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Error here.
print(2 << 4.4)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands to operator <<, int and float.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const CONSTANT = 25


func test():
CONSTANT(123)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Member "CONSTANT" is not a function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Size {
# Error here. Enum values must be integers.
S = 0.0,
}

func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Enum values must be integers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
enum Size {
# Error here. Enum values must be integers.
S = "hello",
}

func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Enum values must be integers.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
func function():
pass


func test():
function = 25
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a new value to a constant.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Error here. Array indices must be integers.
print([0, 1][true])
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid index type "bool" for a base of type "Array".
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
print(true + true)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands to operator +, bool and bool.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
print({"hello": "world"} + {"godot": "engine"})
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands "Dictionary" and "Dictionary" for "+" operator.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
print("hello" + ["world"])
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Invalid operands "String" and "Array" for "+" operator.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Assigned value for constant "TEST" isn't a constant expression.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Number separators may not be placed at the beginning of a number.
var __ = _123
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Identifier "_123" not declared in the current scope.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
func args(a, b):
print(a)
print(b)

func test():
args(1,)
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
var property = 25

func test():
property()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Member "property" is not a function.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a new value to a constant.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func test():
const TEST = 25

# Error here (can't assign a new value to a constant).
TEST = 50
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Cannot assign a new value to a constant.
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_ANALYZER_ERROR
Function "say()" not found in base RefCounted.
16 changes: 16 additions & 0 deletions modules/gdscript/tests/scripts/analyzer/features/as.gd
Original file line number Diff line number Diff line change
@@ -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))
8 changes: 8 additions & 0 deletions modules/gdscript/tests/scripts/analyzer/features/as.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
GDTEST_OK
1
2
3

1
2
3
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Arrays with consecutive commas are not allowed.
var array = ["arrays",,,,]
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected expression as array element.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
var hello == "world"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected end of statement after variable declaration, found "==" instead.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
var hello === "world"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected end of statement after variable declaration, found "==" instead.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
func test():
# Error here.
if foo = 25:
print(foo)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Assignment is not allowed inside an expression.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
var hello = "world" = "test"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Assignment is not allowed inside an expression.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
func test():
# Error here.
if var foo = 25:
print(foo)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected conditional expression after "if".
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
var = "world"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
"class_name" should be used before annotations.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
var TEST = 50
const TEST = 25
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a variable named "TEST" declared in this scope.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
func hello(arg1):
print(arg1)


func test():
# Error here.
hello(arg1 = 25)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Assignment is not allowed inside an expression.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const test = 25


func test():
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Function "test" has the same name as a previously declared constant.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Variable "test" has the same name as a previously declared function.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Error here.
var 23test = "is not a valid identifier"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Error here.
var "yes" = "is not a valid identifier"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
func test():
var a = ("missing paren ->"
var a = ("missing paren ->"
4 changes: 2 additions & 2 deletions modules/gdscript/tests/scripts/parser/errors/missing_colon.gd
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
func test():
if true # Missing colon here.
print("true")
if true # Missing colon here.
print("true")
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
func args(a, b):
print(a)
print(b)
print(a)
print(b)

func test():
args(1,2
args(1,2
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
# Number separators may not be placed right next to each other.
var __ = 1__23
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Only one underscore can be used as a numeric separator.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extends Node


func test():
var a = $ # Expected some node path.
var a = $ # Expected some node path.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
func test():
var while = "it's been a while"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Expected variable name after "var".
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
func test():
const TEST = 25

# Error here (can't redeclare a constant on the same scope).
const TEST = 50
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a constant named "TEST" declared in this scope.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
func test():
const TEST = 25
var TEST = 50
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
There is already a constant named "TEST" declared in this scope.
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GDTEST_PARSER_ERROR
Function "test" has the same name as a previously declared variable.
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
extends Node


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


func test():
$MyNode/23 # Can't use number here.
$MyNode/23 # Can't use number here.
16 changes: 16 additions & 0 deletions modules/gdscript/tests/scripts/parser/features/array.gd
Original file line number Diff line number Diff line change
@@ -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])
Loading

0 comments on commit 32f8f74

Please sign in to comment.