diff options
Diffstat (limited to 'modules/gdscript/tests')
25 files changed, 234 insertions, 8 deletions
diff --git a/modules/gdscript/tests/gdscript_test_runner.cpp b/modules/gdscript/tests/gdscript_test_runner.cpp index 15131afde7..7f42643c8f 100644 --- a/modules/gdscript/tests/gdscript_test_runner.cpp +++ b/modules/gdscript/tests/gdscript_test_runner.cpp @@ -251,7 +251,10 @@ bool GDScriptTestRunner::make_tests_for_dir(const String &p_dir) {  				return false;  			}  		} else { -			if (next.get_extension().to_lower() == "gd") { +			if (next.ends_with(".notest.gd")) { +				next = dir->get_next(); +				continue; +			} else if (next.get_extension().to_lower() == "gd") {  #ifndef DEBUG_ENABLED  				// On release builds, skip tests marked as debug only.  				Error open_err = OK; @@ -461,7 +464,6 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {  	Ref<GDScript> script;  	script.instantiate();  	script->set_path(source_file); -	script->set_script_path(source_file);  	err = script->load_source_code(source_file);  	if (err != OK) {  		enable_stdout(); @@ -598,6 +600,9 @@ GDScriptTest::TestResult GDScriptTest::execute_test_code(bool p_is_generating) {  	}  	enable_stdout(); + +	GDScriptCache::remove_script(script->get_path()); +  	return result;  } diff --git a/modules/gdscript/tests/scripts/analyzer/errors/overload_script_variable.gd b/modules/gdscript/tests/scripts/analyzer/errors/overload_script_variable.gd new file mode 100644 index 0000000000..5c8b9fa4ae --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/overload_script_variable.gd @@ -0,0 +1,6 @@ +extends Node + +var script: int + +func test(): +	pass diff --git a/modules/gdscript/tests/scripts/analyzer/errors/overload_script_variable.out b/modules/gdscript/tests/scripts/analyzer/errors/overload_script_variable.out new file mode 100644 index 0000000000..8454aaa404 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/overload_script_variable.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +Member "script" redefined (original in native class 'Node') diff --git a/modules/gdscript/tests/scripts/analyzer/errors/variable_overloads_superclass_function.gd b/modules/gdscript/tests/scripts/analyzer/errors/variable_overloads_superclass_function.gd new file mode 100644 index 0000000000..28561ff94b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/variable_overloads_superclass_function.gd @@ -0,0 +1,9 @@ +func test(): +	pass + +class A: +	func overload_me(): +		pass + +class B extends A: +	var overload_me diff --git a/modules/gdscript/tests/scripts/analyzer/errors/variable_overloads_superclass_function.out b/modules/gdscript/tests/scripts/analyzer/errors/variable_overloads_superclass_function.out new file mode 100644 index 0000000000..32357f9f6a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/variable_overloads_superclass_function.out @@ -0,0 +1,2 @@ +GDTEST_ANALYZER_ERROR +The member "overload_me" already exists in parent class A. diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_inner_base.gd b/modules/gdscript/tests/scripts/analyzer/features/external_inner_base.gd new file mode 100644 index 0000000000..3f9bfe189c --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/external_inner_base.gd @@ -0,0 +1,4 @@ +extends "inner_base.gd".InnerA.InnerAB + +func test(): +	super.test() diff --git a/modules/gdscript/tests/scripts/analyzer/features/external_inner_base.out b/modules/gdscript/tests/scripts/analyzer/features/external_inner_base.out new file mode 100644 index 0000000000..62f1383392 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/external_inner_base.out @@ -0,0 +1,3 @@ +GDTEST_OK +InnerA.InnerAB.test +InnerB.test diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.notest.gd index ea744e3027..c3fc176679 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.notest.gd @@ -1,7 +1,4 @@  const A := 42 -func test(): -	pass -  func something():  	return "OK" diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_base.gd b/modules/gdscript/tests/scripts/analyzer/features/inner_base.gd new file mode 100644 index 0000000000..a825b59255 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/inner_base.gd @@ -0,0 +1,18 @@ +extends InnerA + +func test(): +	super.test() + +class InnerA extends InnerAB: +	func test(): +		print("InnerA.test") +		super.test() + +	class InnerAB extends InnerB: +		func test(): +			print("InnerA.InnerAB.test") +			super.test() + +class InnerB: +	func test(): +		print("InnerB.test") diff --git a/modules/gdscript/tests/scripts/analyzer/features/inner_base.out b/modules/gdscript/tests/scripts/analyzer/features/inner_base.out new file mode 100644 index 0000000000..ddd5ffcfd3 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/inner_base.out @@ -0,0 +1,4 @@ +GDTEST_OK +InnerA.test +InnerA.InnerAB.test +InnerB.test diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd index 276875dd5a..9d0324ead8 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_constant_types_are_inferred.gd @@ -1,4 +1,4 @@ -const Constants = preload("gdscript_to_preload.gd") +const Constants = preload("gdscript_to_preload.notest.gd")  func test():  	var a := Constants.A diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd new file mode 100644 index 0000000000..b730453a8a --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.gd @@ -0,0 +1,4 @@ +const A = preload("preload_cyclic_reference_a.notest.gd") + +func test(): +	A.test_cyclic_reference() diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out new file mode 100644 index 0000000000..14bb971221 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference.out @@ -0,0 +1,2 @@ +GDTEST_OK +godot diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd new file mode 100644 index 0000000000..7a6035ded1 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_a.notest.gd @@ -0,0 +1,12 @@ +const B = preload("preload_cyclic_reference_b.notest.gd") + +const WAITING_FOR = "godot" + +static func test_cyclic_reference(): +	B.test_cyclic_reference() + +static func test_cyclic_reference_2(): +	B.test_cyclic_reference_2() + +static func test_cyclic_reference_3(): +	B.test_cyclic_reference_3() diff --git a/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd new file mode 100644 index 0000000000..3ea5b01156 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/features/preload_cyclic_reference_b.notest.gd @@ -0,0 +1,10 @@ +const A = preload("preload_cyclic_reference_a.notest.gd") + +static func test_cyclic_reference(): +	A.test_cyclic_reference_2() + +static func test_cyclic_reference_2(): +	A.test_cyclic_reference_3() + +static func test_cyclic_reference_3(): +	print(A.WAITING_FOR) diff --git a/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd b/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd index 5f73064cc0..beabf3d2e5 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd +++ b/modules/gdscript/tests/scripts/analyzer/features/use_preload_script_as_type.gd @@ -1,4 +1,4 @@ -const preloaded : GDScript = preload("gdscript_to_preload.gd") +const preloaded : GDScript = preload("gdscript_to_preload.notest.gd")  func test():  	var preloaded_instance: preloaded = preloaded.new() diff --git a/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out b/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out index 13f759dd46..e89bb9226f 100644 --- a/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out +++ b/modules/gdscript/tests/scripts/parser/warnings/return_value_discarded.out @@ -2,4 +2,4 @@ GDTEST_OK  >> WARNING  >> Line: 6  >> RETURN_VALUE_DISCARDED ->> The function 'i_return_int()' returns a value, but this value is never used. +>> The function 'i_return_int()' returns a value that will be discarded if not used. diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd index c6645c2c34..809d0d28a9 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.gd @@ -69,6 +69,10 @@ func test():  	value = Transform3D()  	print(value == null) +	# Projection +	value = Projection() +	print(value == null) +  	# Color  	value = Color()  	print(value == null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out index 639f6027b9..27423ab8e7 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-equals-null.out @@ -33,3 +33,4 @@ false  false  false  false +false diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd index ee622bf22f..f46afb0f18 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.gd @@ -69,6 +69,10 @@ func test():  	value = Transform3D()  	print(value != null) +	# Projection +	value = Projection() +	print(value != null) +  	# Color  	value = Color()  	print(value != null) diff --git a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out index d1e332afba..a11c47854a 100644 --- a/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out +++ b/modules/gdscript/tests/scripts/runtime/features/compare-builtin-not-equals-null.out @@ -33,3 +33,4 @@ true  true  true  true +true diff --git a/modules/gdscript/tests/scripts/runtime/features/range_optimized_in_for_has_int_iterator.gd b/modules/gdscript/tests/scripts/runtime/features/range_optimized_in_for_has_int_iterator.gd new file mode 100644 index 0000000000..e24137a20d --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/range_optimized_in_for_has_int_iterator.gd @@ -0,0 +1,60 @@ +func test(): +	# All combinations of 1/2/3 arguments, each being int/float. + +	for number in range(5): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(5.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + + +	for number in range(1, 5): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1, 5.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1.2, 5): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1.2, 5.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + + +	for number in range(1, 5, 2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1, 5, 2.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1, 5.2, 2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1, 5.2, 2.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1.2, 5, 2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1.2, 5.2, 2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1.2, 5, 2.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	for number in range(1.2, 5.2, 2.2): +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") diff --git a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.out b/modules/gdscript/tests/scripts/runtime/features/range_optimized_in_for_has_int_iterator.out index d73c5eb7cd..d73c5eb7cd 100644 --- a/modules/gdscript/tests/scripts/analyzer/features/gdscript_to_preload.out +++ b/modules/gdscript/tests/scripts/runtime/features/range_optimized_in_for_has_int_iterator.out diff --git a/modules/gdscript/tests/scripts/runtime/features/range_returns_ints.gd b/modules/gdscript/tests/scripts/runtime/features/range_returns_ints.gd new file mode 100644 index 0000000000..63c3b84305 --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/range_returns_ints.gd @@ -0,0 +1,77 @@ +func test(): +	# All combinations of 1/2/3 arguments, each being int/float. +	# Store result in variable to ensure actual array is created (avoid `for` + `range` optimization). + +	var result + +	result = range(5) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(5.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + + +	result = range(1, 5) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1, 5.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1.2, 5) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1.2, 5.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + + +	result = range(1, 5, 2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1, 5, 2.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1, 5.2, 2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1, 5.2, 2.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1.2, 5, 2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1.2, 5.2, 2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1.2, 5, 2.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") + +	result = range(1.2, 5.2, 2.2) +	for number in result: +		if typeof(number) != TYPE_INT: +			print("Number returned from `range` was not an int!") diff --git a/modules/gdscript/tests/scripts/runtime/features/range_returns_ints.out b/modules/gdscript/tests/scripts/runtime/features/range_returns_ints.out new file mode 100644 index 0000000000..d73c5eb7cd --- /dev/null +++ b/modules/gdscript/tests/scripts/runtime/features/range_returns_ints.out @@ -0,0 +1 @@ +GDTEST_OK  |