1
0
mirror of https://github.com/godotengine/godot.git synced 2026-01-05 19:31:35 +00:00

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
190 changed files with 1788 additions and 17 deletions

View File

@@ -0,0 +1,5 @@
func test():
# These statements always evaluate to `true`, and therefore emit a warning.
assert(true)
assert(-1.234)
assert(2 + 3 == 5)

View File

@@ -0,0 +1,13 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> ASSERT_ALWAYS_TRUE
>> Assert statement is redundant because the expression is always true.
>> WARNING
>> Line: 4
>> ASSERT_ALWAYS_TRUE
>> Assert statement is redundant because the expression is always true.
>> WARNING
>> Line: 5
>> ASSERT_ALWAYS_TRUE
>> Assert statement is redundant because the expression is always true.

View File

@@ -0,0 +1,8 @@
func test():
# `and` should be used instead.
if true && true:
pass
# `or` should be used instead.
if false || true:
pass

View File

@@ -0,0 +1 @@
GDTEST_OK

View File

@@ -0,0 +1,8 @@
func test():
# The ternary operator below returns values of different types and the
# result is assigned to a typed variable. This will cause a run-time error
# if the branch with the incompatible type is picked. Here, it won't happen
# since the `false` condition never evaluates to `true`. Instead, a warning
# will be emitted.
var __: int = 25
__ = "hello" if false else -2

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 8
>> INCOMPATIBLE_TERNARY
>> Values of the ternary conditional are not mutually compatible.

View File

@@ -0,0 +1,10 @@
func test():
# This should emit a warning.
var __ = 5 / 2
# These should not emit warnings.
__ = float(5) / 2
__ = 5 / float(2)
__ = 5.0 / 2
__ = 5 / 2.0
__ = 5.0 / 2.0

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> INTEGER_DIVISION
>> Integer division, decimal part will be discarded.

View File

@@ -0,0 +1,9 @@
func test():
var i = 25
# The default branch (`_`) should be at the end of the `match` statement.
# Otherwise, a warning will be emitted
match i:
_:
print("default")
25:
print("is 25")

View File

@@ -0,0 +1,6 @@
GDTEST_OK
>> WARNING
>> Line: 8
>> UNREACHABLE_PATTERN
>> Unreachable pattern (pattern after wildcard or bind).
default

View File

@@ -0,0 +1,5 @@
func i_accept_ints_only(_i: int):
pass
func test():
i_accept_ints_only(12.345)

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 5
>> NARROWING_CONVERSION
>> Narrowing conversion (float is converted to int and loses precision).

View File

@@ -0,0 +1,6 @@
func i_return_int() -> int:
return 4
func test():
i_return_int()

View File

@@ -0,0 +1 @@
GDTEST_OK

View File

@@ -0,0 +1,8 @@
# See also `parser-errors/redefine-class-constant.gd`.
const TEST = 25
func test():
# Warning here. This is not an error because a new constant is created,
# rather than attempting to set the value of an existing constant.
const TEST = 50

View File

@@ -0,0 +1,9 @@
GDTEST_OK
>> WARNING
>> Line: 8
>> 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: 8
>> SHADOWED_VARIABLE
>> The local constant "TEST" is shadowing an already-declared constant at line 2.

View File

@@ -0,0 +1,8 @@
var foo = 123
func test():
# Notice the `var` keyword. Without this keyword, no warning would be emitted
# because no new variable would be created. Instead, the class variable's value
# would be overwritten.
var foo = 456

View File

@@ -0,0 +1,9 @@
GDTEST_OK
>> WARNING
>> Line: 8
>> UNUSED_VARIABLE
>> The local variable 'foo' is declared but never used in the block. If this is intended, prefix it with an underscore: '_foo'
>> WARNING
>> Line: 8
>> SHADOWED_VARIABLE
>> The local variable "foo" is shadowing an already-declared variable at line 1.

View File

@@ -0,0 +1,2 @@
func test():
var test = "This variable has the same name as the test() function."

View File

@@ -0,0 +1,9 @@
GDTEST_OK
>> WARNING
>> Line: 2
>> UNUSED_VARIABLE
>> The local variable 'test' is declared but never used in the block. If this is intended, prefix it with an underscore: '_test'
>> WARNING
>> Line: 2
>> SHADOWED_VARIABLE
>> The local variable "test" is shadowing an already-declared function at line 1.

View File

@@ -0,0 +1,9 @@
func test():
# The following statements should all be reported as standalone expressions:
"This is a standalone expression"
1234
0.0 + 0.0
Color(1, 1, 1)
Vector3.ZERO
[true, false]
float(125)

View File

@@ -0,0 +1,21 @@
GDTEST_OK
>> WARNING
>> Line: 3
>> STANDALONE_EXPRESSION
>> Standalone expression (the line has no effect).
>> WARNING
>> Line: 4
>> STANDALONE_EXPRESSION
>> Standalone expression (the line has no effect).
>> WARNING
>> Line: 5
>> STANDALONE_EXPRESSION
>> Standalone expression (the line has no effect).
>> WARNING
>> Line: 7
>> STANDALONE_EXPRESSION
>> Standalone expression (the line has no effect).
>> WARNING
>> Line: 8
>> STANDALONE_EXPRESSION
>> Standalone expression (the line has no effect).

View File

@@ -0,0 +1,2 @@
func test():
var __

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 2
>> UNASSIGNED_VARIABLE
>> The variable '__' was used but never assigned a value.

View File

@@ -0,0 +1,4 @@
func test():
var __: int
# Variable has no set value at this point (even though it's implicitly `0` here).
__ += 15

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 4
>> UNASSIGNED_VARIABLE_OP_ASSIGN
>> Using assignment with operation but the variable '__' was not previously assigned a value.

View File

@@ -0,0 +1,7 @@
func test():
var i = 25
return
# This will never be run due to the `return` statement above.
print(i)

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 7
>> UNREACHABLE_CODE
>> Unreachable code (statement after return) in function 'test()'.

View File

@@ -0,0 +1,12 @@
# This should emit a warning since the unused argument is not prefixed with an underscore.
func function_with_unused_argument(p_arg1, p_arg2):
print(p_arg1)
# This shouldn't emit a warning since the unused argument is prefixed with an underscore.
func function_with_ignored_unused_argument(p_arg1, _p_arg2):
print(p_arg1)
func test():
pass

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 2
>> UNUSED_PARAMETER
>> The parameter 'p_arg2' is never used in the function 'function_with_unused_argument'. If this is intended, prefix it with an underscore: '_p_arg2'

View File

@@ -1,2 +1,4 @@
func test():
var unused = "not used"
var unused = "not used"
var _unused = "not used, but no warning since the variable name starts with an underscore"

View File

@@ -0,0 +1,6 @@
func i_return_void() -> void:
return
func test():
var __ = i_return_void()

View File

@@ -0,0 +1,5 @@
GDTEST_OK
>> WARNING
>> Line: 6
>> VOID_ASSIGNMENT
>> Assignment operation, but the function 'i_return_void()' returns void.