Adding log.gd
This commit is contained in:
parent
eb32d6614e
commit
4522259397
547 changed files with 46844 additions and 0 deletions
21
addons/gdUnit4/test/core/ExampleTestSuite.cs
Normal file
21
addons/gdUnit4/test/core/ExampleTestSuite.cs
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
namespace GdUnit4.Tests.Resource
|
||||
{
|
||||
using static Assertions;
|
||||
|
||||
[TestSuite]
|
||||
public partial class ExampleTestSuiteA
|
||||
{
|
||||
|
||||
[TestCase]
|
||||
public void TestCase1()
|
||||
{
|
||||
AssertBool(true).IsEqual(true);
|
||||
}
|
||||
|
||||
[TestCase]
|
||||
public void TestCase2()
|
||||
{
|
||||
AssertBool(false).IsEqual(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
154
addons/gdUnit4/test/core/GdArrayToolsTest.gd
Normal file
154
addons/gdUnit4/test/core/GdArrayToolsTest.gd
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdArrayToolsTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdArrayTools.gd'
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_as_string(_test :String, value, expected :String, test_parameters = [
|
||||
['Array', Array([1, 2]), '[1, 2]'],
|
||||
['Array', Array([1.0, 2.212]), '[1.000000, 2.212000]'],
|
||||
['Array', Array([true, false]), '[true, false]'],
|
||||
['Array', Array(["1", "2"]), '["1", "2"]'],
|
||||
['Array', Array([Vector2.ZERO, Vector2.LEFT]), '[Vector2(), Vector2(-1, 0)]'],
|
||||
['Array', Array([Vector3.ZERO, Vector3.LEFT]), '[Vector3(), Vector3(-1, 0, 0)]'],
|
||||
['Array', Array([Color.RED, Color.GREEN]), '[Color(1, 0, 0, 1), Color(0, 1, 0, 1)]'],
|
||||
['ArrayInt', Array([1, 2]) as Array[int], '[1, 2]'],
|
||||
['ArrayFloat', Array([1.0, 2.212]) as Array[float], '[1.000000, 2.212000]'],
|
||||
['ArrayBool', Array([true, false]) as Array[bool], '[true, false]'],
|
||||
['ArrayString', Array(["1", "2"]) as Array[String], '["1", "2"]'],
|
||||
['ArrayVector2', Array([Vector2.ZERO, Vector2.LEFT]) as Array[Vector2], '[Vector2(), Vector2(-1, 0)]'],
|
||||
['ArrayVector2i', Array([Vector2i.ZERO, Vector2i.LEFT]) as Array[Vector2i], '[Vector2i(), Vector2i(-1, 0)]'],
|
||||
['ArrayVector3', Array([Vector3.ZERO, Vector3.LEFT]) as Array[Vector3], '[Vector3(), Vector3(-1, 0, 0)]'],
|
||||
['ArrayVector3i', Array([Vector3i.ZERO, Vector3i.LEFT]) as Array[Vector3i], '[Vector3i(), Vector3i(-1, 0, 0)]'],
|
||||
['ArrayVector4', Array([Vector4.ZERO, Vector4.ONE]) as Array[Vector4], '[Vector4(), Vector4(1, 1, 1, 1)]'],
|
||||
['ArrayVector4i', Array([Vector4i.ZERO, Vector4i.ONE]) as Array[Vector4i], '[Vector4i(), Vector4i(1, 1, 1, 1)]'],
|
||||
['ArrayColor', Array([Color.RED, Color.GREEN]) as Array[Color], '[Color(1, 0, 0, 1), Color(0, 1, 0, 1)]'],
|
||||
['PackedByteArray', PackedByteArray([1, 2]), 'PackedByteArray[1, 2]'],
|
||||
['PackedInt32Array', PackedInt32Array([1, 2]), 'PackedInt32Array[1, 2]'],
|
||||
['PackedInt64Array', PackedInt64Array([1, 2]), 'PackedInt64Array[1, 2]'],
|
||||
['PackedFloat32Array', PackedFloat32Array([1, 2.212]), 'PackedFloat32Array[1.000000, 2.212000]'],
|
||||
['PackedFloat64Array', PackedFloat64Array([1, 2.212]), 'PackedFloat64Array[1.000000, 2.212000]'],
|
||||
['PackedStringArray', PackedStringArray([1, 2]), 'PackedStringArray["1", "2"]'],
|
||||
['PackedVector2Array', PackedVector2Array([Vector2.ZERO, Vector2.LEFT]), 'PackedVector2Array[Vector2(), Vector2(-1, 0)]'],
|
||||
['PackedVector3Array', PackedVector3Array([Vector3.ZERO, Vector3.LEFT]), 'PackedVector3Array[Vector3(), Vector3(-1, 0, 0)]'],
|
||||
['PackedColorArray', PackedColorArray([Color.RED, Color.GREEN]), 'PackedColorArray[Color(1, 0, 0, 1), Color(0, 1, 0, 1)]'],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdArrayTools.as_string(value)).is_equal(expected)
|
||||
|
||||
|
||||
func test_as_string_simple_format():
|
||||
var value := PackedStringArray(["a", "b"])
|
||||
prints(GdArrayTools.as_string(value, false))
|
||||
assert_that(GdArrayTools.as_string(value, false)).is_equal('[a, b]')
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_is_array_type(_test :String, value, expected :bool, test_parameters = [
|
||||
['bool', true, false],
|
||||
['int', 42, false],
|
||||
['float', 1.21, false],
|
||||
['String', "abc", false],
|
||||
['Dictionary', {}, false],
|
||||
['RefCounted', RefCounted.new(), false],
|
||||
['Array', Array([1, 2]), true],
|
||||
['Array', Array([1.0, 2.212]), true],
|
||||
['Array', Array([true, false]), true],
|
||||
['Array', Array(["1", "2"]), true],
|
||||
['Array', Array([Vector2.ZERO, Vector2.LEFT]), true],
|
||||
['Array', Array([Vector3.ZERO, Vector3.LEFT]), true],
|
||||
['Array', Array([Color.RED, Color.GREEN]), true],
|
||||
['ArrayInt', Array([1, 2]) as Array[int], true],
|
||||
['ArrayFloat', Array([1.0, 2.212]) as Array[float], true],
|
||||
['ArrayBool', Array([true, false]) as Array[bool], true],
|
||||
['ArrayString', Array(["1", "2"]) as Array[String], true],
|
||||
['ArrayVector2', Array([Vector2.ZERO, Vector2.LEFT]) as Array[Vector2], true],
|
||||
['ArrayVector2i', Array([Vector2i.ZERO, Vector2i.LEFT]) as Array[Vector2i], true],
|
||||
['ArrayVector3', Array([Vector3.ZERO, Vector3.LEFT]) as Array[Vector3], true],
|
||||
['ArrayVector3i', Array([Vector3i.ZERO, Vector3i.LEFT]) as Array[Vector3i], true],
|
||||
['ArrayVector4', Array([Vector4.ZERO, Vector4.ONE]) as Array[Vector4], true],
|
||||
['ArrayVector4i', Array([Vector4i.ZERO, Vector4i.ONE]) as Array[Vector4i], true],
|
||||
['ArrayColor', Array([Color.RED, Color.GREEN]) as Array[Color], true],
|
||||
['PackedByteArray', PackedByteArray([1, 2]), true],
|
||||
['PackedInt32Array', PackedInt32Array([1, 2]), true],
|
||||
['PackedInt64Array', PackedInt64Array([1, 2]), true],
|
||||
['PackedFloat32Array', PackedFloat32Array([1, 2.212]), true],
|
||||
['PackedFloat64Array', PackedFloat64Array([1, 2.212]), true],
|
||||
['PackedStringArray', PackedStringArray([1, 2]), true],
|
||||
['PackedVector2Array', PackedVector2Array([Vector2.ZERO, Vector2.LEFT]), true],
|
||||
['PackedVector3Array', PackedVector3Array([Vector3.ZERO, Vector3.LEFT]), true],
|
||||
['PackedColorArray', PackedColorArray([Color.RED, Color.GREEN]), true],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdArrayTools.is_array_type(value)).is_equal(expected)
|
||||
|
||||
|
||||
func test_is_type_array() -> void:
|
||||
for type in [TYPE_NIL, TYPE_MAX]:
|
||||
if type in [TYPE_ARRAY, TYPE_PACKED_COLOR_ARRAY]:
|
||||
assert_that(GdArrayTools.is_type_array(type)).is_true()
|
||||
else:
|
||||
assert_that(GdArrayTools.is_type_array(type)).is_false()
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_filter_value(value, expected_type :int, test_parameters = [
|
||||
[[1, 2, 3, 1], TYPE_ARRAY],
|
||||
[Array([1, 2, 3, 1]) as Array[int], TYPE_ARRAY],
|
||||
[PackedByteArray([1, 2, 3, 1]), TYPE_PACKED_BYTE_ARRAY],
|
||||
[PackedInt32Array([1, 2, 3, 1]), TYPE_PACKED_INT32_ARRAY],
|
||||
[PackedInt64Array([1, 2, 3, 1]), TYPE_PACKED_INT64_ARRAY],
|
||||
[PackedFloat32Array([1.0, 2, 1.1, 1.0]), TYPE_PACKED_FLOAT32_ARRAY],
|
||||
[PackedFloat64Array([1.0, 2, 1.1, 1.0]), TYPE_PACKED_FLOAT64_ARRAY],
|
||||
[PackedStringArray(["1", "2", "3", "1"]), TYPE_PACKED_STRING_ARRAY],
|
||||
[PackedVector2Array([Vector2.ZERO, Vector2.ONE, Vector2.DOWN, Vector2.ZERO]), TYPE_PACKED_VECTOR2_ARRAY],
|
||||
[PackedVector3Array([Vector3.ZERO, Vector3.ONE, Vector3.DOWN, Vector3.ZERO]), TYPE_PACKED_VECTOR3_ARRAY],
|
||||
[PackedColorArray([Color.RED, Color.GREEN, Color.BLUE, Color.RED]), TYPE_PACKED_COLOR_ARRAY]
|
||||
]) -> void:
|
||||
|
||||
var value_to_remove = value[0]
|
||||
var result :Variant = GdArrayTools.filter_value(value, value_to_remove)
|
||||
assert_array(result).not_contains([value_to_remove]).has_size(2)
|
||||
assert_that(typeof(result)).is_equal(expected_type)
|
||||
|
||||
|
||||
func test_filter_value_() -> void:
|
||||
assert_array(GdArrayTools.filter_value([], null)).is_empty()
|
||||
assert_array(GdArrayTools.filter_value([], "")).is_empty()
|
||||
|
||||
var current :Array = [null, "a", "b", null, "c", null]
|
||||
var filtered :Variant= GdArrayTools.filter_value(current, null)
|
||||
assert_array(filtered).contains_exactly(["a", "b", "c"])
|
||||
# verify the source is not affected
|
||||
assert_array(current).contains_exactly([null, "a", "b", null, "c", null])
|
||||
|
||||
current = [null, "a", "xxx", null, "xx", null]
|
||||
filtered = GdArrayTools.filter_value(current, "xxx")
|
||||
assert_array(filtered).contains_exactly([null, "a", null, "xx", null])
|
||||
# verify the source is not affected
|
||||
assert_array(current).contains_exactly([null, "a", "xxx", null, "xx", null])
|
||||
|
||||
|
||||
func test_erase_value() -> void:
|
||||
var current := []
|
||||
GdArrayTools.erase_value(current, null)
|
||||
assert_array(current).is_empty()
|
||||
|
||||
current = [null]
|
||||
GdArrayTools.erase_value(current, null)
|
||||
assert_array(current).is_empty()
|
||||
|
||||
current = [null, "a", "b", null, "c", null]
|
||||
GdArrayTools.erase_value(current, null)
|
||||
# verify the source is affected
|
||||
assert_array(current).contains_exactly(["a", "b", "c"])
|
||||
|
||||
|
||||
func test_scan_typed() -> void:
|
||||
assert_that(GdArrayTools.scan_typed([1, 2, 3])).is_equal(TYPE_INT)
|
||||
assert_that(GdArrayTools.scan_typed([1, 2.2, 3])).is_equal(GdObjects.TYPE_VARIANT)
|
||||
48
addons/gdUnit4/test/core/GdDiffToolTest.gd
Normal file
48
addons/gdUnit4/test/core/GdDiffToolTest.gd
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
# GdUnit generated TestSuite
|
||||
#warning-ignore-all:unused_argument
|
||||
#warning-ignore-all:return_value_discarded
|
||||
class_name GdDiffToolTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdDiffTool.gd'
|
||||
|
||||
|
||||
func test_string_diff_empty():
|
||||
var diffs := GdDiffTool.string_diff("", "")
|
||||
assert_array(diffs).has_size(2)
|
||||
assert_array(diffs[0]).is_empty()
|
||||
assert_array(diffs[1]).is_empty()
|
||||
|
||||
|
||||
func test_string_diff_equals():
|
||||
var diffs := GdDiffTool.string_diff("Abc", "Abc")
|
||||
var expected_l_diff := "Abc".to_ascii_buffer()
|
||||
var expected_r_diff := "Abc".to_ascii_buffer()
|
||||
|
||||
assert_array(diffs).has_size(2)
|
||||
assert_array(diffs[0]).contains_exactly(expected_l_diff)
|
||||
assert_array(diffs[1]).contains_exactly(expected_r_diff)
|
||||
|
||||
|
||||
func test_string_diff():
|
||||
# tests the result of string diff function like assert_str("Abc").is_equal("abc")
|
||||
var diffs := GdDiffTool.string_diff("Abc", "abc")
|
||||
var chars := "Aabc".to_ascii_buffer()
|
||||
var ord_A := chars[0]
|
||||
var ord_a := chars[1]
|
||||
var ord_b := chars[2]
|
||||
var ord_c := chars[3]
|
||||
var expected_l_diff := PackedByteArray([GdDiffTool.DIV_SUB, ord_A, GdDiffTool.DIV_ADD, ord_a, ord_b, ord_c])
|
||||
var expected_r_diff := PackedByteArray([GdDiffTool.DIV_ADD, ord_A, GdDiffTool.DIV_SUB, ord_a, ord_b, ord_c])
|
||||
|
||||
assert_array(diffs).has_size(2)
|
||||
assert_array(diffs[0]).contains_exactly(expected_l_diff)
|
||||
assert_array(diffs[1]).contains_exactly(expected_r_diff)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_string_diff_large_value(fuzzer := Fuzzers.rand_str(1000, 4000), fuzzer_iterations = 10):
|
||||
# test diff with large values not crashes the API GD-100
|
||||
var value :String = fuzzer.next_value()
|
||||
GdDiffTool.string_diff(value, value)
|
||||
512
addons/gdUnit4/test/core/GdObjectsTest.gd
Normal file
512
addons/gdUnit4/test/core/GdObjectsTest.gd
Normal file
|
|
@ -0,0 +1,512 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
func test_equals_string():
|
||||
var a := ""
|
||||
var b := ""
|
||||
var c := "abc"
|
||||
var d := "abC"
|
||||
|
||||
assert_bool(GdObjects.equals("", "")).is_true()
|
||||
assert_bool(GdObjects.equals(a, "")).is_true()
|
||||
assert_bool(GdObjects.equals("", a)).is_true()
|
||||
assert_bool(GdObjects.equals(a, a)).is_true()
|
||||
assert_bool(GdObjects.equals(a, b)).is_true()
|
||||
assert_bool(GdObjects.equals(b, a)).is_true()
|
||||
assert_bool(GdObjects.equals(c, c)).is_true()
|
||||
assert_bool(GdObjects.equals(c, String(c))).is_true()
|
||||
|
||||
assert_bool(GdObjects.equals(a, null)).is_false()
|
||||
assert_bool(GdObjects.equals(null, a)).is_false()
|
||||
assert_bool(GdObjects.equals("", c)).is_false()
|
||||
assert_bool(GdObjects.equals(c, "")).is_false()
|
||||
assert_bool(GdObjects.equals(c, d)).is_false()
|
||||
assert_bool(GdObjects.equals(d, c)).is_false()
|
||||
# against diverent type
|
||||
assert_bool(GdObjects.equals(d, Array())).is_false()
|
||||
assert_bool(GdObjects.equals(d, Dictionary())).is_false()
|
||||
assert_bool(GdObjects.equals(d, Vector2.ONE)).is_false()
|
||||
assert_bool(GdObjects.equals(d, Vector3.ONE)).is_false()
|
||||
|
||||
|
||||
func test_equals_stringname():
|
||||
assert_bool(GdObjects.equals("", &"")).is_true()
|
||||
assert_bool(GdObjects.equals("abc", &"abc")).is_true()
|
||||
assert_bool(GdObjects.equals("abc", &"abC")).is_false()
|
||||
|
||||
|
||||
func test_equals_array():
|
||||
var a := []
|
||||
var b := []
|
||||
var c := Array()
|
||||
var d := [1,2,3,4,5]
|
||||
var e := [1,2,3,4,5]
|
||||
var x := [1,2,3,6,4,5]
|
||||
|
||||
assert_bool(GdObjects.equals(a, a)).is_true()
|
||||
assert_bool(GdObjects.equals(a, b)).is_true()
|
||||
assert_bool(GdObjects.equals(b, a)).is_true()
|
||||
assert_bool(GdObjects.equals(a, c)).is_true()
|
||||
assert_bool(GdObjects.equals(c, b)).is_true()
|
||||
assert_bool(GdObjects.equals(d, d)).is_true()
|
||||
assert_bool(GdObjects.equals(d, e)).is_true()
|
||||
assert_bool(GdObjects.equals(e, d)).is_true()
|
||||
|
||||
assert_bool(GdObjects.equals(a, null)).is_false()
|
||||
assert_bool(GdObjects.equals(null, a)).is_false()
|
||||
assert_bool(GdObjects.equals(a, d)).is_false()
|
||||
assert_bool(GdObjects.equals(d, a)).is_false()
|
||||
assert_bool(GdObjects.equals(d, x)).is_false()
|
||||
assert_bool(GdObjects.equals(x, d)).is_false()
|
||||
# against diverent type
|
||||
assert_bool(GdObjects.equals(a, "")).is_false()
|
||||
assert_bool(GdObjects.equals(a, Dictionary())).is_false()
|
||||
assert_bool(GdObjects.equals(a, Vector2.ONE)).is_false()
|
||||
assert_bool(GdObjects.equals(a, Vector3.ONE)).is_false()
|
||||
|
||||
|
||||
func test_equals_dictionary():
|
||||
var a := {}
|
||||
var b := {}
|
||||
var c := {"a":"foo"}
|
||||
var d := {"a":"foo"}
|
||||
var e1 := {"a":"foo", "b":"bar"}
|
||||
var e2 := {"b":"bar", "a":"foo"}
|
||||
|
||||
assert_bool(GdObjects.equals(a, a)).is_true()
|
||||
assert_bool(GdObjects.equals(a, b)).is_true()
|
||||
assert_bool(GdObjects.equals(b, a)).is_true()
|
||||
assert_bool(GdObjects.equals(c, c)).is_true()
|
||||
assert_bool(GdObjects.equals(c, d)).is_true()
|
||||
assert_bool(GdObjects.equals(e1, e2)).is_true()
|
||||
assert_bool(GdObjects.equals(e2, e1)).is_true()
|
||||
|
||||
assert_bool(GdObjects.equals(a, null)).is_false()
|
||||
assert_bool(GdObjects.equals(null, a)).is_false()
|
||||
assert_bool(GdObjects.equals(a, c)).is_false()
|
||||
assert_bool(GdObjects.equals(c, a)).is_false()
|
||||
assert_bool(GdObjects.equals(a, e1)).is_false()
|
||||
assert_bool(GdObjects.equals(e1, a)).is_false()
|
||||
assert_bool(GdObjects.equals(c, e1)).is_false()
|
||||
assert_bool(GdObjects.equals(e1, c)).is_false()
|
||||
|
||||
|
||||
class TestClass extends Resource:
|
||||
|
||||
enum {
|
||||
A,
|
||||
B
|
||||
}
|
||||
|
||||
var _a:int
|
||||
var _b:String
|
||||
var _c:Array
|
||||
|
||||
func _init(a:int = 0,b:String = "",c:Array = []):
|
||||
_a = a
|
||||
_b = b
|
||||
_c = c
|
||||
|
||||
|
||||
func test_equals_class():
|
||||
var a := TestClass.new()
|
||||
var b := TestClass.new()
|
||||
var c := TestClass.new(1, "foo", ["bar", "xxx"])
|
||||
var d := TestClass.new(1, "foo", ["bar", "xxx"])
|
||||
var x := TestClass.new(1, "foo", ["bar", "xsxx"])
|
||||
|
||||
assert_bool(GdObjects.equals(a, a)).is_true()
|
||||
assert_bool(GdObjects.equals(a, b)).is_true()
|
||||
assert_bool(GdObjects.equals(b, a)).is_true()
|
||||
assert_bool(GdObjects.equals(c, d)).is_true()
|
||||
assert_bool(GdObjects.equals(d, c)).is_true()
|
||||
|
||||
assert_bool(GdObjects.equals(a, null)).is_false()
|
||||
assert_bool(GdObjects.equals(null, a)).is_false()
|
||||
assert_bool(GdObjects.equals(a, c)).is_false()
|
||||
assert_bool(GdObjects.equals(c, a)).is_false()
|
||||
assert_bool(GdObjects.equals(d, x)).is_false()
|
||||
assert_bool(GdObjects.equals(x, d)).is_false()
|
||||
|
||||
|
||||
func test_equals_with_stack_deep():
|
||||
# more extended version
|
||||
var x2 := TestClass.new(1, "foo", [TestClass.new(22, "foo"), TestClass.new(22, "foo")])
|
||||
var x3 := TestClass.new(1, "foo", [TestClass.new(22, "foo"), TestClass.new(23, "foo")])
|
||||
assert_bool(GdObjects.equals(x2, x3)).is_false()
|
||||
|
||||
|
||||
func test_equals_Node_with_deep_check():
|
||||
var nodeA = auto_free(Node.new())
|
||||
var nodeB = auto_free(Node.new())
|
||||
|
||||
# compares by default with deep parameter ckeck
|
||||
assert_bool(GdObjects.equals(nodeA, nodeA)).is_true()
|
||||
assert_bool(GdObjects.equals(nodeB, nodeB)).is_true()
|
||||
assert_bool(GdObjects.equals(nodeA, nodeB)).is_true()
|
||||
assert_bool(GdObjects.equals(nodeB, nodeA)).is_true()
|
||||
# compares by object reference
|
||||
assert_bool(GdObjects.equals(nodeA, nodeA, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_true()
|
||||
assert_bool(GdObjects.equals(nodeB, nodeB, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_true()
|
||||
assert_bool(GdObjects.equals(nodeA, nodeB, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_false()
|
||||
assert_bool(GdObjects.equals(nodeB, nodeA, false, GdObjects.COMPARE_MODE.OBJECT_REFERENCE)).is_false()
|
||||
|
||||
|
||||
func test_is_primitive_type():
|
||||
assert_bool(GdObjects.is_primitive_type(false)).is_true()
|
||||
assert_bool(GdObjects.is_primitive_type(true)).is_true()
|
||||
assert_bool(GdObjects.is_primitive_type(0)).is_true()
|
||||
assert_bool(GdObjects.is_primitive_type(0.1)).is_true()
|
||||
assert_bool(GdObjects.is_primitive_type("")).is_true()
|
||||
assert_bool(GdObjects.is_primitive_type(Vector2.ONE)).is_false()
|
||||
|
||||
|
||||
class TestClassForIsType:
|
||||
var x
|
||||
|
||||
|
||||
func test_is_type():
|
||||
# check build-in types
|
||||
assert_bool(GdObjects.is_type(1)).is_false()
|
||||
assert_bool(GdObjects.is_type(1.3)).is_false()
|
||||
assert_bool(GdObjects.is_type(true)).is_false()
|
||||
assert_bool(GdObjects.is_type(false)).is_false()
|
||||
assert_bool(GdObjects.is_type([])).is_false()
|
||||
assert_bool(GdObjects.is_type("abc")).is_false()
|
||||
|
||||
assert_bool(GdObjects.is_type(null)).is_false()
|
||||
# an object type
|
||||
assert_bool(GdObjects.is_type(Node)).is_true()
|
||||
# an reference type
|
||||
assert_bool(GdObjects.is_type(AStar3D)).is_true()
|
||||
# an script type
|
||||
assert_bool(GdObjects.is_type(GDScript)).is_true()
|
||||
# an custom type
|
||||
assert_bool(GdObjects.is_type(TestClassForIsType)).is_true()
|
||||
# checked inner class type
|
||||
assert_bool(GdObjects.is_type(CustomClass.InnerClassA)).is_true()
|
||||
assert_bool(GdObjects.is_type(CustomClass.InnerClassC)).is_true()
|
||||
|
||||
# for instances must allways endup with false
|
||||
assert_bool(GdObjects.is_type(auto_free(Node.new()))).is_false()
|
||||
assert_bool(GdObjects.is_type(AStar3D.new())).is_false()
|
||||
assert_bool(GdObjects.is_type(Dictionary())).is_false()
|
||||
assert_bool(GdObjects.is_type(PackedColorArray())).is_false()
|
||||
assert_bool(GdObjects.is_type(GDScript.new())).is_false()
|
||||
assert_bool(GdObjects.is_type(TestClassForIsType.new())).is_false()
|
||||
assert_bool(GdObjects.is_type(auto_free(CustomClass.InnerClassC.new()))).is_false()
|
||||
|
||||
|
||||
func test_is_singleton() -> void:
|
||||
for singleton_name in Engine.get_singleton_list():
|
||||
var singleton = Engine.get_singleton(singleton_name)
|
||||
assert_bool(GdObjects.is_singleton(singleton)) \
|
||||
.override_failure_message("Expect to a singleton: '%s' Instance: %s, Class: %s" % [singleton_name, singleton, singleton.get_class()]) \
|
||||
.is_true()
|
||||
# false tests
|
||||
assert_bool(GdObjects.is_singleton(10)).is_false()
|
||||
assert_bool(GdObjects.is_singleton(true)).is_false()
|
||||
assert_bool(GdObjects.is_singleton(Node)).is_false()
|
||||
assert_bool(GdObjects.is_singleton(auto_free(Node.new()))).is_false()
|
||||
|
||||
|
||||
func _is_instance(value) -> bool:
|
||||
return GdObjects.is_instance(auto_free(value))
|
||||
|
||||
|
||||
func test_is_instance_true():
|
||||
assert_bool(_is_instance(RefCounted.new())).is_true()
|
||||
assert_bool(_is_instance(Node.new())).is_true()
|
||||
assert_bool(_is_instance(AStar3D.new())).is_true()
|
||||
assert_bool(_is_instance(PackedScene.new())).is_true()
|
||||
assert_bool(_is_instance(GDScript.new())).is_true()
|
||||
assert_bool(_is_instance(Person.new())).is_true()
|
||||
assert_bool(_is_instance(CustomClass.new())).is_true()
|
||||
assert_bool(_is_instance(CustomNodeTestClass.new())).is_true()
|
||||
assert_bool(_is_instance(TestClassForIsType.new())).is_true()
|
||||
assert_bool(_is_instance(CustomClass.InnerClassC.new())).is_true()
|
||||
|
||||
|
||||
func test_is_instance_false():
|
||||
assert_bool(_is_instance(RefCounted)).is_false()
|
||||
assert_bool(_is_instance(Node)).is_false()
|
||||
assert_bool(_is_instance(AStar3D)).is_false()
|
||||
assert_bool(_is_instance(PackedScene)).is_false()
|
||||
assert_bool(_is_instance(GDScript)).is_false()
|
||||
assert_bool(_is_instance(Dictionary())).is_false()
|
||||
assert_bool(_is_instance(PackedColorArray())).is_false()
|
||||
assert_bool(_is_instance(Person)).is_false()
|
||||
assert_bool(_is_instance(CustomClass)).is_false()
|
||||
assert_bool(_is_instance(CustomNodeTestClass)).is_false()
|
||||
assert_bool(_is_instance(TestClassForIsType)).is_false()
|
||||
assert_bool(_is_instance(CustomClass.InnerClassC)).is_false()
|
||||
|
||||
|
||||
# shorter helper func to extract class name and using auto_free
|
||||
func extract_class_name(value) -> GdUnitResult:
|
||||
return GdObjects.extract_class_name(auto_free(value))
|
||||
|
||||
|
||||
func test_get_class_name_from_class_path():
|
||||
# extract class name by resoure path
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/resources/core/Person.gd"))\
|
||||
.is_success().is_value("Person")
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/resources/core/CustomClass.gd"))\
|
||||
.is_success().is_value("CustomClass")
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/mocker/resources/CustomNodeTestClass.gd"))\
|
||||
.is_success().is_value("CustomNodeTestClass")
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd"))\
|
||||
.is_success().is_value("CustomResourceTestClass")
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd"))\
|
||||
.is_success().is_value("OverridenGetClassTestClass")
|
||||
|
||||
|
||||
func test_get_class_name_from_snake_case_class_path():
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd"))\
|
||||
.is_success().is_value("SnakeCaseWithClassName")
|
||||
# without class_name
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd"))\
|
||||
.is_success().is_value("SnakeCaseWithoutClassName")
|
||||
|
||||
|
||||
func test_get_class_name_from_pascal_case_class_path():
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd"))\
|
||||
.is_success().is_value("PascalCaseWithClassName")
|
||||
# without class_name
|
||||
assert_result(extract_class_name("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd"))\
|
||||
.is_success().is_value("PascalCaseWithoutClassName")
|
||||
|
||||
|
||||
func test_get_class_name_from_type():
|
||||
assert_result(extract_class_name(Animation)).is_success().is_value("Animation")
|
||||
assert_result(extract_class_name(GDScript)).is_success().is_value("GDScript")
|
||||
assert_result(extract_class_name(Camera3D)).is_success().is_value("Camera3D")
|
||||
assert_result(extract_class_name(Node)).is_success().is_value("Node")
|
||||
assert_result(extract_class_name(Tree)).is_success().is_value("Tree")
|
||||
# extract class name from custom classes
|
||||
assert_result(extract_class_name(Person)).is_success().is_value("Person")
|
||||
assert_result(extract_class_name(CustomClass)).is_success().is_value("CustomClass")
|
||||
assert_result(extract_class_name(CustomNodeTestClass)).is_success().is_value("CustomNodeTestClass")
|
||||
assert_result(extract_class_name(CustomResourceTestClass)).is_success().is_value("CustomResourceTestClass")
|
||||
assert_result(extract_class_name(OverridenGetClassTestClass)).is_success().is_value("OverridenGetClassTestClass")
|
||||
assert_result(extract_class_name(AdvancedTestClass)).is_success().is_value("AdvancedTestClass")
|
||||
|
||||
|
||||
func test_get_class_name_from_inner_class():
|
||||
assert_result(extract_class_name(CustomClass))\
|
||||
.is_success().is_value("CustomClass")
|
||||
assert_result(extract_class_name(CustomClass.InnerClassA))\
|
||||
.is_success().is_value("CustomClass.InnerClassA")
|
||||
assert_result(extract_class_name(CustomClass.InnerClassB))\
|
||||
.is_success().is_value("CustomClass.InnerClassB")
|
||||
assert_result(extract_class_name(CustomClass.InnerClassC))\
|
||||
.is_success().is_value("CustomClass.InnerClassC")
|
||||
assert_result(extract_class_name(CustomClass.InnerClassD))\
|
||||
.is_success().is_value("CustomClass.InnerClassD")
|
||||
assert_result(extract_class_name(AdvancedTestClass.SoundData))\
|
||||
.is_success().is_value("AdvancedTestClass.SoundData")
|
||||
assert_result(extract_class_name(AdvancedTestClass.AtmosphereData))\
|
||||
.is_success().is_value("AdvancedTestClass.AtmosphereData")
|
||||
assert_result(extract_class_name(AdvancedTestClass.Area4D))\
|
||||
.is_success().is_value("AdvancedTestClass.Area4D")
|
||||
|
||||
|
||||
func test_extract_class_name_from_instance():
|
||||
assert_result(extract_class_name(Camera3D.new())).is_equal("Camera3D")
|
||||
assert_result(extract_class_name(GDScript.new())).is_equal("GDScript")
|
||||
assert_result(extract_class_name(Node.new())).is_equal("Node")
|
||||
|
||||
# extract class name from custom classes
|
||||
assert_result(extract_class_name(Person.new())).is_equal("Person")
|
||||
assert_result(extract_class_name(ClassWithNameA.new())).is_equal("ClassWithNameA")
|
||||
assert_result(extract_class_name(ClassWithNameB.new())).is_equal("ClassWithNameB")
|
||||
var classWithoutNameA = load("res://addons/gdUnit4/test/mocker/resources/ClassWithoutNameA.gd")
|
||||
assert_result(extract_class_name(classWithoutNameA.new())).is_equal("ClassWithoutNameA")
|
||||
assert_result(extract_class_name(CustomNodeTestClass.new())).is_equal("CustomNodeTestClass")
|
||||
assert_result(extract_class_name(CustomResourceTestClass.new())).is_equal("CustomResourceTestClass")
|
||||
assert_result(extract_class_name(OverridenGetClassTestClass.new())).is_equal("OverridenGetClassTestClass")
|
||||
assert_result(extract_class_name(AdvancedTestClass.new())).is_equal("AdvancedTestClass")
|
||||
# extract inner class name
|
||||
assert_result(extract_class_name(AdvancedTestClass.SoundData.new())).is_equal("AdvancedTestClass.SoundData")
|
||||
assert_result(extract_class_name(AdvancedTestClass.AtmosphereData.new())).is_equal("AdvancedTestClass.AtmosphereData")
|
||||
assert_result(extract_class_name(AdvancedTestClass.Area4D.new(0))).is_equal("AdvancedTestClass.Area4D")
|
||||
assert_result(extract_class_name(CustomClass.InnerClassC.new())).is_equal("CustomClass.InnerClassC")
|
||||
|
||||
|
||||
# verify enigne class names are not converted by configured naming convention
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_extract_class_name_from_class_path(fuzzer=GodotClassNameFuzzer.new(true, true), fuzzer_iterations = 100) -> void:
|
||||
var clazz_name :String = fuzzer.next_value()
|
||||
assert_str(GdObjects.extract_class_name_from_class_path(PackedStringArray([clazz_name]))).is_equal(clazz_name)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_extract_class_name_godot_classes(fuzzer=GodotClassNameFuzzer.new(true, true), fuzzer_iterations = 100):
|
||||
var extract_class_name_ := fuzzer.next_value() as String
|
||||
var instance :Variant = ClassDB.instantiate(extract_class_name_)
|
||||
assert_result(extract_class_name(instance)).is_equal(extract_class_name_)
|
||||
|
||||
|
||||
func test_extract_class_path_by_clazz():
|
||||
# engine classes has no class path
|
||||
assert_array(GdObjects.extract_class_path(Animation)).is_empty()
|
||||
assert_array(GdObjects.extract_class_path(GDScript)).is_empty()
|
||||
assert_array(GdObjects.extract_class_path(Camera3D)).is_empty()
|
||||
assert_array(GdObjects.extract_class_path(Tree)).is_empty()
|
||||
assert_array(GdObjects.extract_class_path(Node)).is_empty()
|
||||
|
||||
# script classes
|
||||
assert_array(GdObjects.extract_class_path(Person))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/resources/core/Person.gd"])
|
||||
assert_array(GdObjects.extract_class_path(CustomClass))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd"])
|
||||
assert_array(GdObjects.extract_class_path(CustomNodeTestClass))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/CustomNodeTestClass.gd"])
|
||||
assert_array(GdObjects.extract_class_path(CustomResourceTestClass))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd"])
|
||||
assert_array(GdObjects.extract_class_path(OverridenGetClassTestClass))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/OverridenGetClassTestClass.gd"])
|
||||
|
||||
# script inner classes
|
||||
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassA))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassA"])
|
||||
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassB))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassB"])
|
||||
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassC))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassC"])
|
||||
assert_array(GdObjects.extract_class_path(AdvancedTestClass.SoundData))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd", "SoundData"])
|
||||
assert_array(GdObjects.extract_class_path(AdvancedTestClass.AtmosphereData))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd", "AtmosphereData"])
|
||||
assert_array(GdObjects.extract_class_path(AdvancedTestClass.Area4D))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/mocker/resources/AdvancedTestClass.gd", "Area4D"])
|
||||
|
||||
# inner inner class
|
||||
assert_array(GdObjects.extract_class_path(CustomClass.InnerClassD.InnerInnerClassA))\
|
||||
.contains_exactly(["res://addons/gdUnit4/test/resources/core/CustomClass.gd", "InnerClassD", "InnerInnerClassA"])
|
||||
|
||||
|
||||
#func __test_can_instantiate():
|
||||
# assert_bool(GdObjects.can_instantiate(GDScript)).is_true()
|
||||
# assert_bool(GdObjects.can_instantiate(Node)).is_true()
|
||||
# assert_bool(GdObjects.can_instantiate(Tree)).is_true()
|
||||
# assert_bool(GdObjects.can_instantiate(Camera3D)).is_true()
|
||||
# assert_bool(GdObjects.can_instantiate(Person)).is_true()
|
||||
# assert_bool(GdObjects.can_instantiate(CustomClass.InnerClassA)).is_true()
|
||||
# assert_bool(GdObjects.can_instantiate(TreeItem)).is_true()
|
||||
#
|
||||
# creates a test instance by given class name or resource path
|
||||
# instances created with auto free
|
||||
func create_instance(clazz):
|
||||
var result := GdObjects.create_instance(clazz)
|
||||
if result.is_success():
|
||||
return auto_free(result.value())
|
||||
return null
|
||||
|
||||
|
||||
func test_create_instance_by_class_name():
|
||||
# instance of engine classes
|
||||
assert_object(create_instance(Node))\
|
||||
.is_not_null()\
|
||||
.is_instanceof(Node)
|
||||
assert_object(create_instance(Camera3D))\
|
||||
.is_not_null()\
|
||||
.is_instanceof(Camera3D)
|
||||
# instance of custom classes
|
||||
assert_object(create_instance(Person))\
|
||||
.is_not_null()\
|
||||
.is_instanceof(Person)
|
||||
# instance of inner classes
|
||||
assert_object(create_instance(CustomClass.InnerClassA))\
|
||||
.is_not_null()\
|
||||
.is_instanceof(CustomClass.InnerClassA)
|
||||
|
||||
|
||||
func test_extract_class_name_on_null_value():
|
||||
# we can't extract class name from a null value
|
||||
assert_result(GdObjects.extract_class_name(null))\
|
||||
.is_error()\
|
||||
.contains_message("Can't extract class name form a null value.")
|
||||
|
||||
|
||||
func test_is_public_script_class() -> void:
|
||||
# snake case format class names
|
||||
assert_bool(GdObjects.is_public_script_class("ScriptWithClassName")).is_true()
|
||||
assert_bool(GdObjects.is_public_script_class("script_without_class_name")).is_false()
|
||||
assert_bool(GdObjects.is_public_script_class("CustomClass")).is_true()
|
||||
# inner classes not listed as public classes
|
||||
assert_bool(GdObjects.is_public_script_class("CustomClass.InnerClassA")).is_false()
|
||||
|
||||
|
||||
func test_is_instance_scene() -> void:
|
||||
# checked none scene objects
|
||||
assert_bool(GdObjects.is_instance_scene(RefCounted.new())).is_false()
|
||||
assert_bool(GdObjects.is_instance_scene(CustomClass.new())).is_false()
|
||||
assert_bool(GdObjects.is_instance_scene(auto_free(Control.new()))).is_false()
|
||||
|
||||
# now check checked a loaded scene
|
||||
var resource = load("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
|
||||
assert_bool(GdObjects.is_instance_scene(resource)).is_false()
|
||||
# checked a instance of a scene
|
||||
assert_bool(GdObjects.is_instance_scene(auto_free(resource.instantiate()))).is_true()
|
||||
|
||||
|
||||
func test_is_scene_resource_path() -> void:
|
||||
assert_bool(GdObjects.is_scene_resource_path(RefCounted.new())).is_false()
|
||||
assert_bool(GdObjects.is_scene_resource_path(CustomClass.new())).is_false()
|
||||
assert_bool(GdObjects.is_scene_resource_path(auto_free(Control.new()))).is_false()
|
||||
|
||||
# check checked a loaded scene
|
||||
var resource = load("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
|
||||
assert_bool(GdObjects.is_scene_resource_path(resource)).is_false()
|
||||
# checked resource path
|
||||
assert_bool(GdObjects.is_scene_resource_path("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")).is_true()
|
||||
|
||||
|
||||
func test_extract_class_functions() -> void:
|
||||
var functions := GdObjects.extract_class_functions("Resource", [""])
|
||||
for f in functions:
|
||||
if f["name"] == "get_path":
|
||||
assert_str(GdFunctionDescriptor.extract_from(f)._to_string()).is_equal("[Line:-1] func get_path() -> String:")
|
||||
|
||||
functions = GdObjects.extract_class_functions("CustomResourceTestClass", ["res://addons/gdUnit4/test/mocker/resources/CustomResourceTestClass.gd"])
|
||||
for f in functions:
|
||||
if f["name"] == "get_path":
|
||||
assert_str(GdFunctionDescriptor.extract_from(f)._to_string()).is_equal("[Line:-1] func get_path() -> String:")
|
||||
|
||||
|
||||
func test_all_types() -> void:
|
||||
var expected_types :Array[int] = []
|
||||
for type_index in TYPE_MAX:
|
||||
expected_types.append(type_index)
|
||||
expected_types.append(GdObjects.TYPE_VOID)
|
||||
expected_types.append(GdObjects.TYPE_VARARG)
|
||||
expected_types.append(GdObjects.TYPE_FUNC)
|
||||
expected_types.append(GdObjects.TYPE_FUZZER)
|
||||
expected_types.append(GdObjects.TYPE_VARIANT)
|
||||
assert_array(GdObjects.all_types()).contains_exactly_in_any_order(expected_types)
|
||||
|
||||
|
||||
func test_to_camel_case() -> void:
|
||||
assert_str(GdObjects.to_camel_case("MyClassName")).is_equal("myClassName")
|
||||
assert_str(GdObjects.to_camel_case("my_class_name")).is_equal("myClassName")
|
||||
assert_str(GdObjects.to_camel_case("myClassName")).is_equal("myClassName")
|
||||
|
||||
|
||||
func test_to_pascal_case() -> void:
|
||||
assert_str(GdObjects.to_pascal_case("MyClassName")).is_equal("MyClassName")
|
||||
assert_str(GdObjects.to_pascal_case("my_class_name")).is_equal("MyClassName")
|
||||
assert_str(GdObjects.to_pascal_case("myClassName")).is_equal("MyClassName")
|
||||
|
||||
|
||||
func test_to_snake_case() -> void:
|
||||
assert_str(GdObjects.to_snake_case("MyClassName")).is_equal("my_class_name")
|
||||
assert_str(GdObjects.to_snake_case("my_class_name")).is_equal("my_class_name")
|
||||
assert_str(GdObjects.to_snake_case("myClassName")).is_equal("my_class_name")
|
||||
|
||||
|
||||
func test_is_snake_case() -> void:
|
||||
assert_bool(GdObjects.is_snake_case("my_class_name")).is_true()
|
||||
assert_bool(GdObjects.is_snake_case("myclassname")).is_true()
|
||||
assert_bool(GdObjects.is_snake_case("MyClassName")).is_false()
|
||||
assert_bool(GdObjects.is_snake_case("my_class_nameTest")).is_false()
|
||||
67
addons/gdUnit4/test/core/GdUnit4VersionTest.gd
Normal file
67
addons/gdUnit4/test/core/GdUnit4VersionTest.gd
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnit4VersionTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/.gd'
|
||||
|
||||
|
||||
func test_parse() -> void:
|
||||
var expected := GdUnit4Version.new(0, 9, 1)
|
||||
assert_object(GdUnit4Version.parse("v0.9.1-rc")).is_equal(expected)
|
||||
assert_object(GdUnit4Version.parse("v0.9.1RC")).is_equal(expected)
|
||||
assert_object(GdUnit4Version.parse("0.9.1 rc")).is_equal(expected)
|
||||
assert_object(GdUnit4Version.parse("0.9.1")).is_equal(expected)
|
||||
|
||||
|
||||
func test_equals() -> void:
|
||||
var version := GdUnit4Version.new(0, 9, 1)
|
||||
assert_bool(version.equals(version)).is_true()
|
||||
assert_bool(version.equals(GdUnit4Version.new(0, 9, 1))).is_true()
|
||||
assert_bool(GdUnit4Version.new(0, 9, 1).equals(version)).is_true()
|
||||
|
||||
assert_bool(GdUnit4Version.new(0, 9, 2).equals(version)).is_false()
|
||||
assert_bool(GdUnit4Version.new(0, 8, 1).equals(version)).is_false()
|
||||
assert_bool(GdUnit4Version.new(1, 9, 1).equals(version)).is_false()
|
||||
|
||||
|
||||
func test_to_string() -> void:
|
||||
var version := GdUnit4Version.new(0, 9, 1)
|
||||
assert_str(str(version)).is_equal("v0.9.1")
|
||||
assert_str("%s" % version).is_equal("v0.9.1")
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_is_greater_major(fuzzer_major := Fuzzers.rangei(1, 20), fuzzer_minor := Fuzzers.rangei(0, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void:
|
||||
var version := GdUnit4Version.new(0, 9, 1)
|
||||
var current := GdUnit4Version.new(fuzzer_major.next_value(), fuzzer_minor.next_value(), fuzzer_patch.next_value());
|
||||
assert_bool(current.is_greater(version))\
|
||||
.override_failure_message("Expect %s is greater then %s" % [current, version])\
|
||||
.is_true()
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_is_not_greater_major(fuzzer_major := Fuzzers.rangei(1, 10), fuzzer_minor := Fuzzers.rangei(0, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void:
|
||||
var version := GdUnit4Version.new(11, 0, 0)
|
||||
var current := GdUnit4Version.new(fuzzer_major.next_value(), fuzzer_minor.next_value(), fuzzer_patch.next_value());
|
||||
assert_bool(current.is_greater(version))\
|
||||
.override_failure_message("Expect %s is not greater then %s" % [current, version])\
|
||||
.is_false()
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_is_greater_minor(fuzzer_minor := Fuzzers.rangei(3, 20), fuzzer_patch := Fuzzers.rangei(0, 20), fuzzer_iterations = 500) -> void:
|
||||
var version := GdUnit4Version.new(0, 2, 1)
|
||||
var current := GdUnit4Version.new(0, fuzzer_minor.next_value(), fuzzer_patch.next_value());
|
||||
assert_bool(current.is_greater(version))\
|
||||
.override_failure_message("Expect %s is greater then %s" % [current, version])\
|
||||
.is_true()
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_is_greater_patch(fuzzer_patch := Fuzzers.rangei(1, 20), fuzzer_iterations = 500) -> void:
|
||||
var version := GdUnit4Version.new(0, 2, 0)
|
||||
var current := GdUnit4Version.new(0, 2, fuzzer_patch.next_value());
|
||||
assert_bool(current.is_greater(version))\
|
||||
.override_failure_message("Expect %s is greater then %s" % [current, version])\
|
||||
.is_true()
|
||||
13
addons/gdUnit4/test/core/GdUnitClassDoublerTest.gd
Normal file
13
addons/gdUnit4/test/core/GdUnitClassDoublerTest.gd
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitClassDoublerTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitClassDoubler.gd'
|
||||
|
||||
# simple function doubler whitout any modifications
|
||||
class TestFunctionDoubler extends GdFunctionDoubler:
|
||||
func double(_func_descriptor :GdFunctionDescriptor) -> PackedStringArray:
|
||||
return PackedStringArray([])
|
||||
|
||||
|
||||
231
addons/gdUnit4/test/core/GdUnitFileAccessTest.gd
Normal file
231
addons/gdUnit4/test/core/GdUnitFileAccessTest.gd
Normal file
|
|
@ -0,0 +1,231 @@
|
|||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitFileAccess.gd'
|
||||
|
||||
|
||||
var file_to_save :String
|
||||
|
||||
|
||||
func after() -> void:
|
||||
# verify tmp files are deleted automatically
|
||||
assert_bool(FileAccess.file_exists(file_to_save)).is_false()
|
||||
|
||||
|
||||
func _create_file(p_path :String, p_name :String) -> void:
|
||||
var file := create_temp_file(p_path, p_name)
|
||||
file.store_string("some content")
|
||||
|
||||
|
||||
func test_copy_directory() -> void:
|
||||
var temp_dir := create_temp_dir("test_copy_directory")
|
||||
assert_bool(GdUnitFileAccess.copy_directory("res://addons/gdUnit4/test/core/resources/copy_test/folder_a/", temp_dir)).is_true()
|
||||
assert_file("%s/file_a.txt" % temp_dir).exists()
|
||||
assert_file("%s/file_b.txt" % temp_dir).exists()
|
||||
|
||||
|
||||
func test_copy_directory_recursive() -> void:
|
||||
var temp_dir := create_temp_dir("test_copy_directory_recursive")
|
||||
assert_bool(GdUnitFileAccess.copy_directory("res://addons/gdUnit4/test/core/resources/copy_test/", temp_dir, true)).is_true()
|
||||
assert_file("%s/folder_a/file_a.txt" % temp_dir).exists()
|
||||
assert_file("%s/folder_a/file_b.txt" % temp_dir).exists()
|
||||
assert_file("%s/folder_b/file_a.txt" % temp_dir).exists()
|
||||
assert_file("%s/folder_b/file_b.txt" % temp_dir).exists()
|
||||
assert_file("%s/folder_b/folder_ba/file_x.txt" % temp_dir).exists()
|
||||
assert_file("%s/folder_c/file_z.txt" % temp_dir).exists()
|
||||
|
||||
|
||||
func test_create_temp_dir() -> void:
|
||||
var temp_dir := create_temp_dir("examples/game/save")
|
||||
file_to_save = temp_dir + "/save_game.dat"
|
||||
|
||||
var data := {
|
||||
'user': "Hoschi",
|
||||
'level': 42
|
||||
}
|
||||
var file := FileAccess.open(file_to_save, FileAccess.WRITE)
|
||||
file.store_line(JSON.stringify(data))
|
||||
assert_bool(FileAccess.file_exists(file_to_save)).is_true()
|
||||
|
||||
|
||||
func test_create_temp_file() -> void:
|
||||
# setup - stores a tmp file with "user://tmp/examples/game/game.sav" (auto closed)
|
||||
var file := create_temp_file("examples/game", "game.sav")
|
||||
assert_object(file).is_not_null()
|
||||
# write some example data
|
||||
file.store_line("some data")
|
||||
file.close()
|
||||
|
||||
# verify
|
||||
var file_read := create_temp_file("examples/game", "game.sav", FileAccess.READ)
|
||||
assert_object(file_read).is_not_null()
|
||||
assert_str(file_read.get_as_text()).is_equal("some data\n")
|
||||
# not needs to be manually close, will be auto closed after test suite execution
|
||||
|
||||
|
||||
func test_make_qualified_path() -> void:
|
||||
assert_str(GdUnitFileAccess.make_qualified_path("MyTest")).is_equal("MyTest")
|
||||
assert_str(GdUnitFileAccess.make_qualified_path("/MyTest.gd")).is_equal("res://MyTest.gd")
|
||||
assert_str(GdUnitFileAccess.make_qualified_path("/foo/bar/MyTest.gd")).is_equal("res://foo/bar/MyTest.gd")
|
||||
assert_str(GdUnitFileAccess.make_qualified_path("res://MyTest.gd")).is_equal("res://MyTest.gd")
|
||||
assert_str(GdUnitFileAccess.make_qualified_path("res://foo/bar/MyTest.gd")).is_equal("res://foo/bar/MyTest.gd")
|
||||
|
||||
|
||||
func test_find_last_path_index() -> void:
|
||||
# not existing directory
|
||||
assert_int(GdUnitFileAccess.find_last_path_index("/foo", "report_")).is_equal(0)
|
||||
# empty directory
|
||||
var temp_dir := create_temp_dir("test_reports")
|
||||
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(0)
|
||||
# create some report directories
|
||||
create_temp_dir("test_reports/report_1")
|
||||
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(1)
|
||||
create_temp_dir("test_reports/report_2")
|
||||
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(2)
|
||||
create_temp_dir("test_reports/report_3")
|
||||
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(3)
|
||||
create_temp_dir("test_reports/report_5")
|
||||
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(5)
|
||||
# create some more
|
||||
for index in range(10, 42):
|
||||
create_temp_dir("test_reports/report_%d" % index)
|
||||
assert_int(GdUnitFileAccess.find_last_path_index(temp_dir, "report_")).is_equal(41)
|
||||
|
||||
|
||||
func test_delete_path_index_lower_equals_than() -> void:
|
||||
var temp_dir := create_temp_dir("test_reports_delete")
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).is_empty()
|
||||
assert_int(GdUnitFileAccess.delete_path_index_lower_equals_than(temp_dir, "report_", 0)).is_equal(0)
|
||||
|
||||
# create some directories
|
||||
for index in range(10, 42):
|
||||
create_temp_dir("test_reports_delete/report_%d" % index)
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).has_size(32)
|
||||
|
||||
# try to delete directories with index lower than 0, shold delete nothing
|
||||
assert_int(GdUnitFileAccess.delete_path_index_lower_equals_than(temp_dir, "report_", 0)).is_equal(0)
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).has_size(32)
|
||||
|
||||
# try to delete directories with index lower_equals than 30
|
||||
# shold delet directories report_10 to report_30 = 21
|
||||
assert_int(GdUnitFileAccess.delete_path_index_lower_equals_than(temp_dir, "report_", 30)).is_equal(21)
|
||||
# and 12 directories are left
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir))\
|
||||
.has_size(11)\
|
||||
.contains([
|
||||
"report_31",
|
||||
"report_32",
|
||||
"report_33",
|
||||
"report_34",
|
||||
"report_35",
|
||||
"report_36",
|
||||
"report_37",
|
||||
"report_38",
|
||||
"report_39",
|
||||
"report_40",
|
||||
"report_41",
|
||||
])
|
||||
|
||||
|
||||
func test_scan_dir() -> void:
|
||||
var temp_dir := create_temp_dir("test_scan_dir")
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).is_empty()
|
||||
|
||||
create_temp_dir("test_scan_dir/report_2")
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir)).contains_exactly(["report_2"])
|
||||
# create some more directories and files
|
||||
create_temp_dir("test_scan_dir/report_4")
|
||||
create_temp_dir("test_scan_dir/report_5")
|
||||
create_temp_dir("test_scan_dir/report_6")
|
||||
create_temp_file("test_scan_dir", "file_a")
|
||||
create_temp_file("test_scan_dir", "file_b")
|
||||
# this shoul not be counted it is a file in a subdirectory
|
||||
create_temp_file("test_scan_dir/report_6", "file_b")
|
||||
assert_array(GdUnitFileAccess.scan_dir(temp_dir))\
|
||||
.has_size(6)\
|
||||
.contains([
|
||||
"report_2",
|
||||
"report_4",
|
||||
"report_5",
|
||||
"report_6",
|
||||
"file_a",
|
||||
"file_b"])
|
||||
|
||||
|
||||
func test_delete_directory() -> void:
|
||||
var tmp_dir := create_temp_dir("test_delete_dir")
|
||||
create_temp_dir("test_delete_dir/data1")
|
||||
create_temp_dir("test_delete_dir/data2")
|
||||
_create_file("test_delete_dir", "example_a.txt")
|
||||
_create_file("test_delete_dir", "example_b.txt")
|
||||
_create_file("test_delete_dir/data1", "example.txt")
|
||||
_create_file("test_delete_dir/data2", "example2.txt")
|
||||
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).contains_exactly_in_any_order([
|
||||
"data1",
|
||||
"data2",
|
||||
"example_a.txt",
|
||||
"example_b.txt"
|
||||
])
|
||||
|
||||
# Delete the entire directory and its contents
|
||||
GdUnitFileAccess.delete_directory(tmp_dir)
|
||||
assert_bool(DirAccess.dir_exists_absolute(tmp_dir)).is_false()
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).is_empty()
|
||||
|
||||
|
||||
func test_delete_directory_content_only() -> void:
|
||||
var tmp_dir := create_temp_dir("test_delete_dir")
|
||||
create_temp_dir("test_delete_dir/data1")
|
||||
create_temp_dir("test_delete_dir/data2")
|
||||
_create_file("test_delete_dir", "example_a.txt")
|
||||
_create_file("test_delete_dir", "example_b.txt")
|
||||
_create_file("test_delete_dir/data1", "example.txt")
|
||||
_create_file("test_delete_dir/data2", "example2.txt")
|
||||
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).contains_exactly_in_any_order([
|
||||
"data1",
|
||||
"data2",
|
||||
"example_a.txt",
|
||||
"example_b.txt"
|
||||
])
|
||||
|
||||
# Delete the entire directory and its contents
|
||||
GdUnitFileAccess.delete_directory(tmp_dir, true)
|
||||
assert_bool(DirAccess.dir_exists_absolute(tmp_dir)).is_true()
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_dir)).is_empty()
|
||||
|
||||
|
||||
func test_extract_package() -> void:
|
||||
clean_temp_dir()
|
||||
var tmp_path := GdUnitFileAccess.create_temp_dir("test_update")
|
||||
var source := "res://addons/gdUnit4/test/update/resources/update.zip"
|
||||
|
||||
# the temp should be inital empty
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).is_empty()
|
||||
# now extract to temp
|
||||
var result := GdUnitFileAccess.extract_zip(source, tmp_path)
|
||||
assert_result(result).is_success()
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).contains_exactly_in_any_order([
|
||||
"addons",
|
||||
"runtest.cmd",
|
||||
"runtest.sh",
|
||||
])
|
||||
|
||||
|
||||
func test_extract_package_invalid_package() -> void:
|
||||
clean_temp_dir()
|
||||
var tmp_path := GdUnitFileAccess.create_temp_dir("test_update")
|
||||
var source := "res://addons/gdUnit4/test/update/resources/update_invalid.zip"
|
||||
|
||||
# the temp should be inital empty
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).is_empty()
|
||||
# now extract to temp
|
||||
var result := GdUnitFileAccess.extract_zip(source, tmp_path)
|
||||
assert_result(result).is_error()\
|
||||
.contains_message("Extracting `%s` failed! Please collect the error log and report this. Error Code: 1" % source)
|
||||
assert_array(GdUnitFileAccess.scan_dir(tmp_path)).is_empty()
|
||||
|
||||
|
|
@ -0,0 +1,36 @@
|
|||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitObjectInteractionsTemplate.gd'
|
||||
|
||||
|
||||
func test___filter_vargs():
|
||||
var template = load(__source).new()
|
||||
|
||||
var varags :Array = [
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE]
|
||||
assert_array(template.__filter_vargs(varags)).is_empty()
|
||||
|
||||
var object := RefCounted.new()
|
||||
varags = [
|
||||
"foo",
|
||||
"bar",
|
||||
null,
|
||||
true,
|
||||
1,
|
||||
object,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE,
|
||||
GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE]
|
||||
assert_array(template.__filter_vargs(varags)).contains_exactly([
|
||||
"foo",
|
||||
"bar",
|
||||
null,
|
||||
true,
|
||||
1,
|
||||
object])
|
||||
37
addons/gdUnit4/test/core/GdUnitResultTest.gd
Normal file
37
addons/gdUnit4/test/core/GdUnitResultTest.gd
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitResultTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitResult.gd'
|
||||
|
||||
|
||||
func test_serde():
|
||||
var value = {
|
||||
"info" : "test",
|
||||
"meta" : 42
|
||||
}
|
||||
var source := GdUnitResult.success(value)
|
||||
var serialized_result = GdUnitResult.serialize(source)
|
||||
var deserialised_result := GdUnitResult.deserialize(serialized_result)
|
||||
assert_object(deserialised_result)\
|
||||
.is_instanceof(GdUnitResult) \
|
||||
.is_equal(source)
|
||||
|
||||
|
||||
func test_or_else_on_success():
|
||||
var result := GdUnitResult.success("some value")
|
||||
assert_str(result.value()).is_equal("some value")
|
||||
assert_str(result.or_else("other value")).is_equal("some value")
|
||||
|
||||
|
||||
func test_or_else_on_warning():
|
||||
var result := GdUnitResult.warn("some warning message")
|
||||
assert_object(result.value()).is_null()
|
||||
assert_str(result.or_else("other value")).is_equal("other value")
|
||||
|
||||
|
||||
func test_or_else_on_error():
|
||||
var result := GdUnitResult.error("some error message")
|
||||
assert_object(result.value()).is_null()
|
||||
assert_str(result.or_else("other value")).is_equal("other value")
|
||||
189
addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd
Normal file
189
addons/gdUnit4/test/core/GdUnitRunnerConfigTest.gd
Normal file
|
|
@ -0,0 +1,189 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitRunnerConfigTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitRunnerConfig.gd'
|
||||
|
||||
|
||||
func test_initial_config():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
assert_dict(config.to_execute()).is_empty()
|
||||
assert_dict(config.skipped()).is_empty()
|
||||
|
||||
|
||||
func test_clear_on_initial_config():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
config.clear()
|
||||
assert_dict(config.to_execute()).is_empty()
|
||||
assert_dict(config.skipped()).is_empty()
|
||||
|
||||
|
||||
func test_clear_on_filled_config():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
config.add_test_suite("res://foo")
|
||||
config.skip_test_suite("res://bar")
|
||||
assert_dict(config.to_execute()).is_not_empty()
|
||||
assert_dict(config.skipped()).is_not_empty()
|
||||
|
||||
# clear it
|
||||
config.clear()
|
||||
assert_dict(config.to_execute()).is_empty()
|
||||
assert_dict(config.skipped()).is_empty()
|
||||
|
||||
|
||||
func test_set_server_port():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
# intial value
|
||||
assert_int(config.server_port()).is_equal(-1)
|
||||
|
||||
config.set_server_port(1000)
|
||||
assert_int(config.server_port()).is_equal(1000)
|
||||
|
||||
|
||||
func test_self_test():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
# initial is empty
|
||||
assert_dict(config.to_execute()).is_empty()
|
||||
|
||||
# configure self test
|
||||
var to_execute := config.self_test().to_execute()
|
||||
assert_dict(to_execute).contains_key_value("res://addons/gdUnit4/test/", PackedStringArray())
|
||||
|
||||
|
||||
func test_add_test_suite():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
# skip should have no affect
|
||||
config.skip_test_suite("res://bar")
|
||||
|
||||
config.add_test_suite("res://foo")
|
||||
assert_dict(config.to_execute()).contains_key_value("res://foo", PackedStringArray())
|
||||
# add two more
|
||||
config.add_test_suite("res://foo2")
|
||||
config.add_test_suite("res://bar/foo")
|
||||
assert_dict(config.to_execute())\
|
||||
.contains_key_value("res://foo", PackedStringArray())\
|
||||
.contains_key_value("res://foo2", PackedStringArray())\
|
||||
.contains_key_value("res://bar/foo", PackedStringArray())
|
||||
|
||||
|
||||
func test_add_test_suites():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
# skip should have no affect
|
||||
config.skip_test_suite("res://bar")
|
||||
|
||||
config.add_test_suites(PackedStringArray(["res://foo2", "res://bar/foo", "res://foo1"]))
|
||||
|
||||
assert_dict(config.to_execute())\
|
||||
.contains_key_value("res://foo1", PackedStringArray())\
|
||||
.contains_key_value("res://foo2", PackedStringArray())\
|
||||
.contains_key_value("res://bar/foo", PackedStringArray())
|
||||
|
||||
|
||||
func test_add_test_case():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
# skip should have no affect
|
||||
config.skip_test_suite("res://bar")
|
||||
|
||||
config.add_test_case("res://foo1", "testcaseA")
|
||||
assert_dict(config.to_execute()).contains_key_value("res://foo1", PackedStringArray(["testcaseA"]))
|
||||
# add two more
|
||||
config.add_test_case("res://foo1", "testcaseB")
|
||||
config.add_test_case("res://foo2", "testcaseX")
|
||||
assert_dict(config.to_execute())\
|
||||
.contains_key_value("res://foo1", PackedStringArray(["testcaseA", "testcaseB"]))\
|
||||
.contains_key_value("res://foo2", PackedStringArray(["testcaseX"]))
|
||||
|
||||
|
||||
func test_add_test_suites_and_test_cases_combi():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
|
||||
config.add_test_suite("res://foo1")
|
||||
config.add_test_suite("res://foo2")
|
||||
config.add_test_suite("res://bar/foo")
|
||||
config.add_test_case("res://foo1", "testcaseA")
|
||||
config.add_test_case("res://foo1", "testcaseB")
|
||||
config.add_test_suites(PackedStringArray(["res://foo3", "res://bar/foo3", "res://foo4"]))
|
||||
|
||||
assert_dict(config.to_execute())\
|
||||
.has_size(6)\
|
||||
.contains_key_value("res://foo1", PackedStringArray(["testcaseA", "testcaseB"]))\
|
||||
.contains_key_value("res://foo2", PackedStringArray())\
|
||||
.contains_key_value("res://foo3", PackedStringArray())\
|
||||
.contains_key_value("res://foo4", PackedStringArray())\
|
||||
.contains_key_value("res://bar/foo3", PackedStringArray())\
|
||||
.contains_key_value("res://bar/foo", PackedStringArray())
|
||||
|
||||
|
||||
func test_skip_test_suite():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
|
||||
config.skip_test_suite("res://foo1")
|
||||
assert_dict(config.skipped()).contains_key_value("res://foo1", PackedStringArray())
|
||||
# add two more
|
||||
config.skip_test_suite("res://foo2")
|
||||
config.skip_test_suite("res://bar/foo1")
|
||||
assert_dict(config.skipped())\
|
||||
.contains_key_value("res://foo1", PackedStringArray())\
|
||||
.contains_key_value("res://foo2", PackedStringArray())\
|
||||
.contains_key_value("res://bar/foo1", PackedStringArray())
|
||||
|
||||
|
||||
func test_skip_test_suite_and_test_case():
|
||||
var possible_paths :PackedStringArray = [
|
||||
"/foo/MyTest.gd",
|
||||
"res://foo/MyTest.gd",
|
||||
"/foo/MyTest.gd:test_x",
|
||||
"res://foo/MyTest.gd:test_y",
|
||||
"MyTest",
|
||||
"MyTest:test",
|
||||
"MyTestX",
|
||||
]
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
for path in possible_paths:
|
||||
config.skip_test_suite(path)
|
||||
assert_dict(config.skipped())\
|
||||
.has_size(3)\
|
||||
.contains_key_value("res://foo/MyTest.gd", PackedStringArray(["test_x", "test_y"]))\
|
||||
.contains_key_value("MyTest", PackedStringArray(["test"]))\
|
||||
.contains_key_value("MyTestX", PackedStringArray())
|
||||
|
||||
|
||||
func test_skip_test_case():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
|
||||
config.skip_test_case("res://foo1", "testcaseA")
|
||||
assert_dict(config.skipped()).contains_key_value("res://foo1", PackedStringArray(["testcaseA"]))
|
||||
# add two more
|
||||
config.skip_test_case("res://foo1", "testcaseB")
|
||||
config.skip_test_case("res://foo2", "testcaseX")
|
||||
assert_dict(config.skipped())\
|
||||
.contains_key_value("res://foo1", PackedStringArray(["testcaseA", "testcaseB"]))\
|
||||
.contains_key_value("res://foo2", PackedStringArray(["testcaseX"]))
|
||||
|
||||
|
||||
func test_load_fail():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
|
||||
assert_result(config.load_config("invalid_path"))\
|
||||
.is_error()\
|
||||
.contains_message("Can't find test runner configuration 'invalid_path'! Please select a test to run.")
|
||||
|
||||
|
||||
func test_save_load():
|
||||
var config := GdUnitRunnerConfig.new()
|
||||
# add some dummy conf
|
||||
config.set_server_port(1000)
|
||||
config.skip_test_suite("res://bar")
|
||||
config.add_test_suite("res://foo2")
|
||||
config.add_test_case("res://foo1", "testcaseA")
|
||||
|
||||
var config_file := create_temp_dir("test_save_load") + "/testconf.cfg"
|
||||
|
||||
assert_result(config.save_config(config_file)).is_success()
|
||||
assert_file(config_file).exists()
|
||||
|
||||
var config2 := GdUnitRunnerConfig.new()
|
||||
assert_result(config2.load_config(config_file)).is_success()
|
||||
# verify the config has original enties
|
||||
assert_object(config2).is_equal(config).is_not_same(config)
|
||||
527
addons/gdUnit4/test/core/GdUnitSceneRunnerInputEventTest.gd
Normal file
527
addons/gdUnit4/test/core/GdUnitSceneRunnerInputEventTest.gd
Normal file
|
|
@ -0,0 +1,527 @@
|
|||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitSceneRunner.gd'
|
||||
|
||||
|
||||
var _runner :GdUnitSceneRunner
|
||||
var _scene_spy :Node
|
||||
|
||||
|
||||
func before_test():
|
||||
_scene_spy = spy("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
|
||||
_runner = scene_runner(_scene_spy)
|
||||
assert_inital_mouse_state()
|
||||
assert_inital_key_state()
|
||||
|
||||
|
||||
# asserts to KeyList Enums
|
||||
func assert_inital_key_state():
|
||||
# scacode 4194304-4194415
|
||||
for key in range(KEY_SPECIAL, KEY_LAUNCHF):
|
||||
assert_that(Input.is_key_pressed(key)).is_false()
|
||||
assert_that(Input.is_physical_key_pressed(key)).is_false()
|
||||
# keycode 32-255
|
||||
for key in range(KEY_SPACE, KEY_SECTION):
|
||||
assert_that(Input.is_key_pressed(key)).is_false()
|
||||
assert_that(Input.is_physical_key_pressed(key)).is_false()
|
||||
|
||||
|
||||
#asserts to Mouse ButtonList Enums
|
||||
func assert_inital_mouse_state():
|
||||
for button in [
|
||||
MOUSE_BUTTON_LEFT,
|
||||
MOUSE_BUTTON_MIDDLE,
|
||||
MOUSE_BUTTON_RIGHT,
|
||||
MOUSE_BUTTON_XBUTTON1,
|
||||
MOUSE_BUTTON_XBUTTON2,
|
||||
MOUSE_BUTTON_WHEEL_UP,
|
||||
MOUSE_BUTTON_WHEEL_DOWN,
|
||||
MOUSE_BUTTON_WHEEL_LEFT,
|
||||
MOUSE_BUTTON_WHEEL_RIGHT,
|
||||
]:
|
||||
assert_that(Input.is_mouse_button_pressed(button)).is_false()
|
||||
assert_that(Input.get_mouse_button_mask()).is_equal(0)
|
||||
|
||||
|
||||
func test_reset_to_inital_state_on_release():
|
||||
var runner = scene_runner("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
|
||||
# simulate mouse buttons and key press but we never released it
|
||||
runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
|
||||
runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
|
||||
runner.simulate_mouse_button_press(MOUSE_BUTTON_MIDDLE)
|
||||
runner.simulate_key_press(KEY_0)
|
||||
runner.simulate_key_press(KEY_X)
|
||||
await await_idle_frame()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_0)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_X)).is_true()
|
||||
# unreference the scene runner to enforce reset to initial Input state
|
||||
runner._notification(NOTIFICATION_PREDELETE)
|
||||
await await_idle_frame()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_false()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_false()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_MIDDLE)).is_false()
|
||||
assert_that(Input.is_key_pressed(KEY_0)).is_false()
|
||||
assert_that(Input.is_key_pressed(KEY_X)).is_false()
|
||||
|
||||
|
||||
func test_simulate_key_press() -> void:
|
||||
# iterate over some example keys
|
||||
for key in [KEY_A, KEY_D, KEY_X, KEY_0]:
|
||||
_runner.simulate_key_press(key)
|
||||
await await_idle_frame()
|
||||
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = key
|
||||
event.physical_keycode = key
|
||||
event.pressed = true
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_key_pressed(key)).is_true()
|
||||
# verify all this keys are still handled as pressed
|
||||
assert_that(Input.is_key_pressed(KEY_A)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_D)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_X)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_0)).is_true()
|
||||
# other keys are not pressed
|
||||
assert_that(Input.is_key_pressed(KEY_B)).is_false()
|
||||
assert_that(Input.is_key_pressed(KEY_G)).is_false()
|
||||
assert_that(Input.is_key_pressed(KEY_Z)).is_false()
|
||||
assert_that(Input.is_key_pressed(KEY_1)).is_false()
|
||||
|
||||
|
||||
func test_simulate_key_press_with_modifiers() -> void:
|
||||
# press shift key + A
|
||||
_runner.simulate_key_press(KEY_SHIFT)
|
||||
_runner.simulate_key_press(KEY_A)
|
||||
await await_idle_frame()
|
||||
|
||||
# results in two events, first is the shift key is press
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = KEY_SHIFT
|
||||
event.physical_keycode = KEY_SHIFT
|
||||
event.pressed = true
|
||||
event.shift_pressed = true
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
# second is the comnbination of current press shift and key A
|
||||
event = InputEventKey.new()
|
||||
event.keycode = KEY_A
|
||||
event.physical_keycode = KEY_A
|
||||
event.pressed = true
|
||||
event.shift_pressed = true
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_key_pressed(KEY_SHIFT)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_A)).is_true()
|
||||
|
||||
|
||||
func test_simulate_many_keys_press() -> void:
|
||||
# press and hold keys W and Z
|
||||
_runner.simulate_key_press(KEY_W)
|
||||
_runner.simulate_key_press(KEY_Z)
|
||||
await await_idle_frame()
|
||||
|
||||
assert_that(Input.is_key_pressed(KEY_W)).is_true()
|
||||
assert_that(Input.is_physical_key_pressed(KEY_W)).is_true()
|
||||
assert_that(Input.is_key_pressed(KEY_Z)).is_true()
|
||||
assert_that(Input.is_physical_key_pressed(KEY_Z)).is_true()
|
||||
|
||||
#now release key w
|
||||
_runner.simulate_key_release(KEY_W)
|
||||
await await_idle_frame()
|
||||
|
||||
assert_that(Input.is_key_pressed(KEY_W)).is_false()
|
||||
assert_that(Input.is_physical_key_pressed(KEY_W)).is_false()
|
||||
assert_that(Input.is_key_pressed(KEY_Z)).is_true()
|
||||
assert_that(Input.is_physical_key_pressed(KEY_Z)).is_true()
|
||||
|
||||
|
||||
func test_simulate_keypressed_as_action() -> void:
|
||||
# add custom action `player_jump` for key 'Space' is pressed
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = KEY_SPACE
|
||||
InputMap.add_action("player_jump")
|
||||
InputMap.action_add_event("player_jump", event)
|
||||
var runner := scene_runner("res://addons/gdUnit4/test/core/resources/scenes/input_actions/InputEventTestScene.tscn")
|
||||
|
||||
# precondition checks
|
||||
var action_event = InputMap.action_get_events("player_jump")
|
||||
assert_array(action_event).contains_exactly([event])
|
||||
assert_bool(Input.is_action_just_released("player_jump", true)).is_false()
|
||||
assert_bool(Input.is_action_just_released("ui_accept", true)).is_false()
|
||||
assert_bool(Input.is_action_just_released("ui_select", true)).is_false()
|
||||
assert_bool(runner.scene()._player_jump_action_released).is_false()
|
||||
|
||||
# test a key event is trigger action event
|
||||
# simulate press space
|
||||
runner.simulate_key_pressed(KEY_SPACE)
|
||||
# it is important do not wait for next frame here, otherwise the input action cache is cleared and can't be use to verify
|
||||
assert_bool(Input.is_action_just_released("player_jump", true)).is_true()
|
||||
assert_bool(Input.is_action_just_released("ui_accept", true)).is_true()
|
||||
assert_bool(Input.is_action_just_released("ui_select", true)).is_true()
|
||||
assert_bool(runner.scene()._player_jump_action_released).is_true()
|
||||
|
||||
# test a key event is not trigger the custom action event
|
||||
# simulate press only space+ctrl
|
||||
runner._reset_input_to_default()
|
||||
runner.simulate_key_pressed(KEY_SPACE, false, true)
|
||||
# it is important do not wait for next frame here, otherwise the input action cache is cleared and can't be use to verify
|
||||
assert_bool(Input.is_action_just_released("player_jump", true)).is_false()
|
||||
assert_bool(Input.is_action_just_released("ui_accept", true)).is_false()
|
||||
assert_bool(Input.is_action_just_released("ui_select", true)).is_false()
|
||||
assert_bool(runner.scene()._player_jump_action_released).is_false()
|
||||
|
||||
# cleanup custom action
|
||||
InputMap.erase_action("player_jump")
|
||||
InputMap.action_erase_events("player_jump")
|
||||
|
||||
|
||||
func test_simulate_set_mouse_pos():
|
||||
# save current global mouse pos
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
# set mouse to pos 100, 100
|
||||
_runner.set_mouse_pos(Vector2(100, 100))
|
||||
await await_idle_frame()
|
||||
var event := InputEventMouseMotion.new()
|
||||
event.position = Vector2(100, 100)
|
||||
event.global_position = gmp
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
# set mouse to pos 800, 400
|
||||
gmp = _runner.get_global_mouse_position()
|
||||
_runner.set_mouse_pos(Vector2(800, 400))
|
||||
await await_idle_frame()
|
||||
event = InputEventMouseMotion.new()
|
||||
event.position = Vector2(800, 400)
|
||||
event.global_position = gmp
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
# and again back to 100,100
|
||||
gmp = _runner.get_global_mouse_position()
|
||||
_runner.set_mouse_pos(Vector2(100, 100))
|
||||
await await_idle_frame()
|
||||
event = InputEventMouseMotion.new()
|
||||
event.position = Vector2(100, 100)
|
||||
event.global_position = gmp
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
|
||||
func test_simulate_set_mouse_pos_with_modifiers():
|
||||
var is_alt := false
|
||||
var is_control := false
|
||||
var is_shift := false
|
||||
|
||||
for modifier in [KEY_SHIFT, KEY_CTRL, KEY_ALT]:
|
||||
is_alt = is_alt or KEY_ALT == modifier
|
||||
is_control = is_control or KEY_CTRL == modifier
|
||||
is_shift = is_shift or KEY_SHIFT == modifier
|
||||
|
||||
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
|
||||
# simulate press shift, set mouse pos and final press mouse button
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_key_press(modifier)
|
||||
_runner.set_mouse_pos(Vector2.ZERO)
|
||||
_runner.simulate_mouse_button_press(mouse_button)
|
||||
await await_idle_frame()
|
||||
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.alt_pressed = is_alt
|
||||
event.ctrl_pressed = is_control
|
||||
event.shift_pressed = is_shift
|
||||
event.pressed = true
|
||||
event.button_index = mouse_button
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_true()
|
||||
# finally release it
|
||||
_runner.simulate_mouse_button_release(mouse_button)
|
||||
await await_idle_frame()
|
||||
|
||||
|
||||
func test_simulate_mouse_move():
|
||||
_runner.set_mouse_pos(Vector2(10, 10))
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_move(Vector2(400, 100))
|
||||
await await_idle_frame()
|
||||
|
||||
var event = InputEventMouseMotion.new()
|
||||
event.position = Vector2(400, 100)
|
||||
event.global_position = gmp
|
||||
event.relative = Vector2(400, 100) - Vector2(10, 10)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
# move mouse to next pos
|
||||
gmp = _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_move(Vector2(55, 42))
|
||||
await await_idle_frame()
|
||||
|
||||
event = InputEventMouseMotion.new()
|
||||
event.position = Vector2(55, 42)
|
||||
event.global_position = gmp
|
||||
event.relative = Vector2(55, 42) - Vector2(400, 100)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
|
||||
func test_simulate_mouse_move_relative():
|
||||
#OS.window_minimized = false
|
||||
_runner.set_mouse_pos(Vector2(10, 10))
|
||||
await await_idle_frame()
|
||||
assert_that(_runner.get_mouse_position()).is_equal(Vector2(10, 10))
|
||||
|
||||
# move the mouse in time of 1 second
|
||||
# the final position is current + relative = Vector2(10, 10) + (Vector2(900, 400)
|
||||
await _runner.simulate_mouse_move_relative(Vector2(900, 400), 1)
|
||||
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(910, 410), Vector2.ONE)
|
||||
|
||||
# move the mouse back in time of 0.1 second
|
||||
# Use the negative value of the previously moved action to move it back to the starting position
|
||||
await _runner.simulate_mouse_move_relative(Vector2(-900, -400), 0.1)
|
||||
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(10, 10), Vector2.ONE)
|
||||
|
||||
|
||||
func test_simulate_mouse_move_absolute():
|
||||
#OS.window_minimized = false
|
||||
_runner.set_mouse_pos(Vector2(10, 10))
|
||||
await await_idle_frame()
|
||||
assert_that(_runner.get_mouse_position()).is_equal(Vector2(10, 10))
|
||||
|
||||
# move the mouse in time of 1 second
|
||||
await _runner.simulate_mouse_move_absolute(Vector2(900, 400), 1)
|
||||
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(900, 400), Vector2.ONE)
|
||||
|
||||
# move the mouse back in time of 0.1 second
|
||||
await _runner.simulate_mouse_move_absolute(Vector2(10, 10), 0.1)
|
||||
assert_vector(_runner.get_mouse_position()).is_equal_approx(Vector2(10, 10), Vector2.ONE)
|
||||
|
||||
|
||||
func test_simulate_mouse_button_press_left():
|
||||
# simulate mouse button press and hold
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(MOUSE_BUTTON_LEFT)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
|
||||
|
||||
func test_simulate_mouse_button_press_left_doubleclick():
|
||||
# simulate mouse button press double_click
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT, true)
|
||||
await await_idle_frame()
|
||||
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.double_click = true
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(MOUSE_BUTTON_LEFT)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
|
||||
|
||||
func test_simulate_mouse_button_press_right():
|
||||
# simulate mouse button press and hold
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
|
||||
await await_idle_frame()
|
||||
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = MOUSE_BUTTON_RIGHT
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(MOUSE_BUTTON_RIGHT)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
|
||||
|
||||
|
||||
func test_simulate_mouse_button_press_left_and_right():
|
||||
# simulate mouse button press left+right
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
|
||||
await await_idle_frame()
|
||||
|
||||
# results in two events, first is left mouse button
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.button_mask = MOUSE_BUTTON_MASK_LEFT
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
# second is left+right and combined mask
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = MOUSE_BUTTON_RIGHT
|
||||
event.button_mask = MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
|
||||
assert_that(Input.get_mouse_button_mask()).is_equal(MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT)
|
||||
|
||||
|
||||
func test_simulate_mouse_button_press_left_and_right_and_release():
|
||||
# simulate mouse button press left+right
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
|
||||
_runner.simulate_mouse_button_press(MOUSE_BUTTON_RIGHT)
|
||||
await await_idle_frame()
|
||||
|
||||
# will results into two events
|
||||
# first for left mouse button
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.button_mask = MOUSE_BUTTON_MASK_LEFT
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
# second is left+right and combined mask
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = MOUSE_BUTTON_RIGHT
|
||||
event.button_mask = MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_true()
|
||||
assert_that(Input.get_mouse_button_mask()).is_equal(MOUSE_BUTTON_MASK_LEFT|MOUSE_BUTTON_MASK_RIGHT)
|
||||
|
||||
# now release the right button
|
||||
gmp = _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_pressed(MOUSE_BUTTON_RIGHT)
|
||||
await await_idle_frame()
|
||||
# will result in right button press false but stay with mask for left pressed
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = false
|
||||
event.button_index = MOUSE_BUTTON_RIGHT
|
||||
event.button_mask = MOUSE_BUTTON_MASK_LEFT
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_false()
|
||||
assert_that(Input.get_mouse_button_mask()).is_equal(MOUSE_BUTTON_MASK_LEFT)
|
||||
|
||||
# finally relase left button
|
||||
gmp = _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
# will result in right button press false but stay with mask for left pressed
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = false
|
||||
event.button_index = MOUSE_BUTTON_LEFT
|
||||
event.button_mask = 0
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_false()
|
||||
assert_that(Input.is_mouse_button_pressed(MOUSE_BUTTON_RIGHT)).is_false()
|
||||
assert_that(Input.get_mouse_button_mask()).is_equal(0)
|
||||
|
||||
|
||||
func test_simulate_mouse_button_pressed():
|
||||
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
|
||||
# simulate mouse button press and release
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_pressed(mouse_button)
|
||||
await await_idle_frame()
|
||||
|
||||
# it genrates two events, first for press and second as released
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = mouse_button
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = false
|
||||
event.button_index = mouse_button
|
||||
event.button_mask = 0
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false()
|
||||
verify(_scene_spy, 2)._input(any_class(InputEventMouseButton))
|
||||
reset(_scene_spy)
|
||||
|
||||
func test_simulate_mouse_button_pressed_doubleclick():
|
||||
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
|
||||
# simulate mouse button press and release by double_click
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_pressed(mouse_button, true)
|
||||
await await_idle_frame()
|
||||
|
||||
# it genrates two events, first for press and second as released
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.double_click = true
|
||||
event.button_index = mouse_button
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = false
|
||||
event.double_click = false
|
||||
event.button_index = mouse_button
|
||||
event.button_mask = 0
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false()
|
||||
verify(_scene_spy, 2)._input(any_class(InputEventMouseButton))
|
||||
reset(_scene_spy)
|
||||
|
||||
|
||||
func test_simulate_mouse_button_press_and_release():
|
||||
for mouse_button in [MOUSE_BUTTON_LEFT, MOUSE_BUTTON_MIDDLE, MOUSE_BUTTON_RIGHT]:
|
||||
var gmp := _runner.get_global_mouse_position()
|
||||
# simulate mouse button press and release
|
||||
_runner.simulate_mouse_button_press(mouse_button)
|
||||
await await_idle_frame()
|
||||
|
||||
var event := InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = true
|
||||
event.button_index = mouse_button
|
||||
event.button_mask = GdUnitSceneRunnerImpl.MAP_MOUSE_BUTTON_MASKS.get(mouse_button)
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_true()
|
||||
|
||||
# now simulate mouse button release
|
||||
gmp = _runner.get_global_mouse_position()
|
||||
_runner.simulate_mouse_button_release(mouse_button)
|
||||
await await_idle_frame()
|
||||
|
||||
event = InputEventMouseButton.new()
|
||||
event.position = Vector2.ZERO
|
||||
event.global_position = gmp
|
||||
event.pressed = false
|
||||
event.button_index = mouse_button
|
||||
#event.button_mask = 0
|
||||
verify(_scene_spy, 1)._input(event)
|
||||
assert_that(Input.is_mouse_button_pressed(mouse_button)).is_false()
|
||||
356
addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd
Normal file
356
addons/gdUnit4/test/core/GdUnitSceneRunnerTest.gd
Normal file
|
|
@ -0,0 +1,356 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitSceneRunnerTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitSceneRunnerImpl.gd'
|
||||
|
||||
|
||||
# loads the test runner and register for auto freeing after test
|
||||
func load_test_scene() -> Node:
|
||||
return auto_free(load("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn").instantiate())
|
||||
|
||||
|
||||
func before():
|
||||
# use a dedicated FPS because we calculate frames by time
|
||||
Engine.set_max_fps(60)
|
||||
|
||||
|
||||
func after():
|
||||
Engine.set_max_fps(0)
|
||||
|
||||
|
||||
func test_get_property() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
|
||||
assert_that(runner.get_property("_box1")).is_instanceof(ColorRect)
|
||||
assert_that(runner.get_property("_invalid")).is_equal("The property '_invalid' not exist checked loaded scene.")
|
||||
assert_that(runner.get_property("_nullable")).is_null()
|
||||
|
||||
|
||||
func test_set_property() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
|
||||
assert_that(runner.set_property("_invalid", 42)).is_equal(false)
|
||||
|
||||
assert_that(runner.set_property("_nullable", RefCounted.new())).is_equal(true)
|
||||
assert_that(runner.get_property("_nullable")).is_instanceof(RefCounted)
|
||||
|
||||
func test_invoke_method() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
|
||||
assert_that(runner.invoke("add", 10, 12)).is_equal(22)
|
||||
assert_that(runner.invoke("sub", 10, 12)).is_equal("The method 'sub' not exist checked loaded scene.")
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_simulate_frames(timeout = 5000) -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
var box1 :ColorRect = runner.get_property("_box1")
|
||||
# initial is white
|
||||
assert_object(box1.color).is_equal(Color.WHITE)
|
||||
|
||||
# start color cycle by invoke the function 'start_color_cycle'
|
||||
runner.invoke("start_color_cycle")
|
||||
|
||||
# we wait for 10 frames
|
||||
await runner.simulate_frames(10)
|
||||
# after 10 frame is still white
|
||||
assert_object(box1.color).is_equal(Color.WHITE)
|
||||
|
||||
# we wait 30 more frames
|
||||
await runner.simulate_frames(30)
|
||||
# after 40 frames the box one should be changed to red
|
||||
assert_object(box1.color).is_equal(Color.RED)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_simulate_frames_withdelay(timeout = 4000) -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
var box1 :ColorRect = runner.get_property("_box1")
|
||||
# initial is white
|
||||
assert_object(box1.color).is_equal(Color.WHITE)
|
||||
|
||||
# start color cycle by invoke the function 'start_color_cycle'
|
||||
runner.invoke("start_color_cycle")
|
||||
|
||||
# we wait for 10 frames each with a 50ms delay
|
||||
await runner.simulate_frames(10, 50)
|
||||
# after 10 frame and in sum 500ms is should be changed to red
|
||||
assert_object(box1.color).is_equal(Color.RED)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_run_scene_colorcycle(timeout=2000) -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
var box1 :ColorRect = runner.get_property("_box1")
|
||||
# verify inital color
|
||||
assert_object(box1.color).is_equal(Color.WHITE)
|
||||
|
||||
# start color cycle by invoke the function 'start_color_cycle'
|
||||
runner.invoke("start_color_cycle")
|
||||
|
||||
# await for each color cycle is emited
|
||||
await runner.await_signal("panel_color_change", [box1, Color.RED])
|
||||
assert_object(box1.color).is_equal(Color.RED)
|
||||
await runner.await_signal("panel_color_change", [box1, Color.BLUE])
|
||||
assert_object(box1.color).is_equal(Color.BLUE)
|
||||
await runner.await_signal("panel_color_change", [box1, Color.GREEN])
|
||||
assert_object(box1.color).is_equal(Color.GREEN)
|
||||
|
||||
|
||||
func test_simulate_scene_inteaction_by_press_enter(timeout=2000) -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
|
||||
# inital no spell is fired
|
||||
assert_object(runner.find_child("Spell")).is_null()
|
||||
|
||||
# fire spell be pressing enter key
|
||||
runner.simulate_key_pressed(KEY_ENTER)
|
||||
# wait until next frame
|
||||
await await_idle_frame()
|
||||
|
||||
# verify a spell is created
|
||||
assert_object(runner.find_child("Spell")).is_not_null()
|
||||
|
||||
# wait until spell is explode after around 1s
|
||||
var spell = runner.find_child("Spell")
|
||||
if spell == null:
|
||||
return
|
||||
await await_signal_on(spell, "spell_explode", [spell], timeout)
|
||||
|
||||
# verify spell is removed when is explode
|
||||
assert_object(runner.find_child("Spell")).is_null()
|
||||
|
||||
|
||||
# mock on a runner and spy on created spell
|
||||
func test_simulate_scene_inteaction_in_combination_with_spy():
|
||||
var spy_ = spy(load_test_scene())
|
||||
# create a runner runner
|
||||
var runner := scene_runner(spy_)
|
||||
|
||||
# simulate a key event to fire a spell
|
||||
runner.simulate_key_pressed(KEY_ENTER)
|
||||
verify(spy_).create_spell()
|
||||
|
||||
var spell = runner.find_child("Spell")
|
||||
assert_that(spell).is_not_null()
|
||||
assert_that(spell.is_connected("spell_explode", Callable(spy_, "_destroy_spell"))).is_true()
|
||||
|
||||
|
||||
func test_simulate_scene_interact_with_buttons():
|
||||
var spyed_scene = spy("res://addons/gdUnit4/test/mocker/resources/scenes/TestScene.tscn")
|
||||
var runner := scene_runner(spyed_scene)
|
||||
# test button 1 interaction
|
||||
await await_millis(1000)
|
||||
runner.set_mouse_pos(Vector2(60, 20))
|
||||
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box1, Color.RED)
|
||||
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box1, Color.GRAY)
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box2, any_color())
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box3, any_color())
|
||||
|
||||
# test button 2 interaction
|
||||
reset(spyed_scene)
|
||||
await await_millis(1000)
|
||||
runner.set_mouse_pos(Vector2(160, 20))
|
||||
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box1, any_color())
|
||||
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box2, Color.RED)
|
||||
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box2, Color.GRAY)
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box3, any_color())
|
||||
|
||||
# test button 3 interaction (is changed after 1s to gray)
|
||||
reset(spyed_scene)
|
||||
await await_millis(1000)
|
||||
runner.set_mouse_pos(Vector2(260, 20))
|
||||
runner.simulate_mouse_button_pressed(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box1, any_color())
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box2, any_color())
|
||||
# is changed to red
|
||||
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box3, Color.RED)
|
||||
# no gray
|
||||
verify(spyed_scene, 0)._on_panel_color_changed(spyed_scene._box3, Color.GRAY)
|
||||
# after one second is changed to gray
|
||||
await await_millis(1200)
|
||||
verify(spyed_scene)._on_panel_color_changed(spyed_scene._box3, Color.GRAY)
|
||||
|
||||
|
||||
func test_await_func_without_time_factor() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
await runner.await_func("color_cycle").is_equal("black")
|
||||
|
||||
|
||||
func test_await_func_with_time_factor() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
|
||||
# set max time factor to minimize waiting time checked `runner.wait_func`
|
||||
runner.set_time_factor(10)
|
||||
await runner.await_func("color_cycle").wait_until(200).is_equal("black")
|
||||
|
||||
|
||||
func test_await_signal_without_time_factor() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
var box1 :ColorRect = runner.get_property("_box1")
|
||||
|
||||
runner.invoke("start_color_cycle")
|
||||
await runner.await_signal("panel_color_change", [box1, Color.RED])
|
||||
await runner.await_signal("panel_color_change", [box1, Color.BLUE])
|
||||
await runner.await_signal("panel_color_change", [box1, Color.GREEN])
|
||||
(
|
||||
# should be interrupted is will never change to Color.KHAKI
|
||||
await assert_failure_await(func x(): await runner.await_signal( "panel_color_change", [box1, Color.KHAKI], 300))
|
||||
).has_message("await_signal_on(panel_color_change, [%s, %s]) timed out after 300ms" % [str(box1), str(Color.KHAKI)])\
|
||||
.has_line(205)
|
||||
|
||||
|
||||
func test_await_signal_with_time_factor() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
var box1 :ColorRect = runner.get_property("_box1")
|
||||
# set max time factor to minimize waiting time checked `runner.wait_func`
|
||||
runner.set_time_factor(10)
|
||||
runner.invoke("start_color_cycle")
|
||||
|
||||
await runner.await_signal("panel_color_change", [box1, Color.RED], 100)
|
||||
await runner.await_signal("panel_color_change", [box1, Color.BLUE], 100)
|
||||
await runner.await_signal("panel_color_change", [box1, Color.GREEN], 100)
|
||||
(
|
||||
# should be interrupted is will never change to Color.KHAKI
|
||||
await assert_failure_await(func x(): await runner.await_signal("panel_color_change", [box1, Color.KHAKI], 30))
|
||||
).has_message("await_signal_on(panel_color_change, [%s, %s]) timed out after 30ms" % [str(box1), str(Color.KHAKI)])\
|
||||
.has_line(222)
|
||||
|
||||
|
||||
func test_simulate_until_signal() -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
var box1 :ColorRect = runner.get_property("_box1")
|
||||
|
||||
# set max time factor to minimize waiting time checked `runner.wait_func`
|
||||
runner.invoke("start_color_cycle")
|
||||
|
||||
await runner.simulate_until_signal("panel_color_change", box1, Color.RED)
|
||||
await runner.simulate_until_signal("panel_color_change", box1, Color.BLUE)
|
||||
await runner.simulate_until_signal("panel_color_change", box1, Color.GREEN)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_simulate_until_object_signal(timeout=2000) -> void:
|
||||
var runner := scene_runner(load_test_scene())
|
||||
|
||||
# inital no spell is fired
|
||||
assert_object(runner.find_child("Spell")).is_null()
|
||||
|
||||
# fire spell be pressing enter key
|
||||
runner.simulate_key_pressed(KEY_ENTER)
|
||||
# wait until next frame
|
||||
await await_idle_frame()
|
||||
var spell = runner.find_child("Spell")
|
||||
prints(spell)
|
||||
|
||||
# simmulate scene until the spell is explode
|
||||
await runner.simulate_until_object_signal(spell, "spell_explode", spell)
|
||||
|
||||
# verify spell is removed when is explode
|
||||
assert_object(runner.find_child("Spell")).is_null()
|
||||
|
||||
|
||||
func test_runner_by_null_instance() -> void:
|
||||
var runner := scene_runner(null)
|
||||
assert_object(runner._current_scene).is_null()
|
||||
|
||||
|
||||
func test_runner_by_invalid_resource_path() -> void:
|
||||
# not existing scene
|
||||
assert_object(scene_runner("res://test_scene.tscn")._current_scene).is_null()
|
||||
# not a path to a scene
|
||||
assert_object(scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.gd")._current_scene).is_null()
|
||||
|
||||
|
||||
func test_runner_by_resource_path() -> void:
|
||||
var runner = scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn")
|
||||
assert_object(runner.scene()).is_instanceof(Node2D)
|
||||
|
||||
# verify the scene is freed when the runner is freed
|
||||
var scene = runner.scene()
|
||||
assert_bool(is_instance_valid(scene)).is_true()
|
||||
runner._notification(NOTIFICATION_PREDELETE)
|
||||
# give engine time to free the resources
|
||||
await await_idle_frame()
|
||||
# verify runner and scene is freed
|
||||
assert_bool(is_instance_valid(scene)).is_false()
|
||||
|
||||
|
||||
func test_runner_by_invalid_scene_instance() -> void:
|
||||
var scene = RefCounted.new()
|
||||
var runner := scene_runner(scene)
|
||||
assert_object(runner._current_scene).is_null()
|
||||
|
||||
|
||||
func test_runner_by_scene_instance() -> void:
|
||||
var scene = load("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn").instantiate()
|
||||
var runner := scene_runner(scene)
|
||||
assert_object(runner.scene()).is_instanceof(Node2D)
|
||||
|
||||
# verify the scene is freed when the runner is freed
|
||||
runner._notification(NOTIFICATION_PREDELETE)
|
||||
# give engine time to free the resources
|
||||
await await_idle_frame()
|
||||
# scene runner using external scene do not free the scene at exit
|
||||
assert_bool(is_instance_valid(scene)).is_true()
|
||||
# needs to be manually freed
|
||||
scene.free()
|
||||
|
||||
|
||||
func test_mouse_drag_and_drop() -> void:
|
||||
var spy_scene = spy("res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropTestScene.tscn")
|
||||
var runner := scene_runner(spy_scene)
|
||||
|
||||
var slot_left :TextureRect = $"/root/DragAndDropScene/left/TextureRect"
|
||||
var slot_right :TextureRect = $"/root/DragAndDropScene/right/TextureRect"
|
||||
|
||||
var save_mouse_pos := get_tree().root.get_mouse_position()
|
||||
# set inital mouse pos over the left slot
|
||||
var mouse_pos := slot_left.global_position + Vector2(10, 10)
|
||||
runner.set_mouse_pos(mouse_pos)
|
||||
await await_millis(1000)
|
||||
|
||||
await await_idle_frame()
|
||||
var event := InputEventMouseMotion.new()
|
||||
event.position = mouse_pos
|
||||
event.global_position = save_mouse_pos
|
||||
verify(spy_scene, 1)._gui_input(event)
|
||||
|
||||
runner.simulate_mouse_button_press(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
assert_bool(Input.is_mouse_button_pressed(MOUSE_BUTTON_LEFT)).is_true()
|
||||
|
||||
# start drag&drop to left pannel
|
||||
for i in 20:
|
||||
runner.simulate_mouse_move(mouse_pos + Vector2(i*.5*i, 0))
|
||||
await await_millis(40)
|
||||
|
||||
runner.simulate_mouse_button_release(MOUSE_BUTTON_LEFT)
|
||||
await await_idle_frame()
|
||||
assert_that(slot_right.texture).is_equal(slot_left.texture)
|
||||
|
||||
|
||||
func test_runner_GD_356() -> void:
|
||||
# to avoid reporting the expected push_error as test failure we disable it
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_PUSH_ERRORS, false)
|
||||
var runner = scene_runner("res://addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn")
|
||||
var player = runner.invoke("find_child", "Player", true, false)
|
||||
assert_that(player).is_not_null()
|
||||
await assert_func(player, "is_on_floor").wait_until(500).is_true()
|
||||
assert_that(runner.scene()).is_not_null()
|
||||
# run simulate_mouse_move_relative without await to reproduce https://github.com/MikeSchulze/gdUnit4/issues/356
|
||||
# this results into releasing the scene while `simulate_mouse_move_relative` is processing the mouse move
|
||||
runner.simulate_mouse_move_relative(Vector2(100, 100), 1.0)
|
||||
assert_that(runner.scene()).is_not_null()
|
||||
|
||||
|
||||
# we override the scene runner function for test purposes to hide push_error notifications
|
||||
func scene_runner(scene, verbose := false) -> GdUnitSceneRunner:
|
||||
return auto_free(GdUnitSceneRunnerImpl.new(scene, verbose, true))
|
||||
155
addons/gdUnit4/test/core/GdUnitSettingsTest.gd
Normal file
155
addons/gdUnit4/test/core/GdUnitSettingsTest.gd
Normal file
|
|
@ -0,0 +1,155 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitSettingsTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitSettings.gd'
|
||||
|
||||
const MAIN_CATEGORY = "unit_test"
|
||||
const CATEGORY_A = MAIN_CATEGORY + "/category_a"
|
||||
const CATEGORY_B = MAIN_CATEGORY + "/category_b"
|
||||
const TEST_PROPERTY_A = CATEGORY_A + "/a/prop_a"
|
||||
const TEST_PROPERTY_B = CATEGORY_A + "/a/prop_b"
|
||||
const TEST_PROPERTY_C = CATEGORY_A + "/a/prop_c"
|
||||
const TEST_PROPERTY_D = CATEGORY_B + "/prop_d"
|
||||
const TEST_PROPERTY_E = CATEGORY_B + "/c/prop_e"
|
||||
const TEST_PROPERTY_F = CATEGORY_B + "/c/prop_f"
|
||||
const TEST_PROPERTY_G = CATEGORY_B + "/a/prop_g"
|
||||
|
||||
|
||||
func before() -> void:
|
||||
GdUnitSettings.dump_to_tmp()
|
||||
|
||||
|
||||
func after() -> void:
|
||||
GdUnitSettings.restore_dump_from_tmp()
|
||||
|
||||
|
||||
func before_test() -> void:
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_A, true, "helptext TEST_PROPERTY_A.")
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_B, false, "helptext TEST_PROPERTY_B.")
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_C, 100, "helptext TEST_PROPERTY_C.")
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_D, true, "helptext TEST_PROPERTY_D.")
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_E, false, "helptext TEST_PROPERTY_E.")
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_F, "abc", "helptext TEST_PROPERTY_F.")
|
||||
GdUnitSettings.create_property_if_need(TEST_PROPERTY_G, 200, "helptext TEST_PROPERTY_G.")
|
||||
|
||||
|
||||
func after_test() -> void:
|
||||
ProjectSettings.clear(TEST_PROPERTY_A)
|
||||
ProjectSettings.clear(TEST_PROPERTY_B)
|
||||
ProjectSettings.clear(TEST_PROPERTY_C)
|
||||
ProjectSettings.clear(TEST_PROPERTY_D)
|
||||
ProjectSettings.clear(TEST_PROPERTY_E)
|
||||
ProjectSettings.clear(TEST_PROPERTY_F)
|
||||
ProjectSettings.clear(TEST_PROPERTY_G)
|
||||
|
||||
|
||||
func test_list_settings() -> void:
|
||||
var settingsA := GdUnitSettings.list_settings(CATEGORY_A)
|
||||
assert_array(settingsA).extractv(extr("name"), extr("type"), extr("value"), extr("default"), extr("help"))\
|
||||
.contains_exactly_in_any_order([
|
||||
tuple(TEST_PROPERTY_A, TYPE_BOOL, true, true, "helptext TEST_PROPERTY_A."),
|
||||
tuple(TEST_PROPERTY_B, TYPE_BOOL,false, false, "helptext TEST_PROPERTY_B."),
|
||||
tuple(TEST_PROPERTY_C, TYPE_INT, 100, 100, "helptext TEST_PROPERTY_C.")
|
||||
])
|
||||
var settingsB := GdUnitSettings.list_settings(CATEGORY_B)
|
||||
assert_array(settingsB).extractv(extr("name"), extr("type"), extr("value"), extr("default"), extr("help"))\
|
||||
.contains_exactly_in_any_order([
|
||||
tuple(TEST_PROPERTY_D, TYPE_BOOL, true, true, "helptext TEST_PROPERTY_D."),
|
||||
tuple(TEST_PROPERTY_E, TYPE_BOOL, false, false, "helptext TEST_PROPERTY_E."),
|
||||
tuple(TEST_PROPERTY_F, TYPE_STRING, "abc", "abc", "helptext TEST_PROPERTY_F."),
|
||||
tuple(TEST_PROPERTY_G, TYPE_INT, 200, 200, "helptext TEST_PROPERTY_G.")
|
||||
])
|
||||
|
||||
|
||||
func test_enum_property() -> void:
|
||||
var value_set :PackedStringArray = GdUnitSettings.NAMING_CONVENTIONS.keys()
|
||||
GdUnitSettings.create_property_if_need("test/enum", GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT, "help", value_set)
|
||||
|
||||
var property := GdUnitSettings.get_property("test/enum")
|
||||
assert_that(property.default()).is_equal(GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
|
||||
assert_that(property.value()).is_equal(GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
|
||||
assert_that(property.type()).is_equal(TYPE_INT)
|
||||
assert_that(property.help()).is_equal('help ["AUTO_DETECT", "SNAKE_CASE", "PASCAL_CASE"]')
|
||||
assert_that(property.value_set()).is_equal(value_set)
|
||||
|
||||
|
||||
func test_migrate_property_change_key() -> void:
|
||||
# setup old property
|
||||
var old_property_X = "/category_patch/group_old/name"
|
||||
var new_property_X = "/category_patch/group_new/name"
|
||||
GdUnitSettings.create_property_if_need(old_property_X, "foo")
|
||||
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_equal("foo")
|
||||
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_null()
|
||||
var old_property := GdUnitSettings.get_property(old_property_X)
|
||||
|
||||
# migrate
|
||||
GdUnitSettings.migrate_property(old_property.name(),\
|
||||
new_property_X,\
|
||||
old_property.default(),\
|
||||
old_property.help())
|
||||
|
||||
var new_property := GdUnitSettings.get_property(new_property_X)
|
||||
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_null()
|
||||
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_equal("foo")
|
||||
assert_object(new_property).is_not_equal(old_property)
|
||||
assert_str(new_property.value()).is_equal(old_property.value())
|
||||
assert_array(new_property.value_set()).is_equal(old_property.value_set())
|
||||
assert_int(new_property.type()).is_equal(old_property.type())
|
||||
assert_str(new_property.default()).is_equal(old_property.default())
|
||||
assert_str(new_property.help()).is_equal(old_property.help())
|
||||
|
||||
# cleanup
|
||||
ProjectSettings.clear(new_property_X)
|
||||
|
||||
|
||||
func test_migrate_property_change_value() -> void:
|
||||
# setup old property
|
||||
var old_property_X = "/category_patch/group_old/name"
|
||||
var new_property_X = "/category_patch/group_new/name"
|
||||
GdUnitSettings.create_property_if_need(old_property_X, "foo", "help to foo")
|
||||
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_equal("foo")
|
||||
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_null()
|
||||
var old_property := GdUnitSettings.get_property(old_property_X)
|
||||
|
||||
# migrate property
|
||||
GdUnitSettings.migrate_property(old_property.name(),\
|
||||
new_property_X,\
|
||||
old_property.default(),\
|
||||
old_property.help(),\
|
||||
func(_value): return "bar")
|
||||
|
||||
var new_property := GdUnitSettings.get_property(new_property_X)
|
||||
assert_str(GdUnitSettings.get_setting(old_property_X, null)).is_null()
|
||||
assert_str(GdUnitSettings.get_setting(new_property_X, null)).is_equal("bar")
|
||||
assert_object(new_property).is_not_equal(old_property)
|
||||
assert_str(new_property.value()).is_equal("bar")
|
||||
assert_array(new_property.value_set()).is_equal(old_property.value_set())
|
||||
assert_int(new_property.type()).is_equal(old_property.type())
|
||||
assert_str(new_property.default()).is_equal(old_property.default())
|
||||
assert_str(new_property.help()).is_equal(old_property.help())
|
||||
# cleanup
|
||||
ProjectSettings.clear(new_property_X)
|
||||
|
||||
|
||||
const TEST_ROOT_FOLDER := "gdunit4/settings/test/test_root_folder"
|
||||
const HELP_TEST_ROOT_FOLDER := "Sets the root folder where test-suites located/generated."
|
||||
|
||||
func test_migrate_properties_v215() -> void:
|
||||
# rebuild original settings
|
||||
GdUnitSettings.create_property_if_need(TEST_ROOT_FOLDER, "test", HELP_TEST_ROOT_FOLDER)
|
||||
ProjectSettings.set_setting(TEST_ROOT_FOLDER, "xxx")
|
||||
|
||||
# migrate
|
||||
GdUnitSettings.migrate_properties()
|
||||
|
||||
# verify
|
||||
var property := GdUnitSettings.get_property(GdUnitSettings.TEST_LOOKUP_FOLDER)
|
||||
assert_str(property.value()).is_equal("xxx")
|
||||
assert_array(property.value_set()).is_empty()
|
||||
assert_int(property.type()).is_equal(TYPE_STRING)
|
||||
assert_str(property.default()).is_equal(GdUnitSettings.DEFAULT_TEST_LOOKUP_FOLDER)
|
||||
assert_str(property.help()).is_equal(GdUnitSettings.HELP_TEST_LOOKUP_FOLDER)
|
||||
assert_that(GdUnitSettings.get_property(TEST_ROOT_FOLDER)).is_null()
|
||||
ProjectSettings.clear(GdUnitSettings.TEST_LOOKUP_FOLDER)
|
||||
46
addons/gdUnit4/test/core/GdUnitSignalAwaiterTest.gd
Normal file
46
addons/gdUnit4/test/core/GdUnitSignalAwaiterTest.gd
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
# GdUnit generated TestSuite
|
||||
#warning-ignore-all:unused_argument
|
||||
#warning-ignore-all:return_value_discarded
|
||||
class_name GdUnitSignalAwaiterTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitSignalAwaiter.gd'
|
||||
|
||||
|
||||
class Monster extends Node:
|
||||
|
||||
signal move(value :float)
|
||||
signal slide(value, x, z )
|
||||
|
||||
var _pos :float = 0.0
|
||||
|
||||
func _process(_delta):
|
||||
_pos += 0.2
|
||||
emit_signal("move", _pos)
|
||||
emit_signal("slide", _pos, 1 , 2)
|
||||
|
||||
|
||||
func test_on_signal_with_single_arg() -> void:
|
||||
var monster = auto_free(Monster.new())
|
||||
add_child(monster)
|
||||
var signal_arg = await await_signal_on(monster, "move", [1.0])
|
||||
assert_float(signal_arg).is_equal(1.0)
|
||||
remove_child(monster)
|
||||
|
||||
|
||||
func test_on_signal_with_many_args() -> void:
|
||||
var monster = auto_free(Monster.new())
|
||||
add_child(monster)
|
||||
var signal_args = await await_signal_on(monster, "slide", [1.0, 1, 2])
|
||||
assert_array(signal_args).is_equal([1.0, 1, 2])
|
||||
remove_child(monster)
|
||||
|
||||
|
||||
func test_on_signal_fail() -> void:
|
||||
var monster = auto_free(Monster.new())
|
||||
add_child(monster)
|
||||
(
|
||||
await assert_failure_await( func x(): await await_signal_on(monster, "move", [4.0]))
|
||||
).has_message("await_signal_on(move, [4]) timed out after 2000ms")
|
||||
remove_child(monster)
|
||||
11
addons/gdUnit4/test/core/GdUnitSingletonTest.gd
Normal file
11
addons/gdUnit4/test/core/GdUnitSingletonTest.gd
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
func test_instance() -> void:
|
||||
var n = GdUnitSingleton.instance("singelton_test", func(): return Node.new() )
|
||||
assert_object(n).is_instanceof(Node)
|
||||
assert_bool(is_instance_valid(n)).is_true()
|
||||
|
||||
# free the singleton
|
||||
GdUnitSingleton.unregister("singelton_test")
|
||||
assert_bool(is_instance_valid(n)).is_false()
|
||||
65
addons/gdUnit4/test/core/GdUnitTestSuiteBuilderTest.gd
Normal file
65
addons/gdUnit4/test/core/GdUnitTestSuiteBuilderTest.gd
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# GdUnit generated TestSuite
|
||||
#warning-ignore-all:unused_argument
|
||||
#warning-ignore-all:return_value_discarded
|
||||
class_name GdUnitTestSuiteBuilderTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
|
||||
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitTestSuiteBuilder.gd'
|
||||
|
||||
var _example_source_gd :String
|
||||
|
||||
|
||||
func before_test():
|
||||
var temp := create_temp_dir("examples")
|
||||
var result := GdUnitFileAccess.copy_file("res://addons/gdUnit4/test/core/resources/sources/test_person.gd", temp)
|
||||
assert_result(result).is_success()
|
||||
_example_source_gd = result.value() as String
|
||||
|
||||
|
||||
func after_test():
|
||||
clean_temp_dir()
|
||||
|
||||
|
||||
func assert_tests(test_suite :Script) -> GdUnitArrayAssert:
|
||||
# needs to be reload to get fresh method list
|
||||
test_suite.reload()
|
||||
var methods := test_suite.get_script_method_list()
|
||||
var test_cases := Array()
|
||||
for method in methods:
|
||||
if method.name.begins_with("test_"):
|
||||
test_cases.append(method.name)
|
||||
return assert_array(test_cases)
|
||||
|
||||
|
||||
func test_create_gd_success() -> void:
|
||||
var source := load(_example_source_gd)
|
||||
|
||||
# create initial test suite based checked function selected by line 9
|
||||
var result := GdUnitTestSuiteBuilder.create(source, 9)
|
||||
|
||||
assert_result(result).is_success()
|
||||
var info := result.value() as Dictionary
|
||||
assert_str(info.get("path")).is_equal("user://tmp/test/examples/test_person_test.gd")
|
||||
assert_int(info.get("line")).is_equal(11)
|
||||
assert_tests(load(info.get("path"))).contains_exactly(["test_first_name"])
|
||||
|
||||
# create additional test checked existing suite based checked function selected by line 15
|
||||
result = GdUnitTestSuiteBuilder.create(source, 15)
|
||||
|
||||
assert_result(result).is_success()
|
||||
info = result.value() as Dictionary
|
||||
assert_str(info.get("path")).is_equal("user://tmp/test/examples/test_person_test.gd")
|
||||
assert_int(info.get("line")).is_equal(16)
|
||||
assert_tests(load(info.get("path"))).contains_exactly_in_any_order(["test_first_name", "test_fully_name"])
|
||||
|
||||
|
||||
func test_create_gd_fail() -> void:
|
||||
var source := load(_example_source_gd)
|
||||
|
||||
# attempt to create an initial test suite based checked the function selected in line 8, which has no function definition
|
||||
var result := GdUnitTestSuiteBuilder.create(source, 8)
|
||||
assert_result(result).is_error().contains_message("No function found at line: 8.")
|
||||
372
addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd
Normal file
372
addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd
Normal file
|
|
@ -0,0 +1,372 @@
|
|||
# GdUnit generated TestSuite
|
||||
#warning-ignore-all:unused_argument
|
||||
#warning-ignore-all:return_value_discarded
|
||||
class_name TestSuiteScannerTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitTestSuiteScanner.gd'
|
||||
|
||||
func before_test():
|
||||
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
|
||||
clean_temp_dir()
|
||||
|
||||
|
||||
func after():
|
||||
clean_temp_dir()
|
||||
|
||||
|
||||
func resolve_path(source_file :String) -> String:
|
||||
return GdUnitTestSuiteScanner.resolve_test_suite_path(source_file, "_test_")
|
||||
|
||||
|
||||
func test_resolve_test_suite_path_project() -> void:
|
||||
# if no `src` folder found use test folder as root
|
||||
assert_str(resolve_path("res://foo.gd")).is_equal("res://_test_/foo_test.gd")
|
||||
assert_str(resolve_path("res://project_name/module/foo.gd")).is_equal("res://_test_/project_name/module/foo_test.gd")
|
||||
# otherwise build relative to 'src'
|
||||
assert_str(resolve_path("res://src/foo.gd")).is_equal("res://_test_/foo_test.gd")
|
||||
assert_str(resolve_path("res://project_name/src/foo.gd")).is_equal("res://project_name/_test_/foo_test.gd")
|
||||
assert_str(resolve_path("res://project_name/src/module/foo.gd")).is_equal("res://project_name/_test_/module/foo_test.gd")
|
||||
|
||||
|
||||
func test_resolve_test_suite_path_plugins() -> void:
|
||||
assert_str(resolve_path("res://addons/plugin_a/foo.gd")).is_equal("res://addons/plugin_a/_test_/foo_test.gd")
|
||||
assert_str(resolve_path("res://addons/plugin_a/src/foo.gd")).is_equal("res://addons/plugin_a/_test_/foo_test.gd")
|
||||
|
||||
|
||||
func test_resolve_test_suite_path__no_test_root():
|
||||
# from a project path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/models/events/ModelChangedEvent.gd", ""))\
|
||||
.is_equal("res://project/src/models/events/ModelChangedEventTest.gd")
|
||||
# from a plugin path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/src/models/events/ModelChangedEvent.gd", ""))\
|
||||
.is_equal("res://addons/MyPlugin/src/models/events/ModelChangedEventTest.gd")
|
||||
# located in user path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/src/models/events/ModelChangedEvent.gd", ""))\
|
||||
.is_equal("user://project/src/models/events/ModelChangedEventTest.gd")
|
||||
|
||||
|
||||
func test_resolve_test_suite_path__path_contains_src_folder():
|
||||
# from a project path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/models/events/ModelChangedEvent.gd"))\
|
||||
.is_equal("res://project/test/models/events/ModelChangedEventTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/models/events/ModelChangedEvent.gd", "custom_test"))\
|
||||
.is_equal("res://project/custom_test/models/events/ModelChangedEventTest.gd")
|
||||
# from a plugin path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/src/models/events/ModelChangedEvent.gd"))\
|
||||
.is_equal("res://addons/MyPlugin/test/models/events/ModelChangedEventTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/src/models/events/ModelChangedEvent.gd", "custom_test"))\
|
||||
.is_equal("res://addons/MyPlugin/custom_test/models/events/ModelChangedEventTest.gd")
|
||||
# located in user path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/src/models/events/ModelChangedEvent.gd"))\
|
||||
.is_equal("user://project/test/models/events/ModelChangedEventTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/src/models/events/ModelChangedEvent.gd", "custom_test"))\
|
||||
.is_equal("user://project/custom_test/models/events/ModelChangedEventTest.gd")
|
||||
|
||||
|
||||
func test_resolve_test_suite_path__path_not_contains_src_folder():
|
||||
# from a project path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/models/events/ModelChangedEvent.gd"))\
|
||||
.is_equal("res://test/project/models/events/ModelChangedEventTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/models/events/ModelChangedEvent.gd", "custom_test"))\
|
||||
.is_equal("res://custom_test/project/models/events/ModelChangedEventTest.gd")
|
||||
# from a plugin path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/models/events/ModelChangedEvent.gd"))\
|
||||
.is_equal("res://addons/MyPlugin/test/models/events/ModelChangedEventTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/MyPlugin/models/events/ModelChangedEvent.gd", "custom_test"))\
|
||||
.is_equal("res://addons/MyPlugin/custom_test/models/events/ModelChangedEventTest.gd")
|
||||
# located in user path
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/models/events/ModelChangedEvent.gd"))\
|
||||
.is_equal("user://test/project/models/events/ModelChangedEventTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("user://project/models/events/ModelChangedEvent.gd", "custom_test"))\
|
||||
.is_equal("user://custom_test/project/models/events/ModelChangedEventTest.gd")
|
||||
|
||||
|
||||
func test_test_suite_exists():
|
||||
var path_exists := "res://addons/gdUnit4/test/resources/core/GeneratedPersonTest.gd"
|
||||
var path_not_exists := "res://addons/gdUnit4/test/resources/core/FamilyTest.gd"
|
||||
assert_that(GdUnitTestSuiteScanner.test_suite_exists(path_exists)).is_true()
|
||||
assert_that(GdUnitTestSuiteScanner.test_suite_exists(path_not_exists)).is_false()
|
||||
|
||||
|
||||
func test_test_case_exists():
|
||||
var test_suite_path := "res://addons/gdUnit4/test/resources/core/GeneratedPersonTest.gd"
|
||||
assert_that(GdUnitTestSuiteScanner.test_case_exists(test_suite_path, "name")).is_true()
|
||||
assert_that(GdUnitTestSuiteScanner.test_case_exists(test_suite_path, "last_name")).is_false()
|
||||
|
||||
|
||||
func test_create_test_suite_pascal_case_path():
|
||||
var temp_dir := create_temp_dir("TestSuiteScannerTest")
|
||||
# checked source with class_name is set
|
||||
var source_path := "res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd"
|
||||
var suite_path := temp_dir + "/test/MyClassTest1.gd"
|
||||
var result := GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
|
||||
assert_that(result.is_success()).is_true()
|
||||
assert_str(result.value()).is_equal(suite_path)
|
||||
assert_file(result.value()).exists()\
|
||||
.is_file()\
|
||||
.is_script()\
|
||||
.contains_exactly([
|
||||
"# GdUnit generated TestSuite",
|
||||
"class_name PascalCaseWithClassNameTest",
|
||||
"extends GdUnitTestSuite",
|
||||
"@warning_ignore('unused_parameter')",
|
||||
"@warning_ignore('return_value_discarded')",
|
||||
"",
|
||||
"# TestSuite generated from",
|
||||
"const __source = '%s'" % source_path,
|
||||
""])
|
||||
# checked source with class_name is NOT set
|
||||
source_path = "res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd"
|
||||
suite_path = temp_dir + "/test/MyClassTest2.gd"
|
||||
result = GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
|
||||
assert_that(result.is_success()).is_true()
|
||||
assert_str(result.value()).is_equal(suite_path)
|
||||
assert_file(result.value()).exists()\
|
||||
.is_file()\
|
||||
.is_script()\
|
||||
.contains_exactly([
|
||||
"# GdUnit generated TestSuite",
|
||||
"class_name PascalCaseWithoutClassNameTest",
|
||||
"extends GdUnitTestSuite",
|
||||
"@warning_ignore('unused_parameter')",
|
||||
"@warning_ignore('return_value_discarded')",
|
||||
"",
|
||||
"# TestSuite generated from",
|
||||
"const __source = '%s'" % source_path,
|
||||
""])
|
||||
|
||||
|
||||
func test_create_test_suite_snake_case_path():
|
||||
var temp_dir := create_temp_dir("TestSuiteScannerTest")
|
||||
# checked source with class_name is set
|
||||
var source_path :="res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd"
|
||||
var suite_path := temp_dir + "/test/my_class_test1.gd"
|
||||
var result := GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
|
||||
assert_that(result.is_success()).is_true()
|
||||
assert_str(result.value()).is_equal(suite_path)
|
||||
assert_file(result.value()).exists()\
|
||||
.is_file()\
|
||||
.is_script()\
|
||||
.contains_exactly([
|
||||
"# GdUnit generated TestSuite",
|
||||
"class_name SnakeCaseWithClassNameTest",
|
||||
"extends GdUnitTestSuite",
|
||||
"@warning_ignore('unused_parameter')",
|
||||
"@warning_ignore('return_value_discarded')",
|
||||
"",
|
||||
"# TestSuite generated from",
|
||||
"const __source = '%s'" % source_path,
|
||||
""])
|
||||
# checked source with class_name is NOT set
|
||||
source_path ="res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd"
|
||||
suite_path = temp_dir + "/test/my_class_test2.gd"
|
||||
result = GdUnitTestSuiteScanner.create_test_suite(suite_path, source_path)
|
||||
assert_that(result.is_success()).is_true()
|
||||
assert_str(result.value()).is_equal(suite_path)
|
||||
assert_file(result.value()).exists()\
|
||||
.is_file()\
|
||||
.is_script()\
|
||||
.contains_exactly([
|
||||
"# GdUnit generated TestSuite",
|
||||
"class_name SnakeCaseWithoutClassNameTest",
|
||||
"extends GdUnitTestSuite",
|
||||
"@warning_ignore('unused_parameter')",
|
||||
"@warning_ignore('return_value_discarded')",
|
||||
"",
|
||||
"# TestSuite generated from",
|
||||
"const __source = '%s'" % source_path,
|
||||
""])
|
||||
|
||||
|
||||
func test_create_test_case():
|
||||
# store test class checked temp dir
|
||||
var tmp_path := create_temp_dir("TestSuiteScannerTest")
|
||||
var source_path := "res://addons/gdUnit4/test/resources/core/Person.gd"
|
||||
# generate new test suite with test 'test_last_name()'
|
||||
var test_suite_path = tmp_path + "/test/PersonTest.gd"
|
||||
var result := GdUnitTestSuiteScanner.create_test_case(test_suite_path, "last_name", source_path)
|
||||
assert_that(result.is_success()).is_true()
|
||||
var info :Dictionary = result.value()
|
||||
assert_int(info.get("line")).is_equal(11)
|
||||
assert_file(info.get("path")).exists()\
|
||||
.is_file()\
|
||||
.is_script()\
|
||||
.contains_exactly([
|
||||
"# GdUnit generated TestSuite",
|
||||
"class_name PersonTest",
|
||||
"extends GdUnitTestSuite",
|
||||
"@warning_ignore('unused_parameter')",
|
||||
"@warning_ignore('return_value_discarded')",
|
||||
"",
|
||||
"# TestSuite generated from",
|
||||
"const __source = '%s'" % source_path,
|
||||
"",
|
||||
"",
|
||||
"func test_last_name() -> void:",
|
||||
" # remove this line and complete your test",
|
||||
" assert_not_yet_implemented()",
|
||||
""])
|
||||
# try to add again
|
||||
result = GdUnitTestSuiteScanner.create_test_case(test_suite_path, "last_name", source_path)
|
||||
assert_that(result.is_success()).is_true()
|
||||
assert_that(result.value()).is_equal({"line" : 16, "path": test_suite_path})
|
||||
|
||||
|
||||
# https://github.com/MikeSchulze/gdUnit4/issues/25
|
||||
func test_build_test_suite_path() -> void:
|
||||
# checked project root
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://new_script.gd")).is_equal("res://test/new_script_test.gd")
|
||||
|
||||
# checked project without src folder
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://foo/bar/new_script.gd")).is_equal("res://test/foo/bar/new_script_test.gd")
|
||||
|
||||
# project code structured by 'src'
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://src/new_script.gd")).is_equal("res://test/new_script_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://src/foo/bar/new_script.gd")).is_equal("res://test/foo/bar/new_script_test.gd")
|
||||
# folder name contains 'src' in name
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://foo/srcare/new_script.gd")).is_equal("res://test/foo/srcare/new_script_test.gd")
|
||||
|
||||
# checked plugins without src folder
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/plugin/foo/bar/new_script.gd")).is_equal("res://addons/plugin/test/foo/bar/new_script_test.gd")
|
||||
# plugin code structured by 'src'
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://addons/plugin/src/foo/bar/new_script.gd")).is_equal("res://addons/plugin/test/foo/bar/new_script_test.gd")
|
||||
|
||||
# checked user temp folder
|
||||
var tmp_path := create_temp_dir("projectX/entity")
|
||||
var source_path := tmp_path + "/Person.gd"
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path(source_path)).is_equal("user://tmp/test/projectX/entity/PersonTest.gd")
|
||||
|
||||
|
||||
func test_parse_and_add_test_cases() -> void:
|
||||
var default_time := GdUnitSettings.test_timeout()
|
||||
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
|
||||
# fake a test suite
|
||||
var test_suite :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
|
||||
test_suite.set_script( load("res://addons/gdUnit4/test/core/resources/test_script_with_arguments.gd"))
|
||||
|
||||
var test_case_names := PackedStringArray([
|
||||
"test_no_args",
|
||||
"test_with_timeout",
|
||||
"test_with_fuzzer",
|
||||
"test_with_fuzzer_iterations",
|
||||
"test_with_multible_fuzzers",
|
||||
"test_multiline_arguments_a",
|
||||
"test_multiline_arguments_b",
|
||||
"test_multiline_arguments_c"])
|
||||
scanner._parse_and_add_test_cases(test_suite, test_suite.get_script(), test_case_names)
|
||||
assert_array(test_suite.get_children())\
|
||||
.extractv(extr("get_name"), extr("timeout"), extr("fuzzer_arguments"), extr("iterations"))\
|
||||
.contains_exactly([
|
||||
tuple("test_no_args", default_time, [], Fuzzer.ITERATION_DEFAULT_COUNT),
|
||||
tuple("test_with_timeout", 2000, [], Fuzzer.ITERATION_DEFAULT_COUNT),
|
||||
tuple("test_with_fuzzer", default_time, [GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)")], Fuzzer.ITERATION_DEFAULT_COUNT),
|
||||
tuple("test_with_fuzzer_iterations", default_time, [GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)")], 10),
|
||||
tuple("test_with_multible_fuzzers", default_time, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 10),
|
||||
tuple("test_multiline_arguments_a", default_time, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 42),
|
||||
tuple("test_multiline_arguments_b", default_time, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 23),
|
||||
tuple("test_multiline_arguments_c", 2000, [GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(-10, 22)"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "Fuzzers.rangei(23, 42)")], 33)
|
||||
])
|
||||
|
||||
|
||||
func test_scan_by_inheritance_class_name() -> void:
|
||||
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
|
||||
var test_suites := scanner.scan("res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/")
|
||||
|
||||
assert_array(test_suites).has_size(3)
|
||||
# sort by names
|
||||
test_suites.sort_custom(func by_name(a, b): return a.get_name() <= b.get_name())
|
||||
assert_array(test_suites).extract("get_name")\
|
||||
.contains_exactly(["BaseTest", "ExtendedTest", "ExtendsExtendedTest"])
|
||||
assert_array(test_suites).extract("get_script.get_path")\
|
||||
.contains_exactly([
|
||||
"res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/BaseTest.gd",
|
||||
"res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/ExtendedTest.gd",
|
||||
"res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_name/ExtendsExtendedTest.gd"])
|
||||
assert_array(test_suites[0].get_children()).extract("name")\
|
||||
.contains_same_exactly_in_any_order([&"test_foo1"])
|
||||
assert_array(test_suites[1].get_children()).extract("name")\
|
||||
.contains_same_exactly_in_any_order([&"test_foo2", &"test_foo1"])
|
||||
assert_array(test_suites[2].get_children()).extract("name")\
|
||||
.contains_same_exactly_in_any_order([&"test_foo3", &"test_foo2", &"test_foo1"])
|
||||
# finally free all scaned test suites
|
||||
for ts in test_suites:
|
||||
ts.free()
|
||||
|
||||
|
||||
func test_scan_by_inheritance_class_path() -> void:
|
||||
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
|
||||
var test_suites := scanner.scan("res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/")
|
||||
|
||||
assert_array(test_suites).extractv(extr("get_name"), extr("get_script.get_path"), extr("get_children.get_name"))\
|
||||
.contains_exactly_in_any_order([
|
||||
tuple("BaseTest", "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/BaseTest.gd", [&"test_foo1"]),
|
||||
tuple("ExtendedTest","res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/ExtendedTest.gd", [&"test_foo2", &"test_foo1"]),
|
||||
tuple("ExtendsExtendedTest", "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/ExtendsExtendedTest.gd", [&"test_foo3", &"test_foo2", &"test_foo1"])
|
||||
])
|
||||
# finally free all scaned test suites
|
||||
for ts in test_suites:
|
||||
ts.free()
|
||||
|
||||
|
||||
func test_get_test_case_line_number() -> void:
|
||||
assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "get_test_case_line_number")).is_equal(317)
|
||||
assert_int(GdUnitTestSuiteScanner.get_test_case_line_number("res://addons/gdUnit4/test/core/GdUnitTestSuiteScannerTest.gd", "unknown")).is_equal(-1)
|
||||
|
||||
|
||||
func test__to_naming_convention() -> void:
|
||||
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.AUTO_DETECT)
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("MyClass")).is_equal("MyClassTest")
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("my_class")).is_equal("my_class_test")
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("myclass")).is_equal("myclass_test")
|
||||
|
||||
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.SNAKE_CASE)
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("MyClass")).is_equal("my_class_test")
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("my_class")).is_equal("my_class_test")
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("myclass")).is_equal("myclass_test")
|
||||
|
||||
ProjectSettings.set_setting(GdUnitSettings.TEST_SITE_NAMING_CONVENTION, GdUnitSettings.NAMING_CONVENTIONS.PASCAL_CASE)
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("MyClass")).is_equal("MyClassTest")
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("my_class")).is_equal("MyClassTest")
|
||||
assert_str(GdUnitTestSuiteScanner._to_naming_convention("myclass")).is_equal("MyclassTest")
|
||||
|
||||
|
||||
func test_is_script_format_supported() -> void:
|
||||
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.gd")).is_true()
|
||||
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.gdns")).is_false()
|
||||
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.vs")).is_false()
|
||||
assert_bool(GdUnitTestSuiteScanner._is_script_format_supported("res://exampe.tres")).is_false()
|
||||
|
||||
|
||||
func test_resolve_test_suite_path() -> void:
|
||||
# forcing the use of a test folder next to the source folder
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/myclass.gd", "test")).is_equal("res://project/test/folder/myclass_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/MyClass.gd", "test")).is_equal("res://project/test/folder/MyClassTest.gd")
|
||||
# forcing to use source directory to create the test
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/myclass.gd", "")).is_equal("res://project/src/folder/myclass_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/MyClass.gd", "")).is_equal("res://project/src/folder/MyClassTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/myclass.gd", "/")).is_equal("res://project/src/folder/myclass_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/src/folder/MyClass.gd", "/")).is_equal("res://project/src/folder/MyClassTest.gd")
|
||||
|
||||
|
||||
func test_resolve_test_suite_path_with_src_folders() -> void:
|
||||
# forcing the use of a test folder next
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/myclass.gd", "test")).is_equal("res://test/project/folder/myclass_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/MyClass.gd", "test")).is_equal("res://test/project/folder/MyClassTest.gd")
|
||||
# forcing to use source directory to create the test
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/myclass.gd", "")).is_equal("res://project/folder/myclass_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/MyClass.gd", "")).is_equal("res://project/folder/MyClassTest.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/myclass.gd", "/")).is_equal("res://project/folder/myclass_test.gd")
|
||||
assert_str(GdUnitTestSuiteScanner.resolve_test_suite_path("res://project/folder/MyClass.gd", "/")).is_equal("res://project/folder/MyClassTest.gd")
|
||||
|
||||
|
||||
func test_scan_test_suite_without_tests() -> void:
|
||||
var scanner :GdUnitTestSuiteScanner = auto_free(GdUnitTestSuiteScanner.new())
|
||||
var test_suites := scanner.scan("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteWithoutTests.gd")
|
||||
|
||||
assert_that(test_suites).is_empty()
|
||||
49
addons/gdUnit4/test/core/GdUnitToolsTest.gd
Normal file
49
addons/gdUnit4/test/core/GdUnitToolsTest.gd
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitToolsTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/GdUnitTools.gd'
|
||||
|
||||
|
||||
class InnerTestNodeClass extends Node:
|
||||
pass
|
||||
|
||||
class InnerTestRefCountedClass extends RefCounted:
|
||||
pass
|
||||
|
||||
|
||||
func test_free_instance() -> void:
|
||||
# on valid instances
|
||||
assert_that(await GdUnitTools.free_instance(RefCounted.new())).is_true()
|
||||
assert_that(await GdUnitTools.free_instance(Node.new())).is_true()
|
||||
assert_that(await GdUnitTools.free_instance(JavaClass.new())).is_true()
|
||||
assert_that(await GdUnitTools.free_instance(InnerTestNodeClass.new())).is_true()
|
||||
assert_that(await GdUnitTools.free_instance(InnerTestRefCountedClass.new())).is_true()
|
||||
|
||||
# on invalid instances
|
||||
assert_that(await GdUnitTools.free_instance(null)).is_false()
|
||||
assert_that(await GdUnitTools.free_instance(RefCounted)).is_false()
|
||||
|
||||
# on already freed instances
|
||||
var node := Node.new()
|
||||
node.free()
|
||||
assert_that(await GdUnitTools.free_instance(node)).is_false()
|
||||
|
||||
|
||||
func test_richtext_normalize() -> void:
|
||||
assert_that(GdUnitTools.richtext_normalize("")).is_equal("")
|
||||
assert_that(GdUnitTools.richtext_normalize("This is a Color Message")).is_equal("This is a Color Message")
|
||||
|
||||
var message = """
|
||||
[color=green]line [/color][color=aqua]11:[/color] [color=#CD5C5C]Expecting:[/color]
|
||||
must be empty but was
|
||||
'[color=#1E90FF]after[/color]'
|
||||
"""
|
||||
assert_that(GdUnitTools.richtext_normalize(message)).is_equal("""
|
||||
line 11: Expecting:
|
||||
must be empty but was
|
||||
'after'
|
||||
""")
|
||||
69
addons/gdUnit4/test/core/LocalTimeTest.gd
Normal file
69
addons/gdUnit4/test/core/LocalTimeTest.gd
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name LocalTimeTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/LocalTime.gd'
|
||||
|
||||
|
||||
func test_time_constants():
|
||||
assert_int(LocalTime.MILLIS_PER_HOUR).is_equal(1000*60*60)
|
||||
assert_int(LocalTime.MILLIS_PER_MINUTE).is_equal(1000*60)
|
||||
assert_int(LocalTime.MILLIS_PER_SECOND).is_equal(1000)
|
||||
assert_int(LocalTime.HOURS_PER_DAY).is_equal(24)
|
||||
assert_int(LocalTime.MINUTES_PER_HOUR).is_equal(60)
|
||||
assert_int(LocalTime.SECONDS_PER_MINUTE).is_equal(60)
|
||||
|
||||
|
||||
func test_now():
|
||||
var current := Time.get_datetime_dict_from_system(true)
|
||||
var local_time := LocalTime.now()
|
||||
assert_int(local_time.hour()).is_equal(current.get("hour"))
|
||||
assert_int(local_time.minute()).is_equal(current.get("minute"))
|
||||
assert_int(local_time.second()).is_equal(current.get("second"))
|
||||
# Time.get_datetime_dict_from_system() does not provide milliseconds
|
||||
#assert_that(local_time.millis()).is_equal(0)
|
||||
|
||||
|
||||
@warning_ignore("integer_division")
|
||||
func test_of_unix_time():
|
||||
var time := LocalTime._get_system_time_msecs()
|
||||
var local_time := LocalTime.of_unix_time(time)
|
||||
assert_int(local_time.hour()).is_equal((time / LocalTime.MILLIS_PER_HOUR) % 24)
|
||||
assert_int(local_time.minute()).is_equal((time / LocalTime.MILLIS_PER_MINUTE) % 60)
|
||||
assert_int(local_time.second()).is_equal((time / LocalTime.MILLIS_PER_SECOND) % 60)
|
||||
assert_int(local_time.millis()).is_equal(time % 1000)
|
||||
|
||||
|
||||
func test_to_string():
|
||||
assert_str(LocalTime.local_time(10, 12, 22, 333)._to_string()).is_equal("10:12:22.333")
|
||||
assert_str(LocalTime.local_time(23, 59, 59, 999)._to_string()).is_equal("23:59:59.999")
|
||||
assert_str(LocalTime.local_time( 0, 0, 0, 000)._to_string()).is_equal("00:00:00.000")
|
||||
assert_str(LocalTime.local_time( 2, 4, 3, 10)._to_string()).is_equal("02:04:03.010")
|
||||
|
||||
|
||||
func test_plus_seconds():
|
||||
var time := LocalTime.local_time(10, 12, 22, 333)
|
||||
assert_str(time.plus(LocalTime.TimeUnit.SECOND, 10)._to_string()).is_equal("10:12:32.333")
|
||||
assert_str(time.plus(LocalTime.TimeUnit.SECOND, 27)._to_string()).is_equal("10:12:59.333")
|
||||
assert_str(time.plus(LocalTime.TimeUnit.SECOND, 1)._to_string()).is_equal("10:13:00.333")
|
||||
|
||||
# test overflow
|
||||
var time2 := LocalTime.local_time(10, 59, 59, 333)
|
||||
var start_time = time2._time
|
||||
for iteration in 10000:
|
||||
var t = LocalTime.of_unix_time(start_time)
|
||||
var seconds:int = randi_range(0, 1000)
|
||||
t.plus(LocalTime.TimeUnit.SECOND, seconds)
|
||||
var expected := LocalTime.of_unix_time(start_time + (seconds * LocalTime.MILLIS_PER_SECOND))
|
||||
assert_str(t._to_string()).is_equal(expected._to_string())
|
||||
|
||||
|
||||
func test_elapsed():
|
||||
assert_str(LocalTime.elapsed(10)).is_equal("10ms")
|
||||
assert_str(LocalTime.elapsed(201)).is_equal("201ms")
|
||||
assert_str(LocalTime.elapsed(999)).is_equal("999ms")
|
||||
assert_str(LocalTime.elapsed(1000)).is_equal("1s 0ms")
|
||||
assert_str(LocalTime.elapsed(2000)).is_equal("2s 0ms")
|
||||
assert_str(LocalTime.elapsed(3040)).is_equal("3s 40ms")
|
||||
assert_str(LocalTime.elapsed(LocalTime.MILLIS_PER_MINUTE * 6 + 3040)).is_equal("6min 3s 40ms")
|
||||
296
addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd
Normal file
296
addons/gdUnit4/test/core/ParameterizedTestCaseTest.gd
Normal file
|
|
@ -0,0 +1,296 @@
|
|||
#warning-ignore-all:unused_argument
|
||||
class_name ParameterizedTestCaseTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
var _collected_tests = {}
|
||||
var _expected_tests = {
|
||||
"test_parameterized_bool_value" : [
|
||||
[0, false],
|
||||
[1, true]
|
||||
],
|
||||
"test_parameterized_int_values" : [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 12],
|
||||
[6, 7, 8, 21]
|
||||
],
|
||||
"test_parameterized_float_values" : [
|
||||
[2.2, 2.2, 4.4],
|
||||
[2.2, 2.3, 4.5],
|
||||
[3.3, 2.2, 5.5]
|
||||
],
|
||||
"test_parameterized_string_values" : [
|
||||
["2.2", "2.2", "2.22.2"],
|
||||
["foo", "bar", "foobar"],
|
||||
["a", "b", "ab"]
|
||||
],
|
||||
"test_parameterized_Vector2_values" : [
|
||||
[Vector2.ONE, Vector2.ONE, Vector2(2, 2)],
|
||||
[Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO],
|
||||
[Vector2.ZERO, Vector2.LEFT, Vector2.LEFT]
|
||||
],
|
||||
"test_parameterized_Vector3_values" : [
|
||||
[Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)],
|
||||
[Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO],
|
||||
[Vector3.ZERO, Vector3.LEFT, Vector3.LEFT]
|
||||
],
|
||||
"test_parameterized_obj_values" : [
|
||||
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]
|
||||
],
|
||||
"test_parameterized_dict_values" : [
|
||||
[{"key_a":"value_a"}, '{"key_a":"value_a"}'],
|
||||
[{"key_b":"value_b"}, '{"key_b":"value_b"}']
|
||||
],
|
||||
"test_with_dynamic_paramater_resolving" : [
|
||||
["test_a"],
|
||||
["test_b"],
|
||||
["test_c"],
|
||||
["test_d"]
|
||||
],
|
||||
"test_with_dynamic_paramater_resolving2" : [
|
||||
["test_a"],
|
||||
["test_b"],
|
||||
["test_c"]
|
||||
],
|
||||
"test_with_extern_parameter_set" : [
|
||||
["test_a"],
|
||||
["test_b"],
|
||||
["test_c"]
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
var _test_node_before :Node
|
||||
var _test_node_before_test :Node
|
||||
|
||||
|
||||
func before() -> void:
|
||||
_test_node_before = auto_free(SubViewport.new())
|
||||
|
||||
|
||||
func before_test() -> void:
|
||||
_test_node_before_test = auto_free(SubViewport.new())
|
||||
|
||||
|
||||
func after():
|
||||
for test_name in _expected_tests.keys():
|
||||
if _collected_tests.has(test_name):
|
||||
var current_values = _collected_tests[test_name]
|
||||
var expected_values = _expected_tests[test_name]
|
||||
assert_that(current_values)\
|
||||
.override_failure_message("Expecting '%s' called with parameters:\n %s\n but was\n %s" % [test_name, expected_values, current_values])\
|
||||
.is_equal(expected_values)
|
||||
else:
|
||||
fail("Missing test '%s' executed!" % test_name)
|
||||
|
||||
|
||||
func collect_test_call(test_name :String, values :Array) -> void:
|
||||
if not _collected_tests.has(test_name):
|
||||
_collected_tests[test_name] = Array()
|
||||
_collected_tests[test_name].append(values)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_bool_value(a: int, expected :bool, test_parameters := [
|
||||
[0, false],
|
||||
[1, true]]):
|
||||
collect_test_call("test_parameterized_bool_value", [a, expected])
|
||||
assert_that(bool(a)).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 12],
|
||||
[6, 7, 8, 21] ]):
|
||||
|
||||
collect_test_call("test_parameterized_int_values", [a, b, c, expected])
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_float_values(a: float, b :float, expected :float, test_parameters := [
|
||||
[2.2, 2.2, 4.4],
|
||||
[2.2, 2.3, 4.5],
|
||||
[3.3, 2.2, 5.5] ]):
|
||||
|
||||
collect_test_call("test_parameterized_float_values", [a, b, expected])
|
||||
assert_float(a+b).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_string_values(a: String, b :String, expected :String, test_parameters := [
|
||||
["2.2", "2.2", "2.22.2"],
|
||||
["foo", "bar", "foobar"],
|
||||
["a", "b", "ab"] ]):
|
||||
|
||||
collect_test_call("test_parameterized_string_values", [a, b, expected])
|
||||
assert_that(a+b).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2, test_parameters := [
|
||||
[Vector2.ONE, Vector2.ONE, Vector2(2, 2)],
|
||||
[Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO],
|
||||
[Vector2.ZERO, Vector2.LEFT, Vector2.LEFT] ]):
|
||||
|
||||
collect_test_call("test_parameterized_Vector2_values", [a, b, expected])
|
||||
assert_that(a+b).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_Vector3_values(a: Vector3, b :Vector3, expected :Vector3, test_parameters := [
|
||||
[Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)],
|
||||
[Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO],
|
||||
[Vector3.ZERO, Vector3.LEFT, Vector3.LEFT] ]):
|
||||
|
||||
collect_test_call("test_parameterized_Vector3_values", [a, b, expected])
|
||||
assert_that(a+b).is_equal(expected)
|
||||
|
||||
|
||||
class TestObj extends RefCounted:
|
||||
var _value :String
|
||||
|
||||
func _init(value :String):
|
||||
_value = value
|
||||
|
||||
func _to_string() -> String:
|
||||
return _value
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_obj_values(a: Object, b :Object, expected :String, test_parameters := [
|
||||
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]):
|
||||
|
||||
collect_test_call("test_parameterized_obj_values", [a, b, expected])
|
||||
assert_that(a.to_string()+b.to_string()).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_dict_values(data: Dictionary, expected :String, test_parameters := [
|
||||
[{"key_a" : "value_a"}, '{"key_a":"value_a"}'],
|
||||
[{"key_b" : "value_b"}, '{"key_b":"value_b"}']
|
||||
]):
|
||||
collect_test_call("test_parameterized_dict_values", [data, expected])
|
||||
assert_that(str(data).replace(" ", "")).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_dictionary_div_number_types(
|
||||
value : Dictionary,
|
||||
expected : Dictionary,
|
||||
test_parameters : Array = [
|
||||
[{ top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}, { top = 50, bottom = 50, left = 50, right = 50}],
|
||||
[{ top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}, { top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}],
|
||||
[{ top = 50, bottom = 50, left = 50, right = 50}, { top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}],
|
||||
[{ top = 50, bottom = 50, left = 50, right = 50}, { top = 50, bottom = 50, left = 50, right = 50}],
|
||||
]
|
||||
) -> void:
|
||||
# allow to compare type unsave
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, false)
|
||||
assert_that(value).is_equal(expected)
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, true)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_string_paramset(
|
||||
values : Array,
|
||||
expected : String,
|
||||
test_parameters : Array = [
|
||||
[ ["a"], "a" ],
|
||||
[ ["a", "very", "long", "argument"], "a very long argument" ],
|
||||
]
|
||||
):
|
||||
var current := " ".join(values)
|
||||
assert_that(current.strip_edges()).is_equal(expected)
|
||||
|
||||
|
||||
# https://github.com/MikeSchulze/gdUnit4/issues/213
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_string_contains_brackets(
|
||||
test_index :int,
|
||||
value :String,
|
||||
test_parameters := [
|
||||
[1, "flowchart TD\nid>This is a flag shaped node]"],
|
||||
[2, "flowchart TD\nid(((This is a double circle node)))"],
|
||||
[3, "flowchart TD\nid((This is a circular node))"],
|
||||
[4, "flowchart TD\nid>This is a flag shaped node]"],
|
||||
[5, "flowchart TD\nid{'This is a rhombus node'}"],
|
||||
[6, 'flowchart TD\nid((This is a circular node))'],
|
||||
[7, 'flowchart TD\nid>This is a flag shaped node]'],
|
||||
[8, 'flowchart TD\nid{"This is a rhombus node"}'],
|
||||
[9, """
|
||||
flowchart TD
|
||||
id{"This is a rhombus node"}
|
||||
"""],
|
||||
]
|
||||
):
|
||||
match test_index:
|
||||
1: assert_str(value).is_equal("flowchart TD\nid>This is a flag shaped node]")
|
||||
2: assert_str(value).is_equal("flowchart TD\nid(((This is a double circle node)))")
|
||||
3: assert_str(value).is_equal("flowchart TD\nid((This is a circular node))")
|
||||
4: assert_str(value).is_equal("flowchart TD\nid>" + "This is a flag shaped node]")
|
||||
5: assert_str(value).is_equal("flowchart TD\nid{'This is a rhombus node'}")
|
||||
6: assert_str(value).is_equal('flowchart TD\nid((This is a circular node))')
|
||||
7: assert_str(value).is_equal('flowchart TD\nid>This is a flag shaped node]')
|
||||
8: assert_str(value).is_equal('flowchart TD\nid{"This is a rhombus node"}')
|
||||
9: assert_str(value).is_equal("""
|
||||
flowchart TD
|
||||
id{"This is a rhombus node"}
|
||||
""")
|
||||
|
||||
|
||||
func test_with_dynamic_parameter_resolving(name: String, value, expected, test_parameters := [
|
||||
["test_a", auto_free(Node2D.new()), Node2D],
|
||||
["test_b", auto_free(Node3D.new()), Node3D],
|
||||
["test_c", _test_node_before, SubViewport],
|
||||
["test_d", _test_node_before_test, SubViewport],
|
||||
]) -> void:
|
||||
# all values must be resolved
|
||||
assert_that(value).is_not_null().is_instanceof(expected)
|
||||
if name == "test_c":
|
||||
assert_that(value).is_same(_test_node_before)
|
||||
if name == "test_d":
|
||||
assert_that(value).is_same(_test_node_before_test)
|
||||
# the argument 'test_parameters' must be replaced by <null> set to avoid re-instantiate of test arguments
|
||||
assert_that(test_parameters).is_empty()
|
||||
collect_test_call("test_with_dynamic_paramater_resolving", [name])
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_dynamic_parameter_resolving2(
|
||||
name: String,
|
||||
type,
|
||||
log_level,
|
||||
expected_logs,
|
||||
test_parameters = [
|
||||
["test_a", null, "LOG", {}],
|
||||
[
|
||||
"test_b",
|
||||
Node2D,
|
||||
null,
|
||||
{Node2D: "ERROR"}
|
||||
],
|
||||
[
|
||||
"test_c",
|
||||
Node2D,
|
||||
"LOG",
|
||||
{Node2D: "LOG"}
|
||||
]
|
||||
]
|
||||
):
|
||||
# the argument 'test_parameters' must be replaced by <null> set to avoid re-instantiate of test arguments
|
||||
assert_that(test_parameters).is_empty()
|
||||
collect_test_call("test_with_dynamic_paramater_resolving2", [name])
|
||||
|
||||
|
||||
var _test_set =[
|
||||
["test_a"],
|
||||
["test_b"],
|
||||
["test_c"]
|
||||
]
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_extern_parameter_set(value, test_parameters = _test_set):
|
||||
assert_that(value).is_not_empty()
|
||||
assert_that(test_parameters).is_empty()
|
||||
collect_test_call("test_with_extern_parameter_set", [value])
|
||||
70
addons/gdUnit4/test/core/command/GdUnitCommandHandlerTest.gd
Normal file
70
addons/gdUnit4/test/core/command/GdUnitCommandHandlerTest.gd
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/command/GdUnitCommandHandler.gd'
|
||||
|
||||
var _handler :GdUnitCommandHandler
|
||||
|
||||
|
||||
func before():
|
||||
_handler = GdUnitCommandHandler.new()
|
||||
|
||||
|
||||
func after():
|
||||
_handler._notification(NOTIFICATION_PREDELETE)
|
||||
_handler = null
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_create_shortcuts_defaults(shortcut :GdUnitShortcut.ShortCut, expected :String, test_parameters := [
|
||||
[GdUnitShortcut.ShortCut.RUN_TESTCASE, "GdUnitShortcutAction: RUN_TESTCASE (Ctrl+Alt+F5) -> Run TestCases"],
|
||||
[GdUnitShortcut.ShortCut.RUN_TESTCASE_DEBUG, "GdUnitShortcutAction: RUN_TESTCASE_DEBUG (Ctrl+Alt+F6) -> Run TestCases (Debug)"],
|
||||
[GdUnitShortcut.ShortCut.RERUN_TESTS, "GdUnitShortcutAction: RERUN_TESTS (Ctrl+F5) -> ReRun Tests"],
|
||||
[GdUnitShortcut.ShortCut.RERUN_TESTS_DEBUG, "GdUnitShortcutAction: RERUN_TESTS_DEBUG (Ctrl+F6) -> ReRun Tests (Debug)"],
|
||||
[GdUnitShortcut.ShortCut.RUN_TESTS_OVERALL, "GdUnitShortcutAction: RUN_TESTS_OVERALL (Ctrl+F7) -> Debug Overall TestSuites"],
|
||||
[GdUnitShortcut.ShortCut.STOP_TEST_RUN, "GdUnitShortcutAction: STOP_TEST_RUN (Ctrl+F8) -> Stop Test Run"],
|
||||
[GdUnitShortcut.ShortCut.CREATE_TEST, "GdUnitShortcutAction: CREATE_TEST (Ctrl+Alt+F10) -> Create TestCase"],]) -> void:
|
||||
|
||||
if OS.get_name().to_lower() == "macos":
|
||||
expected.replace("Ctrl", "Command")
|
||||
|
||||
var action := _handler.get_shortcut_action(shortcut)
|
||||
assert_that(str(action)).is_equal(expected)
|
||||
|
||||
|
||||
## actually needs to comment out, it produces a lot of leaked instances
|
||||
func _test__check_test_run_stopped_manually() -> void:
|
||||
var inspector :GdUnitCommandHandler = mock(GdUnitCommandHandler, CALL_REAL_FUNC)
|
||||
inspector._client_id = 1
|
||||
|
||||
# simulate no test is running
|
||||
do_return(false).on(inspector).is_test_running_but_stop_pressed()
|
||||
inspector.check_test_run_stopped_manually()
|
||||
verify(inspector, 0).cmd_stop(any_int())
|
||||
|
||||
# simulate the test runner was manually stopped by the editor
|
||||
do_return(true).on(inspector).is_test_running_but_stop_pressed()
|
||||
inspector.check_test_run_stopped_manually()
|
||||
verify(inspector, 1).cmd_stop(inspector._client_id)
|
||||
|
||||
|
||||
func test_scan_test_directorys() -> void:
|
||||
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "test", [])).contains_exactly([
|
||||
"res://addons/gdUnit4/test"
|
||||
])
|
||||
# for root folders
|
||||
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "", [])).contains_exactly([
|
||||
"res://addons", "res://assets", "res://gdUnit3-examples"
|
||||
])
|
||||
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "/", [])).contains_exactly([
|
||||
"res://addons", "res://assets", "res://gdUnit3-examples"
|
||||
])
|
||||
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "res://", [])).contains_exactly([
|
||||
"res://addons", "res://assets", "res://gdUnit3-examples"
|
||||
])
|
||||
# a test folder not exists
|
||||
assert_array(GdUnitCommandHandler.scan_test_directorys("res://", "notest", [])).is_empty()
|
||||
22
addons/gdUnit4/test/core/event/GdUnitEventTest.gd
Normal file
22
addons/gdUnit4/test/core/event/GdUnitEventTest.gd
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitEventTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/event/GdUnitEvent.gd'
|
||||
|
||||
|
||||
func test_GdUnitEvent_defaults() -> void:
|
||||
var event := GdUnitEvent.new()
|
||||
|
||||
assert_bool(event.is_success()).is_true()
|
||||
assert_bool(event.is_warning()).is_false()
|
||||
assert_bool(event.is_failed()).is_false()
|
||||
assert_bool(event.is_error()).is_false()
|
||||
assert_bool(event.is_skipped()).is_false()
|
||||
|
||||
assert_int(event.elapsed_time()).is_zero()
|
||||
assert_int(event.orphan_nodes()).is_zero()
|
||||
assert_int(event.total_count()).is_zero()
|
||||
assert_int(event.failed_count()).is_zero()
|
||||
assert_int(event.skipped_count()).is_zero()
|
||||
51
addons/gdUnit4/test/core/event/GdUnitTestEventSerdeTest.gd
Normal file
51
addons/gdUnit4/test/core/event/GdUnitTestEventSerdeTest.gd
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
# this test test for serialization and deserialization succcess
|
||||
# of GdUnitEvent class
|
||||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
func test_serde_suite_before():
|
||||
var event := GdUnitEvent.new().suite_before("path", "test_suite_a", 22)
|
||||
var serialized := event.serialize()
|
||||
var deserialized := GdUnitEvent.new().deserialize(serialized)
|
||||
assert_that(deserialized).is_instanceof(GdUnitEvent)
|
||||
assert_that(deserialized).is_equal(event)
|
||||
|
||||
|
||||
func test_serde_suite_after():
|
||||
var event := GdUnitEvent.new().suite_after("path","test_suite_a")
|
||||
var serialized := event.serialize()
|
||||
var deserialized := GdUnitEvent.new().deserialize(serialized)
|
||||
assert_that(deserialized).is_equal(event)
|
||||
|
||||
|
||||
func test_serde_test_before():
|
||||
var event := GdUnitEvent.new().test_before("path", "test_suite_a", "test_foo")
|
||||
var serialized := event.serialize()
|
||||
var deserialized := GdUnitEvent.new().deserialize(serialized)
|
||||
assert_that(deserialized).is_equal(event)
|
||||
|
||||
|
||||
func test_serde_test_after_no_report():
|
||||
var event := GdUnitEvent.new().test_after("path", "test_suite_a", "test_foo")
|
||||
var serialized := event.serialize()
|
||||
var deserialized := GdUnitEvent.new().deserialize(serialized)
|
||||
assert_that(deserialized).is_equal(event)
|
||||
|
||||
|
||||
func test_serde_test_after_with_report():
|
||||
var reports :Array[GdUnitReport] = [\
|
||||
GdUnitReport.new().create(GdUnitReport.FAILURE, 24, "this is a error a"), \
|
||||
GdUnitReport.new().create(GdUnitReport.FAILURE, 26, "this is a error b")]
|
||||
var event := GdUnitEvent.new().test_after("path", "test_suite_a", "test_foo", {}, reports)
|
||||
|
||||
var serialized := event.serialize()
|
||||
var deserialized := GdUnitEvent.new().deserialize(serialized)
|
||||
assert_that(deserialized).is_equal(event)
|
||||
assert_array(deserialized.reports()).contains_exactly(reports)
|
||||
|
||||
|
||||
func test_serde_TestReport():
|
||||
var report := GdUnitReport.new().create(GdUnitReport.FAILURE, 24, "this is a error")
|
||||
var serialized := report.serialize()
|
||||
var deserialized := GdUnitReport.new().deserialize(serialized)
|
||||
assert_that(deserialized).is_equal(report)
|
||||
222
addons/gdUnit4/test/core/execution/GdUnitExecutionContextTest.gd
Normal file
222
addons/gdUnit4/test/core/execution/GdUnitExecutionContextTest.gd
Normal file
|
|
@ -0,0 +1,222 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitExecutionContextTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/execution/GdUnitExecutionContext.gd'
|
||||
|
||||
|
||||
func add_report(ec :GdUnitExecutionContext, report :GdUnitReport) -> void:
|
||||
ec._report_collector.on_reports(ec.get_instance_id(), report)
|
||||
|
||||
|
||||
func assert_statistics(ec :GdUnitExecutionContext):
|
||||
assert_that(ec.has_failures()).is_false()
|
||||
assert_that(ec.has_errors()).is_false()
|
||||
assert_that(ec.has_warnings()).is_false()
|
||||
assert_that(ec.has_skipped()).is_false()
|
||||
assert_that(ec.count_failures(true)).is_equal(0)
|
||||
assert_that(ec.count_errors(true)).is_equal(0)
|
||||
assert_that(ec.count_skipped(true)).is_equal(0)
|
||||
assert_that(ec.count_orphans()).is_equal(0)
|
||||
assert_dict(ec.build_report_statistics(0))\
|
||||
.contains_key_value(GdUnitEvent.FAILED, false)\
|
||||
.contains_key_value(GdUnitEvent.ERRORS, false)\
|
||||
.contains_key_value(GdUnitEvent.WARNINGS, false)\
|
||||
.contains_key_value(GdUnitEvent.SKIPPED, false)\
|
||||
.contains_key_value(GdUnitEvent.ORPHAN_NODES, 0)\
|
||||
.contains_key_value(GdUnitEvent.FAILED_COUNT, 0)\
|
||||
.contains_key_value(GdUnitEvent.ERROR_COUNT, 0)\
|
||||
.contains_key_value(GdUnitEvent.SKIPPED_COUNT, 0)\
|
||||
.contains_keys([GdUnitEvent.ELAPSED_TIME])
|
||||
|
||||
|
||||
func test_create_context_of_test_suite() -> void:
|
||||
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
|
||||
var ec := GdUnitExecutionContext.of_test_suite(ts)
|
||||
# verify the current context is not affected by this test itself
|
||||
assert_object(__execution_context).is_not_same(ec)
|
||||
|
||||
# verify the execution context is assigned to the test suite
|
||||
assert_object(ts.__execution_context).is_same(ec)
|
||||
|
||||
# verify execution context is fully initialized
|
||||
assert_that(ec).is_not_null()
|
||||
assert_object(ec.test_suite).is_same(ts)
|
||||
assert_object(ec.test_case).is_null()
|
||||
assert_array(ec._sub_context).is_empty()
|
||||
assert_object(ec._orphan_monitor).is_not_null()
|
||||
assert_object(ec._memory_observer).is_not_null()
|
||||
assert_object(ec._report_collector).is_not_null()
|
||||
assert_statistics(ec)
|
||||
ec.dispose()
|
||||
|
||||
|
||||
func test_create_context_of_test_case() -> void:
|
||||
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
|
||||
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
|
||||
ts.add_child(tc)
|
||||
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
|
||||
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
|
||||
# verify the current context is not affected by this test itself
|
||||
assert_object(__execution_context).is_not_same(ec1)
|
||||
assert_object(__execution_context).is_not_same(ec2)
|
||||
|
||||
# verify current execution contest is assigned to the test suite
|
||||
assert_object(ts.__execution_context).is_same(ec2)
|
||||
# verify execution context is fully initialized
|
||||
assert_that(ec2).is_not_null()
|
||||
assert_object(ec2.test_suite).is_same(ts)
|
||||
assert_object(ec2.test_case).is_same(tc)
|
||||
assert_array(ec2._sub_context).is_empty()
|
||||
assert_object(ec2._orphan_monitor).is_not_null().is_not_same(ec1._orphan_monitor)
|
||||
assert_object(ec2._memory_observer).is_not_null().is_not_same(ec1._memory_observer)
|
||||
assert_object(ec2._report_collector).is_not_null().is_not_same(ec1._report_collector)
|
||||
assert_statistics(ec2)
|
||||
# check parent context ec1 is still valid
|
||||
assert_that(ec1).is_not_null()
|
||||
assert_object(ec1.test_suite).is_same(ts)
|
||||
assert_object(ec1.test_case).is_null()
|
||||
assert_array(ec1._sub_context).contains_exactly([ec2])
|
||||
assert_object(ec1._orphan_monitor).is_not_null()
|
||||
assert_object(ec1._memory_observer).is_not_null()
|
||||
assert_object(ec1._report_collector).is_not_null()
|
||||
assert_statistics(ec1)
|
||||
ec1.dispose()
|
||||
|
||||
|
||||
func test_create_context_of_test() -> void:
|
||||
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
|
||||
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
|
||||
ts.add_child(tc)
|
||||
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
|
||||
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
|
||||
var ec3 := GdUnitExecutionContext.of(ec2)
|
||||
# verify the current context is not affected by this test itself
|
||||
assert_object(__execution_context).is_not_same(ec1)
|
||||
assert_object(__execution_context).is_not_same(ec2)
|
||||
assert_object(__execution_context).is_not_same(ec3)
|
||||
|
||||
# verify current execution contest is assigned to the test suite
|
||||
assert_object(ts.__execution_context).is_same(ec3)
|
||||
# verify execution context is fully initialized
|
||||
assert_that(ec3).is_not_null()
|
||||
assert_object(ec3.test_suite).is_same(ts)
|
||||
assert_object(ec3.test_case).is_same(tc)
|
||||
assert_array(ec3._sub_context).is_empty()
|
||||
assert_object(ec3._orphan_monitor).is_not_null()\
|
||||
.is_not_same(ec1._orphan_monitor)\
|
||||
.is_not_same(ec2._orphan_monitor)
|
||||
assert_object(ec3._memory_observer).is_not_null()\
|
||||
.is_not_same(ec1._memory_observer)\
|
||||
.is_not_same(ec2._memory_observer)
|
||||
assert_object(ec3._report_collector).is_not_null()\
|
||||
.is_not_same(ec1._report_collector)\
|
||||
.is_not_same(ec2._report_collector)
|
||||
assert_statistics(ec3)
|
||||
# check parent context ec2 is still valid
|
||||
assert_that(ec2).is_not_null()
|
||||
assert_object(ec2.test_suite).is_same(ts)
|
||||
assert_object(ec2.test_case).is_same(tc)
|
||||
assert_array(ec2._sub_context).contains_exactly([ec3])
|
||||
assert_object(ec2._orphan_monitor).is_not_null()\
|
||||
.is_not_same(ec1._orphan_monitor)
|
||||
assert_object(ec2._memory_observer).is_not_null()\
|
||||
.is_not_same(ec1._memory_observer)
|
||||
assert_object(ec2._report_collector).is_not_null()\
|
||||
.is_not_same(ec1._report_collector)
|
||||
assert_statistics(ec2)
|
||||
# check parent context ec1 is still valid
|
||||
assert_that(ec1).is_not_null()
|
||||
assert_object(ec1.test_suite).is_same(ts)
|
||||
assert_object(ec1.test_case).is_null()
|
||||
assert_array(ec1._sub_context).contains_exactly([ec2])
|
||||
assert_object(ec1._orphan_monitor).is_not_null()
|
||||
assert_object(ec1._memory_observer).is_not_null()
|
||||
assert_object(ec1._report_collector).is_not_null()
|
||||
assert_statistics(ec1)
|
||||
ec1.dispose()
|
||||
|
||||
|
||||
func test_report_collectors() -> void:
|
||||
# setup
|
||||
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
|
||||
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
|
||||
ts.add_child(tc)
|
||||
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
|
||||
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
|
||||
var ec3 := GdUnitExecutionContext.of(ec2)
|
||||
|
||||
# add reports
|
||||
var failure11 := GdUnitReport.new().create(GdUnitReport.FAILURE, 1, "error_ec11")
|
||||
add_report(ec1, failure11)
|
||||
var failure21 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec21")
|
||||
var failure22 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec22")
|
||||
add_report(ec2, failure21)
|
||||
add_report(ec2, failure22)
|
||||
var failure31 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec31")
|
||||
var failure32 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec32")
|
||||
var failure33 := GdUnitReport.new().create(GdUnitReport.FAILURE, 3, "error_ec33")
|
||||
add_report(ec3, failure31)
|
||||
add_report(ec3, failure32)
|
||||
add_report(ec3, failure33)
|
||||
# verify
|
||||
assert_array(ec1.reports()).contains_exactly([failure11])
|
||||
assert_array(ec2.reports()).contains_exactly([failure21, failure22])
|
||||
assert_array(ec3.reports()).contains_exactly([failure31, failure32, failure33])
|
||||
ec1.dispose()
|
||||
|
||||
|
||||
func test_has_and_count_failures() -> void:
|
||||
# setup
|
||||
var ts :GdUnitTestSuite = auto_free(GdUnitTestSuite.new())
|
||||
var tc :_TestCase = auto_free(_TestCase.new().configure("test_case1", 0, ""))
|
||||
ts.add_child(tc)
|
||||
var ec1 := GdUnitExecutionContext.of_test_suite(ts)
|
||||
var ec2 := GdUnitExecutionContext.of_test_case(ec1, "test_case1")
|
||||
var ec3 := GdUnitExecutionContext.of(ec2)
|
||||
|
||||
# precheck
|
||||
assert_that(ec1.has_failures()).is_false()
|
||||
assert_that(ec1.count_failures(true)).is_equal(0)
|
||||
assert_that(ec2.has_failures()).is_false()
|
||||
assert_that(ec2.count_failures(true)).is_equal(0)
|
||||
assert_that(ec3.has_failures()).is_false()
|
||||
assert_that(ec3.count_failures(true)).is_equal(0)
|
||||
|
||||
# add four failure report to test
|
||||
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 42, "error_ec31"))
|
||||
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 43, "error_ec32"))
|
||||
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 44, "error_ec33"))
|
||||
add_report(ec3, GdUnitReport.new().create(GdUnitReport.FAILURE, 45, "error_ec34"))
|
||||
# verify
|
||||
assert_that(ec1.has_failures()).is_true()
|
||||
assert_that(ec1.count_failures(true)).is_equal(4)
|
||||
assert_that(ec2.has_failures()).is_true()
|
||||
assert_that(ec2.count_failures(true)).is_equal(4)
|
||||
assert_that(ec3.has_failures()).is_true()
|
||||
assert_that(ec3.count_failures(true)).is_equal(4)
|
||||
|
||||
# add two failure report to test_case_stage
|
||||
add_report(ec2, GdUnitReport.new().create(GdUnitReport.FAILURE, 42, "error_ec21"))
|
||||
add_report(ec2, GdUnitReport.new().create(GdUnitReport.FAILURE, 43, "error_ec22"))
|
||||
# verify
|
||||
assert_that(ec1.has_failures()).is_true()
|
||||
assert_that(ec1.count_failures(true)).is_equal(6)
|
||||
assert_that(ec2.has_failures()).is_true()
|
||||
assert_that(ec2.count_failures(true)).is_equal(6)
|
||||
assert_that(ec3.has_failures()).is_true()
|
||||
assert_that(ec3.count_failures(true)).is_equal(4)
|
||||
|
||||
# add one failure report to test_suite_stage
|
||||
add_report(ec1, GdUnitReport.new().create(GdUnitReport.FAILURE, 42, "error_ec1"))
|
||||
# verify
|
||||
assert_that(ec1.has_failures()).is_true()
|
||||
assert_that(ec1.count_failures(true)).is_equal(7)
|
||||
assert_that(ec2.has_failures()).is_true()
|
||||
assert_that(ec2.count_failures(true)).is_equal(6)
|
||||
assert_that(ec3.has_failures()).is_true()
|
||||
assert_that(ec3.count_failures(true)).is_equal(4)
|
||||
ec1.dispose()
|
||||
|
|
@ -0,0 +1,708 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitTestSuiteExecutorTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/execution/GdUnitTestSuiteExecutor.gd'
|
||||
const GdUnitTools := preload("res://addons/gdUnit4/src/core/GdUnitTools.gd")
|
||||
|
||||
|
||||
const SUCCEEDED = true
|
||||
const FAILED = false
|
||||
const SKIPPED = true
|
||||
const NOT_SKIPPED = false
|
||||
|
||||
var _collected_events :Array[GdUnitEvent] = []
|
||||
|
||||
|
||||
func before() -> void:
|
||||
GdUnitSignals.instance().gdunit_event_debug.connect(_on_gdunit_event_debug)
|
||||
|
||||
|
||||
func after() -> void:
|
||||
GdUnitSignals.instance().gdunit_event_debug.disconnect(_on_gdunit_event_debug)
|
||||
|
||||
|
||||
func after_test():
|
||||
_collected_events.clear()
|
||||
|
||||
|
||||
func _on_gdunit_event_debug(event :GdUnitEvent) -> void:
|
||||
_collected_events.append(event)
|
||||
|
||||
|
||||
func _load(resource_path :String) -> GdUnitTestSuite:
|
||||
return GdUnitTestResourceLoader.load_test_suite(resource_path) as GdUnitTestSuite
|
||||
|
||||
|
||||
func flating_message(message :String) -> String:
|
||||
return GdUnitTools.richtext_normalize(message)
|
||||
|
||||
|
||||
func execute(test_suite :GdUnitTestSuite) -> Array[GdUnitEvent]:
|
||||
await GdUnitThreadManager.run("test_executor", func():
|
||||
var executor := GdUnitTestSuiteExecutor.new(true)
|
||||
await executor.execute(test_suite))
|
||||
return _collected_events
|
||||
|
||||
|
||||
func assert_event_list(events :Array[GdUnitEvent], suite_name :String, test_case_names :Array[String]) -> void:
|
||||
var expected_events := Array()
|
||||
expected_events.append(tuple(GdUnitEvent.TESTSUITE_BEFORE, suite_name, "before", test_case_names.size()))
|
||||
for test_case in test_case_names:
|
||||
expected_events.append(tuple(GdUnitEvent.TESTCASE_BEFORE, suite_name, test_case, 0))
|
||||
expected_events.append(tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, test_case, 0))
|
||||
expected_events.append(tuple(GdUnitEvent.TESTSUITE_AFTER, suite_name, "after", 0))
|
||||
|
||||
var expected_event_count := 2 + test_case_names.size() * 2
|
||||
assert_array(events)\
|
||||
.override_failure_message("Expecting be %d events emitted, but counts %d." % [expected_event_count, events.size()])\
|
||||
.has_size(expected_event_count)
|
||||
|
||||
assert_array(events)\
|
||||
.extractv(extr("type"), extr("suite_name"), extr("test_name"), extr("total_count"))\
|
||||
.contains_exactly(expected_events)
|
||||
|
||||
|
||||
func assert_event_counters(events :Array[GdUnitEvent]) -> GdUnitArrayAssert:
|
||||
return assert_array(events).extractv(extr("type"), extr("error_count"), extr("failed_count"), extr("orphan_nodes"))
|
||||
|
||||
|
||||
func assert_event_states(events :Array[GdUnitEvent]) -> GdUnitArrayAssert:
|
||||
return assert_array(events).extractv(extr("test_name"), extr("is_success"), extr("is_skipped"), extr("is_warning"), extr("is_failed"), extr("is_error"))
|
||||
|
||||
|
||||
func assert_event_reports(events :Array[GdUnitEvent], expected_reports :Array) -> void:
|
||||
for event_index in events.size():
|
||||
var current :Array = events[event_index].reports()
|
||||
var expected = expected_reports[event_index] if expected_reports.size() > event_index else []
|
||||
if expected.is_empty():
|
||||
for m in current.size():
|
||||
assert_str(flating_message(current[m].message())).is_empty()
|
||||
|
||||
for m in expected.size():
|
||||
if m < current.size():
|
||||
assert_str(flating_message(current[m].message())).is_equal(expected[m])
|
||||
else:
|
||||
assert_str("<N/A>").is_equal(expected[m])
|
||||
|
||||
|
||||
func test_execute_success() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteAllStagesSuccess.resource")
|
||||
# simulate test suite execution
|
||||
var events := await execute(test_suite)
|
||||
assert_event_list(events,\
|
||||
"TestSuiteAllStagesSuccess",\
|
||||
["test_case1", "test_case2"])
|
||||
# verify all counters are zero / no errors, failures, orphans
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
])
|
||||
# all success no reports expected
|
||||
assert_event_reports(events, [
|
||||
[], [], [], [], [], []
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_on_stage_before() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageBefore.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailOnStageBefore",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect the testsuite is failing on stage 'before()' and commits one failure
|
||||
# reported finally at TESTSUITE_AFTER event
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
# report failure failed_count = 1
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 1, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# report suite is not success, is failed
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# one failure at before()
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
["failed on before()"]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_on_stage_after() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageAfter.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailOnStageAfter",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect the testsuite is failing on stage 'before()' and commits one failure
|
||||
# reported finally at TESTSUITE_AFTER event
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
# report failure failed_count = 1
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 1, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# report suite is not success, is failed
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# one failure at after()
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
["failed on after()"]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_on_stage_before_test() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageBeforeTest.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailOnStageBeforeTest",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect the testsuite is failing on stage 'before_test()' and commits one failure on each test case
|
||||
# because is in scope of test execution
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# failure is count to the test
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# failure is count to the test
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
|
||||
# report suite is not success, is failed
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# before_test() failure report is append to each test
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
# verify failure report is append to 'test_case1'
|
||||
["failed on before_test()"],
|
||||
[],
|
||||
# verify failure report is append to 'test_case2'
|
||||
["failed on before_test()"],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_on_stage_after_test() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageAfterTest.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailOnStageAfterTest",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect the testsuite is failing on stage 'after_test()' and commits one failure on each test case
|
||||
# because is in scope of test execution
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# failure is count to the test
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# failure is count to the test
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
|
||||
# report suite is not success, is failed
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# 'after_test' failure report is append to each test
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
# verify failure report is append to 'test_case1'
|
||||
["failed on after_test()"],
|
||||
[],
|
||||
# verify failure report is append to 'test_case2'
|
||||
["failed on after_test()"],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_on_stage_test_case1() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnStageTestCase1.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailOnStageTestCase1",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect the test case 'test_case1' is failing and commits one failure
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# test has one failure
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# report suite is not success, is failed
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# only 'test_case1' reports a failure
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
# verify failure report is append to 'test_case1'
|
||||
["failed on test_case1()"],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_on_multiple_stages() -> void:
|
||||
# this is a more complex failure state, we expect to find multipe failures on different stages
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailOnMultipeStages.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailOnMultipeStages",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect failing on multiple stages
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# the first test has two failures plus one from 'before_test'
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 3, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# the second test has no failures but one from 'before_test'
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
# and one failure is on stage 'after' found
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 1, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", FAILED, NOT_SKIPPED, false, true, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
|
||||
# report suite is not success, is failed
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# only 'test_case1' reports a 'real' failures plus test setup stage failures
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
# verify failure reports to 'test_case1'
|
||||
["failed on before_test()", "failed 1 on test_case1()", "failed 2 on test_case1()"],
|
||||
[],
|
||||
# verify failure reports to 'test_case2'
|
||||
["failed on before_test()"],
|
||||
# and one failure detected at stage 'after'
|
||||
["failed on after()"]
|
||||
])
|
||||
|
||||
|
||||
# GD-63
|
||||
func test_execute_failure_and_orphans() -> void:
|
||||
# this is a more complex failure state, we expect to find multipe orphans on different stages
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailAndOrpahnsDetected.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailAndOrpahnsDetected",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect failing on multiple stages
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# the first test ends with a warning and in summ 5 orphans detected
|
||||
# 2 from stage 'before_test' + 3 from test itself
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 5),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# the second test ends with a one failure and in summ 6 orphans detected
|
||||
# 2 from stage 'before_test' + 4 from test itself
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 6),
|
||||
# and one orphan detected from stage 'before'
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 1),
|
||||
])
|
||||
# is_success, is_warning, is_failed, is_error
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# test case has only warnings
|
||||
tuple("test_case1", FAILED, NOT_SKIPPED, true, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# test case has failures and warnings
|
||||
tuple("test_case2", FAILED, NOT_SKIPPED, true, true, false),
|
||||
# report suite is not success, has warnings and failures
|
||||
tuple("after", FAILED, NOT_SKIPPED, true, true, false),
|
||||
])
|
||||
# only 'test_case1' reports a 'real' failures plus test setup stage failures
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
# ends with warnings
|
||||
["WARNING:\n Detected <2> orphan nodes during test setup! Check before_test() and after_test()!",
|
||||
"WARNING:\n Detected <3> orphan nodes during test execution!"],
|
||||
[],
|
||||
# ends with failure and warnings
|
||||
["WARNING:\n Detected <2> orphan nodes during test setup! Check before_test() and after_test()!",
|
||||
"WARNING:\n Detected <4> orphan nodes during test execution!",
|
||||
"faild on test_case2()"],
|
||||
# and one failure detected at stage 'after'
|
||||
["WARNING:\n Detected <1> orphan nodes during test suite setup stage! Check before() and after()!"]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_and_orphans_report_orphan_disabled() -> void:
|
||||
# this is a more complex failure state, we expect to find multipe orphans on different stages
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailAndOrpahnsDetected.resource")
|
||||
# simulate test suite execution whit disabled orphan detection
|
||||
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ORPHANS, false)
|
||||
var events = await execute(test_suite)
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ORPHANS, true)
|
||||
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailAndOrpahnsDetected",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect failing on multiple stages, no orphans reported
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# one failure
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
# is_success, is_warning, is_failed, is_error
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# test case has success
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# test case has a failure
|
||||
tuple("test_case2", FAILED, NOT_SKIPPED, false, true, false),
|
||||
# report suite is not success, has warnings and failures
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# only 'test_case1' reports a failure, orphans are not reported
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
# ends with a failure
|
||||
["faild on test_case2()"],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_error_on_test_timeout() -> void:
|
||||
# this tests a timeout on a test case reported as error
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteErrorOnTestTimeout.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteErrorOnTestTimeout",\
|
||||
["test_case1", "test_case2"])
|
||||
# we expect test_case1 fails by a timeout
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
# the first test timed out after 2s
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 1, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# testcase ends with a timeout error
|
||||
tuple("test_case1", FAILED, NOT_SKIPPED, false, false, true),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
# report suite is not success, is error
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, false, true),
|
||||
])
|
||||
# 'test_case1' reports a error triggered by test timeout
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
# verify error reports to 'test_case1'
|
||||
["Timeout !\n 'Test timed out after 2s 0ms'"],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
# This test checks if all test stages are called at each test iteration.
|
||||
func test_execute_fuzzed_metrics() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFuzzedMetricsTest.resource")
|
||||
|
||||
var events = await execute(test_suite)
|
||||
assert_event_states(events).contains([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
])
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
# This test checks if all test stages are called at each test iteration.
|
||||
func test_execute_parameterized_metrics() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedMetricsTest.resource")
|
||||
|
||||
var events = await execute(test_suite)
|
||||
assert_event_states(events).contains([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
])
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_failure_fuzzer_iteration() -> void:
|
||||
# this tests a timeout on a test case reported as error
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/GdUnitFuzzerTest.resource")
|
||||
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
|
||||
# verify basis infos
|
||||
assert_event_list(events, "GdUnitFuzzerTest", [
|
||||
"test_multi_yielding_with_fuzzer",
|
||||
"test_multi_yielding_with_fuzzer_fail_after_3_iterations"])
|
||||
# we expect failing at 'test_multi_yielding_with_fuzzer_fail_after_3_iterations' after three iterations
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
# test failed after 3 iterations
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 1, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
# is_success, is_warning, is_failed, is_error
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_multi_yielding_with_fuzzer", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_multi_yielding_with_fuzzer", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_multi_yielding_with_fuzzer_fail_after_3_iterations", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_multi_yielding_with_fuzzer_fail_after_3_iterations", FAILED, NOT_SKIPPED, false, true, false),
|
||||
tuple("after", FAILED, NOT_SKIPPED, false, true, false),
|
||||
])
|
||||
# 'test_case1' reports a error triggered by test timeout
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
[],
|
||||
# must fail after three iterations
|
||||
["Found an error after '3' test iterations\n Expecting: 'false' but is 'true'"],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_add_child_on_before_GD_106() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteFailAddChildStageBefore.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# verify basis infos
|
||||
assert_event_list(events,\
|
||||
"TestSuiteFailAddChildStageBefore",\
|
||||
["test_case1", "test_case2"])
|
||||
# verify all counters are zero / no errors, failures, orphans
|
||||
assert_event_counters(events).contains_exactly([
|
||||
tuple(GdUnitEvent.TESTSUITE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_BEFORE, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, 0, 0, 0),
|
||||
tuple(GdUnitEvent.TESTSUITE_AFTER, 0, 0, 0),
|
||||
])
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
])
|
||||
# all success no reports expected
|
||||
assert_event_reports(events, [
|
||||
[], [], [], [], [], []
|
||||
])
|
||||
|
||||
|
||||
func test_execute_parameterizied_tests() -> void:
|
||||
# this is a more complex failure state, we expect to find multipe failures on different stages
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource")
|
||||
# simulate test suite execution
|
||||
# run the tests with to compare type save
|
||||
var original_mode = ProjectSettings.get_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE)
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, true)
|
||||
var events = await execute(test_suite)
|
||||
var suite_name = "TestSuiteParameterizedTests"
|
||||
# the test is partial failing because of diverent type in the dictionary
|
||||
assert_array(events).extractv(
|
||||
extr("type"), extr("suite_name"), TestCaseNameExtractor.new(), extr("is_error"), extr("is_failed"), extr("orphan_nodes"))\
|
||||
.contains([
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:0", false, true, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:1", false, false, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:2", false, true, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:3", false, false, 0)
|
||||
])
|
||||
|
||||
# rerun the same tests again with allow to compare type unsave
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, false)
|
||||
# simulate test suite execution
|
||||
test_suite = _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteParameterizedTests.resource")
|
||||
events = await execute(test_suite)
|
||||
ProjectSettings.set_setting(GdUnitSettings.REPORT_ASSERT_STRICT_NUMBER_TYPE_COMPARE, original_mode)
|
||||
|
||||
# the test should now be successful
|
||||
assert_array(events).extractv(
|
||||
extr("type"), extr("suite_name"), TestCaseNameExtractor.new(), extr("is_error"), extr("is_failed"), extr("orphan_nodes"))\
|
||||
.contains([
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:0", false, false, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:1", false, false, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:2", false, false, 0),
|
||||
tuple(GdUnitEvent.TESTCASE_AFTER, suite_name, "test_dictionary_div_number_types:3", false, false, 0)
|
||||
])
|
||||
|
||||
|
||||
func test_execute_test_suite_is_skipped() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteSkipped.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# the entire test-suite is skipped
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("after", FAILED, SKIPPED, false, false, false),
|
||||
])
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
# must fail after three iterations
|
||||
["""
|
||||
Entire test-suite is skipped!
|
||||
Tests skipped: '2'
|
||||
Reason: '"do not run this"'
|
||||
""".dedent().trim_prefix("\n")]
|
||||
])
|
||||
|
||||
|
||||
func test_execute_test_case_is_skipped() -> void:
|
||||
var test_suite := _load("res://addons/gdUnit4/test/core/resources/testsuites/TestCaseSkipped.resource")
|
||||
# simulate test suite execution
|
||||
var events = await execute(test_suite)
|
||||
# the test_case1 is skipped
|
||||
assert_event_states(events).contains_exactly([
|
||||
tuple("before", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case1", FAILED, SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("test_case2", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
tuple("after", SUCCEEDED, NOT_SKIPPED, false, false, false),
|
||||
])
|
||||
|
||||
assert_event_reports(events, [
|
||||
[],
|
||||
[],
|
||||
["""
|
||||
This test is skipped!
|
||||
Reason: '"do not run this"'
|
||||
""".dedent().trim_prefix("\n")],
|
||||
[],
|
||||
[],
|
||||
[]
|
||||
])
|
||||
|
||||
|
||||
class TestCaseNameExtractor extends GdUnitValueExtractor:
|
||||
var r := RegEx.create_from_string("^.*:\\d")
|
||||
|
||||
func extract_value(value):
|
||||
var m := r.search(value.test_name())
|
||||
return m.get_string(0) if m != null else value.test_name()
|
||||
255
addons/gdUnit4/test/core/parse/GdDefaultValueDecoderTest.gd
Normal file
255
addons/gdUnit4/test/core/parse/GdDefaultValueDecoderTest.gd
Normal file
|
|
@ -0,0 +1,255 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdDefaultValueDecoderTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdDefaultValueDecoder.gd'
|
||||
|
||||
|
||||
var _tested_types = {}
|
||||
|
||||
|
||||
func after():
|
||||
# we verify we have covered all variant types
|
||||
for type_id in TYPE_MAX:
|
||||
if type_id == TYPE_OBJECT:
|
||||
continue
|
||||
assert_that(_tested_types.get(type_id))\
|
||||
.override_failure_message("Missing Variant type '%s'" % GdObjects.type_as_string(type_id))\
|
||||
.is_not_null()
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Primitives(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_NIL, null, "null"],
|
||||
[TYPE_BOOL, true, "true"],
|
||||
[TYPE_BOOL, false, "false"],
|
||||
[TYPE_INT, -100, "-100"],
|
||||
[TYPE_INT, 0, "0"],
|
||||
[TYPE_INT, 100, "100"],
|
||||
[TYPE_FLOAT, -100.123, "-100.123000"],
|
||||
[TYPE_FLOAT, 0.00, "0.000000"],
|
||||
[TYPE_FLOAT, 100, "100.000000"],
|
||||
[TYPE_FLOAT, 100.123, "100.123000"],
|
||||
[TYPE_STRING, "hello", '"hello"'],
|
||||
[TYPE_STRING, "", '""'],
|
||||
[TYPE_STRING_NAME, StringName("hello"), 'StringName("hello")'],
|
||||
[TYPE_STRING_NAME, StringName(""), 'StringName()'],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Vectors(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_VECTOR2, Vector2(), "Vector2()"],
|
||||
[TYPE_VECTOR2, Vector2(1,2), "Vector2(1, 2)"],
|
||||
[TYPE_VECTOR2I, Vector2i(), "Vector2i()"],
|
||||
[TYPE_VECTOR2I, Vector2i(1,2), "Vector2i(1, 2)"],
|
||||
[TYPE_VECTOR3, Vector3(), "Vector3()"],
|
||||
[TYPE_VECTOR3, Vector3(1,2,3), "Vector3(1, 2, 3)"],
|
||||
[TYPE_VECTOR3I, Vector3i(), "Vector3i()"],
|
||||
[TYPE_VECTOR3I, Vector3i(1,2,3), "Vector3i(1, 2, 3)"],
|
||||
[TYPE_VECTOR4, Vector4(), "Vector4()"],
|
||||
[TYPE_VECTOR4, Vector4(1,2,3,4), "Vector4(1, 2, 3, 4)"],
|
||||
[TYPE_VECTOR4I, Vector4i(), "Vector4i()"],
|
||||
[TYPE_VECTOR4I, Vector4i(1,2,3,4), "Vector4i(1, 2, 3, 4)"],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Rect2(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_RECT2, Rect2(), "Rect2()"],
|
||||
[TYPE_RECT2, Rect2(1,2, 10,20), "Rect2(Vector2(1, 2), Vector2(10, 20))"],
|
||||
[TYPE_RECT2I, Rect2i(), "Rect2i()"],
|
||||
[TYPE_RECT2I, Rect2i(1,2, 10,20), "Rect2i(Vector2i(1, 2), Vector2i(10, 20))"],
|
||||
]) -> void:
|
||||
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Transforms(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_TRANSFORM2D, Transform2D(),
|
||||
"Transform2D()"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(2.0, Vector2(1,2)),
|
||||
"Transform2D(Vector2(-0.416147, 0.909297), Vector2(-0.909297, -0.416147), Vector2(1, 2))"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(2.0, Vector2(1,2), 2.0, Vector2(3,4)),
|
||||
"Transform2D(Vector2(-0.416147, 0.909297), Vector2(1.513605, -1.307287), Vector2(3, 4))"],
|
||||
[TYPE_TRANSFORM2D, Transform2D(Vector2(1,2), Vector2(3,4), Vector2.ONE),
|
||||
"Transform2D(Vector2(1, 2), Vector2(3, 4), Vector2(1, 1))"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(),
|
||||
"Transform3D()"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(Basis.FLIP_X, Vector3.ONE),
|
||||
"Transform3D(Vector3(-1, 0, 0), Vector3(0, 1, 0), Vector3(0, 0, 1), Vector3(1, 1, 1))"],
|
||||
[TYPE_TRANSFORM3D, Transform3D(Vector3(1,2,3), Vector3(4,5,6), Vector3(7,8,9), Vector3.ONE),
|
||||
"Transform3D(Vector3(1, 2, 3), Vector3(4, 5, 6), Vector3(7, 8, 9), Vector3(1, 1, 1))"],
|
||||
[TYPE_PROJECTION, Projection(),
|
||||
"Projection(Vector4(1, 0, 0, 0), Vector4(0, 1, 0, 0), Vector4(0, 0, 1, 0), Vector4(0, 0, 0, 1))"],
|
||||
[TYPE_PROJECTION, Projection(Vector4.ONE, Vector4.ONE*2, Vector4.ONE*3, Vector4.ZERO),
|
||||
"Projection(Vector4(1, 1, 1, 1), Vector4(2, 2, 2, 2), Vector4(3, 3, 3, 3), Vector4(0, 0, 0, 0))"]
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Plane(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_PLANE, Plane(), "Plane()"],
|
||||
[TYPE_PLANE, Plane(1,2,3,4), "Plane(1, 2, 3, 4)"],
|
||||
[TYPE_PLANE, Plane(Vector3.ONE, Vector3.ZERO), "Plane(1, 1, 1, 0)"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Quaternion(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_QUATERNION, Quaternion(), "Quaternion()"],
|
||||
[TYPE_QUATERNION, Quaternion(1,2,3,4), "Quaternion(1, 2, 3, 4)"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_AABB(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_AABB, AABB(), "AABB()"],
|
||||
[TYPE_AABB, AABB(Vector3.ONE, Vector3(10,20,30)), "AABB(Vector3(1, 1, 1), Vector3(10, 20, 30))"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Basis(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_BASIS, Basis(), "Basis()"],
|
||||
[TYPE_BASIS, Basis(Vector3(0.1,0.2,0.3).normalized(), .1),
|
||||
"Basis(Vector3(0.995361, 0.080758, -0.052293), Vector3(-0.079331, 0.996432, 0.028823), Vector3(0.054434, -0.024541, 0.998216))"],
|
||||
[TYPE_BASIS, Basis(Vector3.ONE, Vector3.ONE*2, Vector3.ONE*3),
|
||||
"Basis(Vector3(1, 1, 1), Vector3(2, 2, 2), Vector3(3, 3, 3))"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Color(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_COLOR, Color(), "Color()"],
|
||||
[TYPE_COLOR, Color.RED, "Color(1, 0, 0, 1)"],
|
||||
[TYPE_COLOR, Color(1,.2,.5,.5), "Color(1, 0.2, 0.5, 0.5)"],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_NodePath(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_NODE_PATH, NodePath(), 'NodePath()'],
|
||||
[TYPE_NODE_PATH, NodePath("/foo/bar"), 'NodePath("/foo/bar")'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_RID(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_RID, RID(), 'RID()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func _test_decode_Object(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_OBJECT, Node.new(), 'Node.new()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Callable(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_CALLABLE, Callable(), 'Callable()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Signal(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_SIGNAL, Signal(), 'Signal()'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Dictionary(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_DICTIONARY, {}, '{}'],
|
||||
[TYPE_DICTIONARY, Dictionary(), '{}'],
|
||||
[TYPE_DICTIONARY, {1:2, 2:3}, '{ 1: 2, 2: 3 }'],
|
||||
[TYPE_DICTIONARY, {"aa":2, "bb":"cc"}, '{ "aa": 2, "bb": "cc" }'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_Array(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_ARRAY, [], '[]'],
|
||||
[TYPE_ARRAY, Array(), '[]'],
|
||||
[TYPE_ARRAY, [1,2,3], '[1, 2, 3]'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_decode_typedArrays(variant_type :int, value, expected :String, test_parameters := [
|
||||
[TYPE_PACKED_BYTE_ARRAY, PackedByteArray(),
|
||||
'PackedByteArray()'],
|
||||
[TYPE_PACKED_BYTE_ARRAY, PackedByteArray([1, 2, 3]),
|
||||
'PackedByteArray([1, 2, 3])'],
|
||||
[TYPE_PACKED_COLOR_ARRAY, PackedColorArray(),
|
||||
'PackedColorArray()'],
|
||||
[TYPE_PACKED_COLOR_ARRAY, PackedColorArray([Color.RED, Color.BLUE]),
|
||||
'PackedColorArray([Color(1, 0, 0, 1), Color(0, 0, 1, 1)])'],
|
||||
[TYPE_PACKED_FLOAT32_ARRAY, PackedFloat32Array(),
|
||||
'PackedFloat32Array()'],
|
||||
[TYPE_PACKED_FLOAT32_ARRAY, PackedFloat32Array([1.2, 2.3]),
|
||||
'PackedFloat32Array([1.20000004768372, 2.29999995231628])'],
|
||||
[TYPE_PACKED_FLOAT64_ARRAY, PackedFloat64Array(),
|
||||
'PackedFloat64Array()'],
|
||||
[TYPE_PACKED_FLOAT64_ARRAY, PackedFloat64Array([1.2, 2.3]),
|
||||
'PackedFloat64Array([1.2, 2.3])'],
|
||||
[TYPE_PACKED_INT32_ARRAY, PackedInt32Array(),
|
||||
'PackedInt32Array()'],
|
||||
[TYPE_PACKED_INT32_ARRAY, PackedInt32Array([1, 2]),
|
||||
'PackedInt32Array([1, 2])'],
|
||||
[TYPE_PACKED_INT64_ARRAY, PackedInt64Array(),
|
||||
'PackedInt64Array()'],
|
||||
[TYPE_PACKED_INT64_ARRAY, PackedInt64Array([1, 2]),
|
||||
'PackedInt64Array([1, 2])'],
|
||||
[TYPE_PACKED_STRING_ARRAY, PackedStringArray(),
|
||||
'PackedStringArray()'],
|
||||
[TYPE_PACKED_STRING_ARRAY, PackedStringArray(["aa", "bb"]),
|
||||
'PackedStringArray(["aa", "bb"])'],
|
||||
[TYPE_PACKED_VECTOR2_ARRAY, PackedVector2Array(),
|
||||
'PackedVector2Array()'],
|
||||
[TYPE_PACKED_VECTOR2_ARRAY, PackedVector2Array([Vector2.ONE, Vector2.ONE*2]),
|
||||
'PackedVector2Array([Vector2(1, 1), Vector2(2, 2)])'],
|
||||
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array(),
|
||||
'PackedVector3Array()'],
|
||||
[TYPE_PACKED_VECTOR3_ARRAY, PackedVector3Array([Vector3.ONE, Vector3.ONE*2]),
|
||||
'PackedVector3Array([Vector3(1, 1, 1), Vector3(2, 2, 2)])'],
|
||||
]) -> void:
|
||||
assert_that(GdDefaultValueDecoder.decode_typed(variant_type, value)).is_equal(expected)
|
||||
_tested_types[variant_type] = 1
|
||||
76
addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd
Normal file
76
addons/gdUnit4/test/core/parse/GdFunctionArgumentTest.gd
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdFunctionArgumentTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionArgument.gd'
|
||||
|
||||
|
||||
func test__parse_argument_as_array_typ1() -> void:
|
||||
var test_parameters := """[
|
||||
[1, "flowchart TD\nid>This is a flag shaped node]"],
|
||||
[
|
||||
2,
|
||||
"flowchart TD\nid(((This is a\tdouble circle node)))"
|
||||
],
|
||||
[3,
|
||||
"flowchart TD\nid((This is a circular node))"],
|
||||
[
|
||||
4, "flowchart TD\nid>This is a flag shaped node]"
|
||||
],
|
||||
[5, "flowchart TD\nid{'This is a rhombus node'}"],
|
||||
[6, 'flowchart TD\nid((This is a circular node))'],
|
||||
[7, 'flowchart TD\nid>This is a flag shaped node]'], [8, 'flowchart TD\nid{"This is a rhombus node"}'],
|
||||
[9, \"\"\"
|
||||
flowchart TD
|
||||
id{"This is a rhombus node"}
|
||||
\"\"\"]
|
||||
]"""
|
||||
|
||||
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly([
|
||||
"""[1, "flowchart TDid>This is a flag shaped node]"]""",
|
||||
"""[2, "flowchart TDid(((This is a\tdouble circle node)))"]""",
|
||||
"""[3, "flowchart TDid((This is a circular node))"]""",
|
||||
"""[4, "flowchart TDid>This is a flag shaped node]"]""",
|
||||
"""[5, "flowchart TDid{'This is a rhombus node'}"]""",
|
||||
"""[6, 'flowchart TDid((This is a circular node))']""",
|
||||
"""[7, 'flowchart TDid>This is a flag shaped node]']""",
|
||||
"""[8, 'flowchart TDid{"This is a rhombus node"}']""",
|
||||
"""[9, \"\"\"flowchart TDid{"This is a rhombus node"}\"\"\"]"""
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func test__parse_argument_as_array_typ2() -> void:
|
||||
var test_parameters := """[
|
||||
["test_a", null, "LOG", {}],
|
||||
[
|
||||
"test_b",
|
||||
Node2D,
|
||||
null,
|
||||
{Node2D: "ER,ROR"}
|
||||
],
|
||||
[
|
||||
"test_c",
|
||||
Node2D,
|
||||
"LOG",
|
||||
{Node2D: "LOG"}
|
||||
]
|
||||
]"""
|
||||
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).contains_exactly([
|
||||
"""["test_a", null, "LOG", {}]""",
|
||||
"""["test_b", Node2D, null, {Node2D: "ER,ROR"}]""",
|
||||
"""["test_c", Node2D, "LOG", {Node2D: "LOG"}]"""
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
func test__parse_argument_as_reference() -> void:
|
||||
var test_parameters := "_test_args()"
|
||||
|
||||
var fa := GdFunctionArgument.new(GdFunctionArgument.ARG_PARAMETERIZED_TEST, TYPE_STRING, test_parameters)
|
||||
assert_array(fa.parameter_sets()).is_empty()
|
||||
146
addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd
Normal file
146
addons/gdUnit4/test/core/parse/GdFunctionDescriptorTest.gd
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdFunctionDescriptorTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdFunctionDescriptor.gd'
|
||||
|
||||
|
||||
# helper to get method descriptor
|
||||
func get_method_description(clazz_name :String, method_name :String) -> Dictionary:
|
||||
var method_list :Array = ClassDB.class_get_method_list(clazz_name)
|
||||
for method_descriptor in method_list:
|
||||
if method_descriptor["name"] == method_name:
|
||||
return method_descriptor
|
||||
return Dictionary()
|
||||
|
||||
|
||||
func test_extract_from_func_without_return_type():
|
||||
# void add_sibling(sibling: Node, force_readable_name: bool = false)
|
||||
var method_descriptor := get_method_description("Node", "add_sibling")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("add_sibling")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(TYPE_NIL)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("sibling_", GdObjects.TYPE_NODE),
|
||||
GdFunctionArgument.new("force_readable_name_", TYPE_BOOL, "false")
|
||||
])
|
||||
# void add_sibling(node: Node, child_node: Node, legible_unique_name: bool = false)
|
||||
assert_str(fd.typeless()).is_equal("func add_sibling(sibling_, force_readable_name_=false) -> void:")
|
||||
|
||||
|
||||
func test_extract_from_func_with_return_type():
|
||||
# Node find_child(pattern: String, recursive: bool = true, owned: bool = true) const
|
||||
var method_descriptor := get_method_description("Node", "find_child")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("find_child")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(TYPE_OBJECT)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("pattern_", TYPE_STRING),
|
||||
GdFunctionArgument.new("recursive_", TYPE_BOOL, "true"),
|
||||
GdFunctionArgument.new("owned_", TYPE_BOOL, "true"),
|
||||
])
|
||||
# Node find_child(mask: String, recursive: bool = true, owned: bool = true) const
|
||||
assert_str(fd.typeless()).is_equal("func find_child(pattern_, recursive_=true, owned_=true) -> Node:")
|
||||
|
||||
|
||||
func test_extract_from_func_with_vararg():
|
||||
# Error emit_signal(signal: StringName, ...) vararg
|
||||
var method_descriptor := get_method_description("Node", "emit_signal")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("emit_signal")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_true()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_array(fd.args()).contains_exactly([GdFunctionArgument.new("signal_", TYPE_STRING_NAME)])
|
||||
assert_array(fd.varargs()).contains_exactly([
|
||||
GdFunctionArgument.new("vararg0_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg1_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg2_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg3_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg4_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg5_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg6_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg7_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg8_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE),
|
||||
GdFunctionArgument.new("vararg9_", GdObjects.TYPE_VARARG, "\"%s\"" % GdObjects.TYPE_VARARG_PLACEHOLDER_VALUE)
|
||||
])
|
||||
assert_str(fd.typeless()).is_equal("func emit_signal(signal_, vararg0_=\"__null__\", vararg1_=\"__null__\", vararg2_=\"__null__\", vararg3_=\"__null__\", vararg4_=\"__null__\", vararg5_=\"__null__\", vararg6_=\"__null__\", vararg7_=\"__null__\", vararg8_=\"__null__\", vararg9_=\"__null__\") -> Error:")
|
||||
|
||||
|
||||
func test_extract_from_descriptor_is_virtual_func():
|
||||
var method_descriptor := get_method_description("Node", "_enter_tree")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("_enter_tree")
|
||||
assert_bool(fd.is_virtual()).is_true()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(TYPE_NIL)
|
||||
assert_array(fd.args()).is_empty()
|
||||
# void _enter_tree() virtual
|
||||
assert_str(fd.typeless()).is_equal("func _enter_tree() -> void:")
|
||||
|
||||
|
||||
func test_extract_from_descriptor_is_virtual_func_full_check():
|
||||
var methods := ClassDB.class_get_method_list("Node")
|
||||
var expected_virtual_functions := [
|
||||
# Object virtuals
|
||||
"_get",
|
||||
"_get_property_list",
|
||||
"_init",
|
||||
"_notification",
|
||||
"_property_can_revert",
|
||||
"_property_get_revert",
|
||||
"_set",
|
||||
"_to_string",
|
||||
# Note virtuals
|
||||
"_enter_tree",
|
||||
"_exit_tree",
|
||||
"_get_configuration_warnings",
|
||||
"_input",
|
||||
"_physics_process",
|
||||
"_process",
|
||||
"_ready",
|
||||
"_shortcut_input",
|
||||
"_unhandled_input",
|
||||
"_unhandled_key_input"
|
||||
]
|
||||
# since Godot 4.2 there are more virtual functions
|
||||
if Engine.get_version_info().hex >= 0x40200:
|
||||
expected_virtual_functions.append("_validate_property")
|
||||
|
||||
var _count := 0
|
||||
for method_descriptor in methods:
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
|
||||
if fd.is_virtual():
|
||||
_count += 1
|
||||
assert_array(expected_virtual_functions).contains([fd.name()])
|
||||
assert_int(_count).is_equal(expected_virtual_functions.size())
|
||||
|
||||
|
||||
func test_extract_from_func_with_return_type_variant():
|
||||
var method_descriptor := get_method_description("Node", "get")
|
||||
var fd := GdFunctionDescriptor.extract_from(method_descriptor)
|
||||
assert_str(fd.name()).is_equal("get")
|
||||
assert_bool(fd.is_virtual()).is_false()
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_bool(fd.is_engine()).is_true()
|
||||
assert_bool(fd.is_vararg()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("property_", TYPE_STRING_NAME),
|
||||
])
|
||||
# Variant get(property: String) const
|
||||
assert_str(fd.typeless()).is_equal("func get(property_) -> Variant:")
|
||||
632
addons/gdUnit4/test/core/parse/GdScriptParserTest.gd
Normal file
632
addons/gdUnit4/test/core/parse/GdScriptParserTest.gd
Normal file
|
|
@ -0,0 +1,632 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
var _parser: GdScriptParser
|
||||
|
||||
|
||||
func before():
|
||||
_parser = GdScriptParser.new()
|
||||
|
||||
|
||||
func test_parse_argument():
|
||||
# create example row whit different assignment types
|
||||
var row = "func test_foo(arg1 = 41, arg2 := 42, arg3 : int = 43)"
|
||||
assert_that(_parser.parse_argument(row, "arg1", 23)).is_equal(41)
|
||||
assert_that(_parser.parse_argument(row, "arg2", 23)).is_equal(42)
|
||||
assert_that(_parser.parse_argument(row, "arg3", 23)).is_equal(43)
|
||||
|
||||
|
||||
func test_parse_argument_default_value():
|
||||
# arg4 not exists expect to return the default value
|
||||
var row = "func test_foo(arg1 = 41, arg2 := 42, arg3 : int = 43)"
|
||||
assert_that(_parser.parse_argument(row, "arg4", 23)).is_equal(23)
|
||||
|
||||
|
||||
func test_parse_argument_has_no_arguments():
|
||||
assert_that(_parser.parse_argument("func test_foo()", "arg4", 23)).is_equal(23)
|
||||
|
||||
|
||||
func test_parse_argument_with_bad_formatting():
|
||||
var row = "func test_foo( arg1 = 41, arg2 : = 42, arg3 : int = 43 )"
|
||||
assert_that(_parser.parse_argument(row, "arg3", 23)).is_equal(43)
|
||||
|
||||
|
||||
func test_parse_argument_with_same_func_name():
|
||||
var row = "func test_arg1(arg1 = 41)"
|
||||
assert_that(_parser.parse_argument(row, "arg1", 23)).is_equal(41)
|
||||
|
||||
|
||||
func test_parse_argument_timeout():
|
||||
var DEFAULT_TIMEOUT = 1000
|
||||
assert_that(_parser.parse_argument("func test_foo()", "timeout", DEFAULT_TIMEOUT)).is_equal(DEFAULT_TIMEOUT)
|
||||
assert_that(_parser.parse_argument("func test_foo(timeout = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
assert_that(_parser.parse_argument("func test_foo(timeout: = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
assert_that(_parser.parse_argument("func test_foo(timeout:int = 2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
assert_that(_parser.parse_argument("func test_foo(arg1 = false, timeout=2000)", "timeout", DEFAULT_TIMEOUT)).is_equal(2000)
|
||||
|
||||
|
||||
func test_parse_arguments():
|
||||
assert_array(_parser.parse_arguments("func foo():")) \
|
||||
.has_size(0)
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo() -> String:\n")) \
|
||||
.has_size(0)
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1, arg2, name):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_NIL),
|
||||
GdFunctionArgument.new("arg2", TYPE_NIL),
|
||||
GdFunctionArgument.new("name", TYPE_NIL)])
|
||||
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :int, arg2 :bool, name :String = "abc"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, '"abc"')])
|
||||
|
||||
assert_array(_parser.parse_arguments('func bar(arg1 :int, arg2 :int = 23, name :String = "test") -> String:')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_INT, "23"),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, '"test"')])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1, arg2=value(1,2,3), name:=foo()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_NIL),
|
||||
GdFunctionArgument.new("arg2", GdObjects.TYPE_FUNC, "value(1,2,3)"),
|
||||
GdFunctionArgument.new("name", GdObjects.TYPE_FUNC, "foo()")])
|
||||
# enum as prefix in value name
|
||||
assert_array(_parser.parse_arguments("func get_value( type := ENUM_A) -> int:"))\
|
||||
.contains_exactly([GdFunctionArgument.new("type", TYPE_STRING, "ENUM_A")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func create_timer(timeout :float) -> Timer:")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("timeout", TYPE_FLOAT)])
|
||||
|
||||
# array argument
|
||||
assert_array(_parser.parse_arguments("func foo(a :int, b :int, parameters = [[1, 2], [3, 4], [5, 6]]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("a", TYPE_INT),
|
||||
GdFunctionArgument.new("b", TYPE_INT),
|
||||
GdFunctionArgument.new("parameters", TYPE_ARRAY, "[[1, 2], [3, 4], [5, 6]]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func test_values(a:Vector2, b:Vector2, expected:Vector2, test_parameters:=[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]):"))\
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("a", TYPE_VECTOR2),
|
||||
GdFunctionArgument.new("b", TYPE_VECTOR2),
|
||||
GdFunctionArgument.new("expected", TYPE_VECTOR2),
|
||||
GdFunctionArgument.new("test_parameters", TYPE_ARRAY, "[[Vector2.ONE,Vector2.ONE,Vector2(1,1)]]"),
|
||||
])
|
||||
|
||||
|
||||
func test_parse_arguments_with_super_constructor():
|
||||
assert_array(_parser.parse_arguments('func foo().foo("abc"):')).is_empty()
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 = "arg").foo("abc", arg1):'))\
|
||||
.contains_exactly([GdFunctionArgument.new("arg1", TYPE_STRING, '"arg"')])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_String():
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2="default"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
|
||||
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2 :="default"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
|
||||
|
||||
assert_array(_parser.parse_arguments('func foo(arg1 :String, arg2 :String ="default"):')) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_STRING, '"default"')])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Boolean():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :bool=false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Real():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=3.14):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=3.14):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :float=3.14):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_FLOAT, "3.14")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Array():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=Array()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "Array()")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=[1, 2, 3]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=[]):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[]")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Array=[1, 2, 3], arg3 := false):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_ARRAY, "[1, 2, 3]"),
|
||||
GdFunctionArgument.new("arg3", TYPE_BOOL, "false")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Color():
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2=Color.RED):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :=Color.RED):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func foo(arg1 :String, arg2 :Color=Color.RED):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_COLOR, "Color.RED")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_Vector():
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 =Vector3.FORWARD):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :=Vector3.FORWARD):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :Vector3=Vector3.FORWARD):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_type_AABB():
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 := AABB()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_AABB, "AABB()")])
|
||||
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 :AABB=AABB()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_AABB, "AABB()")])
|
||||
|
||||
|
||||
func test_parse_arguments_default_build_in_types():
|
||||
assert_array(_parser.parse_arguments("func bar(arg1 :String, arg2 := Vector3.FORWARD, aabb := AABB()):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_STRING),
|
||||
GdFunctionArgument.new("arg2", TYPE_VECTOR3, "Vector3.FORWARD"),
|
||||
GdFunctionArgument.new("aabb", TYPE_AABB, "AABB()")])
|
||||
|
||||
|
||||
func test_parse_arguments_fuzzers() -> void:
|
||||
assert_array(_parser.parse_arguments("func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(), fuzzer_c :Fuzzer = fuzz_c(), fuzzer_iterations = 234, fuzzer_seed = 100):")) \
|
||||
.contains_exactly([
|
||||
GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "fuzz_a()"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "fuzz_b()"),
|
||||
GdFunctionArgument.new("fuzzer_c", GdObjects.TYPE_FUZZER, "fuzz_c()"),
|
||||
GdFunctionArgument.new("fuzzer_iterations", TYPE_INT, "234"),
|
||||
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, "100"),])
|
||||
|
||||
|
||||
func test_parse_arguments_no_function():
|
||||
assert_array(_parser.parse_arguments("var x:=10")) \
|
||||
.has_size(0)
|
||||
|
||||
|
||||
class TestObject:
|
||||
var x
|
||||
|
||||
|
||||
func test_parse_function_return_type():
|
||||
assert_that(_parser.parse_func_return_type("func foo():")).is_equal(TYPE_NIL)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> void:")).is_equal(GdObjects.TYPE_VOID)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> TestObject:")).is_equal(TYPE_OBJECT)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> bool:")).is_equal(TYPE_BOOL)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> String:")).is_equal(TYPE_STRING)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> int:")).is_equal(TYPE_INT)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> float:")).is_equal(TYPE_FLOAT)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Vector2:")).is_equal(TYPE_VECTOR2)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Rect2:")).is_equal(TYPE_RECT2)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Vector3:")).is_equal(TYPE_VECTOR3)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Transform2D:")).is_equal(TYPE_TRANSFORM2D)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Plane:")).is_equal(TYPE_PLANE)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Quaternion:")).is_equal(TYPE_QUATERNION)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> AABB:")).is_equal(TYPE_AABB)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Basis:")).is_equal(TYPE_BASIS)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Transform3D:")).is_equal(TYPE_TRANSFORM3D)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Color:")).is_equal(TYPE_COLOR)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> NodePath:")).is_equal(TYPE_NODE_PATH)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> RID:")).is_equal(TYPE_RID)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Dictionary:")).is_equal(TYPE_DICTIONARY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> Array:")).is_equal(TYPE_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedByteArray:")).is_equal(TYPE_PACKED_BYTE_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedInt32Array:")).is_equal(TYPE_PACKED_INT32_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedFloat32Array:")).is_equal(TYPE_PACKED_FLOAT32_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedStringArray:")).is_equal(TYPE_PACKED_STRING_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedVector2Array:")).is_equal(TYPE_PACKED_VECTOR2_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedVector3Array:")).is_equal(TYPE_PACKED_VECTOR3_ARRAY)
|
||||
assert_that(_parser.parse_func_return_type("func foo() -> PackedColorArray:")).is_equal(TYPE_PACKED_COLOR_ARRAY)
|
||||
|
||||
|
||||
func test_parse_func_name():
|
||||
assert_str(_parser.parse_func_name("func foo():")).is_equal("foo")
|
||||
assert_str(_parser.parse_func_name("static func foo():")).is_equal("foo")
|
||||
assert_str(_parser.parse_func_name("func a() -> String:")).is_equal("a")
|
||||
# function name contains tokens e.g func or class
|
||||
assert_str(_parser.parse_func_name("func foo_func_class():")).is_equal("foo_func_class")
|
||||
# should fail
|
||||
assert_str(_parser.parse_func_name("#func foo():")).is_empty()
|
||||
assert_str(_parser.parse_func_name("var x")).is_empty()
|
||||
|
||||
|
||||
func test_extract_source_code():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
|
||||
var file_content := resource_as_array(path[0])
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_source_code_inner_class_AtmosphereData():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass.AtmosphereData)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/AtmosphereData.txt")
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_source_code_inner_class_SoundData():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass.SoundData)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/SoundData.txt")
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_source_code_inner_class_Area4D():
|
||||
var path := GdObjects.extract_class_path(AdvancedTestClass.Area4D)
|
||||
var rows = _parser.extract_source_code(path)
|
||||
var file_content := resource_as_array("res://addons/gdUnit4/test/core/resources/Area4D.txt")
|
||||
assert_array(rows).contains_exactly(file_content)
|
||||
|
||||
|
||||
func test_extract_function_signature() -> void:
|
||||
var path := GdObjects.extract_class_path("res://addons/gdUnit4/test/mocker/resources/ClassWithCustomFormattings.gd")
|
||||
var rows = _parser.extract_source_code(path)
|
||||
|
||||
assert_that(_parser.extract_func_signature(rows, 12))\
|
||||
.is_equal("""
|
||||
func a1(set_name:String, path:String="", load_on_init:bool=false,
|
||||
set_auto_save:bool=false, set_network_sync:bool=false
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 19))\
|
||||
.is_equal("""
|
||||
func a2(set_name:String, path:String="", load_on_init:bool=false,
|
||||
set_auto_save:bool=false, set_network_sync:bool=false
|
||||
) -> void:""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 26))\
|
||||
.is_equal("""
|
||||
func a3(set_name:String, path:String="", load_on_init:bool=false,
|
||||
set_auto_save:bool=false, set_network_sync:bool=false
|
||||
) :""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 33))\
|
||||
.is_equal("""
|
||||
func a4(set_name:String,
|
||||
path:String="",
|
||||
load_on_init:bool=false,
|
||||
set_auto_save:bool=false,
|
||||
set_network_sync:bool=false
|
||||
):""".dedent().trim_prefix("\n"))
|
||||
assert_that(_parser.extract_func_signature(rows, 43))\
|
||||
.is_equal("""
|
||||
func a5(
|
||||
value : Array,
|
||||
expected : String,
|
||||
test_parameters : Array = [
|
||||
[ ["a"], "a" ],
|
||||
[ ["a", "very", "long", "argument"], "a very long argument" ],
|
||||
]
|
||||
):""".dedent().trim_prefix("\n"))
|
||||
|
||||
|
||||
func test_strip_leading_spaces():
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("")).is_empty()
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_empty()
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_empty()
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces(" ")).is_equal(" ")
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("var x=")).is_equal("var x=")
|
||||
assert_str(GdScriptParser.TokenInnerClass._strip_leading_spaces("class foo")).is_equal("class foo")
|
||||
|
||||
|
||||
func test_extract_clazz_name():
|
||||
assert_str(_parser.extract_clazz_name("classSoundData:\n")).is_equal("SoundData")
|
||||
assert_str(_parser.extract_clazz_name("classSoundDataextendsNode:\n")).is_equal("SoundData")
|
||||
|
||||
|
||||
func test_is_virtual_func() -> void:
|
||||
# checked non virtual func
|
||||
assert_bool(_parser.is_virtual_func("UnknownClass", [""], "")).is_false()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "")).is_false()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "func foo():")).is_false()
|
||||
# checked virtual func
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "_exit_tree")).is_true()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "_ready")).is_true()
|
||||
assert_bool(_parser.is_virtual_func("Node", [""], "_init")).is_true()
|
||||
|
||||
|
||||
func test_is_static_func():
|
||||
assert_bool(_parser.is_static_func("")).is_false()
|
||||
assert_bool(_parser.is_static_func("var a=0")).is_false()
|
||||
assert_bool(_parser.is_static_func("func foo():")).is_false()
|
||||
assert_bool(_parser.is_static_func("func foo() -> void:")).is_false()
|
||||
assert_bool(_parser.is_static_func("static func foo():")).is_true()
|
||||
assert_bool(_parser.is_static_func("static func foo() -> void:")).is_true()
|
||||
|
||||
|
||||
func test_parse_func_description():
|
||||
var fd := _parser.parse_func_description("func foo():", "clazz_name", [""], 10)
|
||||
assert_str(fd.name()).is_equal("foo")
|
||||
assert_bool(fd.is_static()).is_false()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
|
||||
assert_array(fd.args()).is_empty()
|
||||
assert_str(fd.typeless()).is_equal("func foo() -> Variant:")
|
||||
|
||||
# static function
|
||||
fd = _parser.parse_func_description("static func foo(arg1 :int, arg2:=false) -> String:", "clazz_name", [""], 22)
|
||||
assert_str(fd.name()).is_equal("foo")
|
||||
assert_bool(fd.is_static()).is_true()
|
||||
assert_int(fd.return_type()).is_equal(TYPE_STRING)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")
|
||||
])
|
||||
assert_str(fd.typeless()).is_equal("static func foo(arg1, arg2=false) -> String:")
|
||||
|
||||
# static function without return type
|
||||
fd = _parser.parse_func_description("static func foo(arg1 :int, arg2:=false):", "clazz_name", [""], 23)
|
||||
assert_str(fd.name()).is_equal("foo")
|
||||
assert_bool(fd.is_static()).is_true()
|
||||
assert_int(fd.return_type()).is_equal(GdObjects.TYPE_VARIANT)
|
||||
assert_array(fd.args()).contains_exactly([
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_BOOL, "false")
|
||||
])
|
||||
assert_str(fd.typeless()).is_equal("static func foo(arg1, arg2=false) -> Variant:")
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_enum():
|
||||
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
|
||||
assert_result(result).is_success()
|
||||
|
||||
var fd := _parser.parse_func_description("func get_enum() -> TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
|
||||
assert_that(fd.name()).is_equal("get_enum")
|
||||
assert_that(fd.is_static()).is_false()
|
||||
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_that(fd._return_class).is_equal("ClassWithEnumReturnTypes.TEST_ENUM")
|
||||
assert_that(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_internal_class_enum():
|
||||
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
|
||||
assert_result(result).is_success()
|
||||
|
||||
var fd := _parser.parse_func_description("func get_inner_class_enum() -> InnerClass.TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
|
||||
assert_that(fd.name()).is_equal("get_inner_class_enum")
|
||||
assert_that(fd.is_static()).is_false()
|
||||
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_that(fd._return_class).is_equal("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")
|
||||
assert_that(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_parse_func_description_return_type_external_class_enum():
|
||||
var result := _parser.parse("ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"])
|
||||
assert_result(result).is_success()
|
||||
|
||||
var fd := _parser.parse_func_description("func get_external_class_enum() -> CustomEnums.TEST_ENUM:", "ClassWithEnumReturnTypes", ["res://addons/gdUnit4/test/mocker/resources/ClassWithEnumReturnTypes.gd"], 33)
|
||||
assert_that(fd.name()).is_equal("get_external_class_enum")
|
||||
assert_that(fd.is_static()).is_false()
|
||||
assert_that(fd.return_type()).is_equal(GdObjects.TYPE_ENUM)
|
||||
assert_that(fd._return_class).is_equal("CustomEnums.TEST_ENUM")
|
||||
assert_that(fd.args()).is_empty()
|
||||
|
||||
|
||||
func test_parse_class_inherits():
|
||||
var clazz_path := GdObjects.extract_class_path(CustomClassExtendsCustomClass)
|
||||
var clazz_name := GdObjects.extract_class_name_from_class_path(clazz_path)
|
||||
var result := _parser.parse(clazz_name, clazz_path)
|
||||
assert_result(result).is_success()
|
||||
|
||||
# verify class extraction
|
||||
var clazz_desccriptor :GdClassDescriptor = result.value()
|
||||
assert_object(clazz_desccriptor).is_not_null()
|
||||
assert_str(clazz_desccriptor.name()).is_equal("CustomClassExtendsCustomClass")
|
||||
assert_bool(clazz_desccriptor.is_inner_class()).is_false()
|
||||
assert_array(clazz_desccriptor.functions()).contains_exactly([
|
||||
GdFunctionDescriptor.new("foo2", 5, false, false, false, GdObjects.TYPE_VARIANT, "", []),
|
||||
GdFunctionDescriptor.new("bar2", 8, false, false, false, TYPE_STRING, "", [])
|
||||
])
|
||||
|
||||
# extends from CustomResourceTestClass
|
||||
clazz_desccriptor = clazz_desccriptor.parent()
|
||||
assert_object(clazz_desccriptor).is_not_null()
|
||||
assert_str(clazz_desccriptor.name()).is_equal("CustomResourceTestClass")
|
||||
assert_bool(clazz_desccriptor.is_inner_class()).is_false()
|
||||
assert_array(clazz_desccriptor.functions()).contains_exactly([
|
||||
GdFunctionDescriptor.new("foo", 4, false, false, false, TYPE_STRING, "", []),
|
||||
GdFunctionDescriptor.new("foo2", 7, false, false, false, GdObjects.TYPE_VARIANT, "", []),
|
||||
GdFunctionDescriptor.new("foo_void", 10, false, false, false, GdObjects.TYPE_VOID, "", []),
|
||||
GdFunctionDescriptor.new("bar", 13, false, false, false, TYPE_STRING, "", [
|
||||
GdFunctionArgument.new("arg1", TYPE_INT),
|
||||
GdFunctionArgument.new("arg2", TYPE_INT, "23"),
|
||||
GdFunctionArgument.new("name", TYPE_STRING, '"test"'),
|
||||
]),
|
||||
GdFunctionDescriptor.new("foo5", 16, false, false, false, GdObjects.TYPE_VARIANT, "", []),
|
||||
])
|
||||
|
||||
# no other class extends
|
||||
clazz_desccriptor = clazz_desccriptor.parent()
|
||||
assert_object(clazz_desccriptor).is_null()
|
||||
|
||||
|
||||
func test_get_class_name_pascal_case() -> void:
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd")))\
|
||||
.is_equal("PascalCaseWithClassName")
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithoutClassName.gd")))\
|
||||
.is_equal("PascalCaseWithoutClassName")
|
||||
|
||||
|
||||
func test_get_class_name_snake_case() -> void:
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_with_class_name.gd")))\
|
||||
.is_equal("SnakeCaseWithClassName")
|
||||
assert_str(_parser.get_class_name(load("res://addons/gdUnit4/test/core/resources/naming_conventions/snake_case_without_class_name.gd")))\
|
||||
.is_equal("SnakeCaseWithoutClassName")
|
||||
|
||||
|
||||
func test_is_func_end() -> void:
|
||||
assert_bool(_parser.is_func_end("")).is_false()
|
||||
assert_bool(_parser.is_func_end("func test_a():")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a() -> void:")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1) :")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1 ): ")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1 ): ")).is_true()
|
||||
assert_bool(_parser.is_func_end(" ):")).is_true()
|
||||
assert_bool(_parser.is_func_end(" ):")).is_true()
|
||||
assert_bool(_parser.is_func_end(" -> void:")).is_true()
|
||||
assert_bool(_parser.is_func_end(" ) -> void :")).is_true()
|
||||
assert_bool(_parser.is_func_end("func test_a(arg1, arg2 = {1:2} ):")).is_true()
|
||||
|
||||
|
||||
func test_extract_func_signature_multiline() -> void:
|
||||
var source_code = """
|
||||
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):
|
||||
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
""".dedent().split("\n")
|
||||
|
||||
var fs = _parser.extract_func_signature(source_code, 0)
|
||||
|
||||
assert_that(fs).is_equal("""
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):"""
|
||||
.dedent()
|
||||
.trim_prefix("\n")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_description_paramized_test():
|
||||
var fd = _parser.parse_func_description("functest_parameterized(a:int,b:int,c:int,expected:int,parameters=[[1,2,3,6],[3,4,5,11],[6,7,8,21]]):", "class", ["path"], 22)
|
||||
|
||||
assert_that(fd).is_equal(GdFunctionDescriptor.new("test_parameterized", 22, false, false, false, GdObjects.TYPE_VARIANT, "", [
|
||||
GdFunctionArgument.new("a", TYPE_INT),
|
||||
GdFunctionArgument.new("b", TYPE_INT),
|
||||
GdFunctionArgument.new("c", TYPE_INT),
|
||||
GdFunctionArgument.new("expected", TYPE_INT),
|
||||
GdFunctionArgument.new("parameters", TYPE_ARRAY, "[[1,2,3,6],[3,4,5,11],[6,7,8,21]]"),
|
||||
]))
|
||||
|
||||
|
||||
func test_parse_func_description_paramized_test_with_comments() -> void:
|
||||
var source_code = """
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
|
||||
# before data set
|
||||
[1, 2, 3, 6], # after data set
|
||||
# between data sets
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 'string #ABCD', 21], # dataset with [comment] singn
|
||||
[6, 7, "string #ABCD", 21] # dataset with "#comment" singn
|
||||
#eof
|
||||
]):
|
||||
pass
|
||||
""".dedent().split("\n")
|
||||
|
||||
var fs = _parser.extract_func_signature(source_code, 0)
|
||||
|
||||
assert_that(fs).is_equal("""
|
||||
func test_parameterized(a: int, b :int, c :int, expected :int, parameters = [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 'string #ABCD', 21],
|
||||
[6, 7, "string #ABCD", 21]
|
||||
]):"""
|
||||
.dedent()
|
||||
.trim_prefix("\n")
|
||||
)
|
||||
|
||||
|
||||
func test_parse_func_descriptor_with_fuzzers():
|
||||
var source_code := """
|
||||
func test_foo(fuzzer_a = fuzz_a(), fuzzer_b := fuzz_b(),
|
||||
fuzzer_c :Fuzzer = fuzz_c(),
|
||||
fuzzer = Fuzzers.random_rangei(-23, 22),
|
||||
fuzzer_iterations = 234,
|
||||
fuzzer_seed = 100):
|
||||
""".split("\n")
|
||||
var fs = _parser.extract_func_signature(source_code, 0)
|
||||
var fd = _parser.parse_func_description(fs, "class", ["path"], 22)
|
||||
|
||||
assert_that(fd).is_equal(GdFunctionDescriptor.new("test_foo", 22, false, false, false, GdObjects.TYPE_VARIANT, "", [
|
||||
GdFunctionArgument.new("fuzzer_a", GdObjects.TYPE_FUZZER, "fuzz_a()"),
|
||||
GdFunctionArgument.new("fuzzer_b", GdObjects.TYPE_FUZZER, "fuzz_b()"),
|
||||
GdFunctionArgument.new("fuzzer_c", GdObjects.TYPE_FUZZER, "fuzz_c()"),
|
||||
GdFunctionArgument.new("fuzzer", GdObjects.TYPE_FUZZER, "Fuzzers.random_rangei(-23, 22)"),
|
||||
GdFunctionArgument.new("fuzzer_iterations", TYPE_INT, "234"),
|
||||
GdFunctionArgument.new("fuzzer_seed", TYPE_INT, "100")
|
||||
]))
|
||||
|
||||
|
||||
func test_is_class_enum_type() -> void:
|
||||
var parser := GdScriptParser.new()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.InnerClass.TEST_ENUM")).is_true()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.InnerClass")).is_false()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.TEST_ENUM")).is_true()
|
||||
assert_that(parser.is_class_enum_type("CustomEnums.TEST_ENUM")).is_true()
|
||||
assert_that(parser.is_class_enum_type("CustomEnums")).is_false()
|
||||
assert_that(parser.is_class_enum_type("ClassWithEnumReturnTypes.NOT_AN_ENUM")).is_false()
|
||||
65
addons/gdUnit4/test/core/parse/GdUnitExpressionRunnerTest.gd
Normal file
65
addons/gdUnit4/test/core/parse/GdUnitExpressionRunnerTest.gd
Normal file
|
|
@ -0,0 +1,65 @@
|
|||
# GdUnit generated TestSuite
|
||||
class_name GdUnitExpressionsTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitExpressionRunner.gd'
|
||||
|
||||
const TestFuzzers := preload("res://addons/gdUnit4/test/fuzzers/TestFuzzers.gd")
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_default():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(-10, 22)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(-10, 22)
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_with_constants():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(-10, 22)
|
||||
|
||||
|
||||
func test_create_fuzzer_argument_with_custom_function():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "get_fuzzer()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer).is_instanceof(Fuzzer)
|
||||
assert_int(fuzzer.next_value()).is_between(TestFuzzers.MIN_VALUE, TestFuzzers.MAX_VALUE)
|
||||
|
||||
|
||||
func test_create_fuzzer_do_fail():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "non_fuzzer()")
|
||||
assert_that(fuzzer).is_null()
|
||||
|
||||
|
||||
func test_create_nested_fuzzer_do_fail():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "NestedFuzzer.new()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestFuzzers.NestedFuzzer).is_true()
|
||||
|
||||
|
||||
func test_create_external_fuzzer():
|
||||
var fuzzer := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "TestExternalFuzzer.new()")
|
||||
assert_that(fuzzer).is_not_null()
|
||||
assert_that(fuzzer is Fuzzer).is_true()
|
||||
assert_bool(fuzzer is TestExternalFuzzer).is_true()
|
||||
|
||||
|
||||
func test_create_multipe_fuzzers():
|
||||
var fuzzer_a := GdUnitExpressionRunner.new().to_fuzzer(TestFuzzers, "Fuzzers.rangei(-10, MAX_VALUE)")
|
||||
var fuzzer_b := GdUnitExpressionRunner.new().to_fuzzer(GDScript.new(), "Fuzzers.rangei(10, 20)")
|
||||
assert_that(fuzzer_a).is_not_null()
|
||||
assert_that(fuzzer_a).is_instanceof(IntFuzzer)
|
||||
var a :IntFuzzer = fuzzer_a
|
||||
assert_int(a._from).is_equal(-10)
|
||||
assert_int(a._to).is_equal(TestFuzzers.MAX_VALUE)
|
||||
assert_that(fuzzer_b).is_not_null()
|
||||
assert_that(fuzzer_b).is_instanceof(IntFuzzer)
|
||||
var b :IntFuzzer = fuzzer_b
|
||||
assert_int(b._from).is_equal(10)
|
||||
assert_int(b._to).is_equal(20)
|
||||
|
|
@ -0,0 +1,222 @@
|
|||
# GdUnit generated TestSuite
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/parse/GdUnitTestParameterSetResolver.gd'
|
||||
|
||||
|
||||
var _test_param1 := 10
|
||||
var _test_param2 := 20
|
||||
|
||||
|
||||
func before():
|
||||
_test_param1 = 11
|
||||
|
||||
|
||||
func test_before():
|
||||
_test_param2 = 22
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_a(a: int, b: int, test_parameters=[[1, 2], [3,4]]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_b(a: Vector2, b: Vector2, test_parameters=[
|
||||
[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_c(a: Object, b: Object, test_parameters=[
|
||||
[Resource.new(), Resource.new()],
|
||||
[Resource.new(), null]
|
||||
] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_resolve_parameters_static(a: int, b: int, test_parameters=[
|
||||
[1, 10],
|
||||
[2, 20]
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_resolve_parameters_at_runtime(a: int, b: int, test_parameters=[
|
||||
[1, _test_param1],
|
||||
[2, _test_param2],
|
||||
[3, 30]
|
||||
]) -> void:
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_parameterized_with_comments(a: int, b :int, c :String, expected :int, test_parameters = [
|
||||
# before data set
|
||||
[1, 2, '3', 6], # after data set
|
||||
# between data sets
|
||||
[3, 4, '5', 11],
|
||||
[6, 7, 'string #ABCD', 21], # dataset with [comment] singn
|
||||
[6, 7, "string #ABCD", 21] # dataset with "comment" singn
|
||||
#eof
|
||||
]):
|
||||
pass
|
||||
|
||||
|
||||
func build_param(value: float) -> Vector3:
|
||||
return Vector3(value, value, value)
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_d(a: Vector3, b: Vector3, test_parameters=[
|
||||
[build_param(1), build_param(3)],
|
||||
[Vector3.BACK, Vector3.UP]
|
||||
] ) -> void:
|
||||
pass
|
||||
|
||||
|
||||
class TestObj extends RefCounted:
|
||||
var _value: String
|
||||
|
||||
func _init(value: String):
|
||||
_value = value
|
||||
|
||||
func _to_string() -> String:
|
||||
return _value
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_example_e(a: Object, b: Object, expected: String, test_parameters:=[
|
||||
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]):
|
||||
pass
|
||||
|
||||
|
||||
# verify the used 'test_parameters' is completly resolved
|
||||
func test_load_parameter_sets() -> void:
|
||||
var tc := get_test_case("test_example_a")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[1, 2], [3, 4]])
|
||||
|
||||
tc = get_test_case("test_example_b")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[Vector2.ZERO, Vector2.ONE], [Vector2(1.1, 3.2), Vector2.DOWN]])
|
||||
|
||||
tc = get_test_case("test_example_c")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[Resource.new(), Resource.new()], [Resource.new(), null]])
|
||||
|
||||
tc = get_test_case("test_example_d")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[Vector3(1, 1, 1), Vector3(3, 3, 3)], [Vector3.BACK, Vector3.UP]])
|
||||
|
||||
tc = get_test_case("test_example_e")
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([[TestObj.new("abc"), TestObj.new("def"), "abcdef"]])
|
||||
|
||||
|
||||
func test_load_parameter_sets_at_runtime() -> void:
|
||||
var tc := get_test_case("test_resolve_parameters_at_runtime")
|
||||
assert_that(tc).is_not_null()
|
||||
# check the parameters resolved at runtime
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([
|
||||
# the value `_test_param1` is changed from 10 to 11 on `before` stage
|
||||
[1, 11],
|
||||
# the value `_test_param2` is changed from 20 to 2 on `test_before` stage
|
||||
[2, 22],
|
||||
# the value is static initial `30`
|
||||
[3, 30]])
|
||||
|
||||
|
||||
func test_load_parameter_with_comments() -> void:
|
||||
var tc := get_test_case("test_parameterized_with_comments")
|
||||
assert_that(tc).is_not_null()
|
||||
# check the parameters resolved at runtime
|
||||
assert_array(tc.parameter_set_resolver().load_parameter_sets(tc)) \
|
||||
.is_equal([
|
||||
[1, 2, '3', 6],
|
||||
[3, 4, '5', 11],
|
||||
[6, 7, 'string #ABCD', 21],
|
||||
[6, 7, "string #ABCD", 21]])
|
||||
|
||||
|
||||
func test_build_test_case_names_on_static_parameter_set() -> void:
|
||||
var test_case := get_test_case("test_resolve_parameters_static")
|
||||
var resolver := test_case.parameter_set_resolver()
|
||||
|
||||
assert_array(resolver.build_test_case_names(test_case))\
|
||||
.contains_exactly([
|
||||
"test_resolve_parameters_static:0 [1, 10]",
|
||||
"test_resolve_parameters_static:1 [2, 20]"])
|
||||
assert_that(resolver.is_parameter_sets_static()).is_true()
|
||||
assert_that(resolver.is_parameter_set_static(0)).is_true()
|
||||
assert_that(resolver.is_parameter_set_static(1)).is_true()
|
||||
|
||||
|
||||
func test_build_test_case_names_on_runtime_parameter_set() -> void:
|
||||
var test_case := get_test_case("test_resolve_parameters_at_runtime")
|
||||
var resolver := test_case.parameter_set_resolver()
|
||||
|
||||
assert_array(resolver.build_test_case_names(test_case))\
|
||||
.contains_exactly([
|
||||
"test_resolve_parameters_at_runtime:0 [1, _test_param1]",
|
||||
"test_resolve_parameters_at_runtime:1 [2, _test_param2]",
|
||||
"test_resolve_parameters_at_runtime:2 [3, 30]"])
|
||||
assert_that(resolver.is_parameter_sets_static()).is_false()
|
||||
assert_that(resolver.is_parameter_set_static(0)).is_false()
|
||||
assert_that(resolver.is_parameter_set_static(1)).is_false()
|
||||
assert_that(resolver.is_parameter_set_static(2)).is_false()
|
||||
|
||||
|
||||
func test_validate_test_parameter_set():
|
||||
var test_suite :GdUnitTestSuite = auto_free(GdUnitTestResourceLoader.load_test_suite("res://addons/gdUnit4/test/core/resources/testsuites/TestSuiteInvalidParameterizedTests.resource"))
|
||||
|
||||
assert_is_not_skipped(test_suite, "test_no_parameters")
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_success")
|
||||
assert_is_not_skipped(test_suite, "test_parameterized_failed")
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args")\
|
||||
.contains("The parameter set at index [0] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [3] input parameters, but the set contains [4]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_many_args")\
|
||||
.contains("The parameter set at index [0] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [5] input parameters, but the set contains [4]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_to_less_args_at_index_1")\
|
||||
.contains("The parameter set at index [1] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [3] input parameters, but the set contains [4]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_invalid_struct")\
|
||||
.contains("The parameter set at index [1] does not match the expected input parameters!")\
|
||||
.contains("The test case requires [3] input parameters, but the set contains [1]")
|
||||
assert_is_skipped(test_suite, "test_parameterized_invalid_args")\
|
||||
.contains("The parameter set at index [1] does not match the expected input parameters!")\
|
||||
.contains("The value '4' does not match the required input parameter <b:int>.")
|
||||
|
||||
|
||||
func assert_is_not_skipped(test_suite :GdUnitTestSuite, test_case :String) -> void:
|
||||
# set actual execution context for this test suite
|
||||
test_suite.__execution_context = GdUnitExecutionContext.new(test_suite.get_name())
|
||||
var test :_TestCase = test_suite.find_child(test_case, true, false)
|
||||
if test.is_parameterized():
|
||||
# to load parameter set and force validate
|
||||
var resolver := test.parameter_set_resolver()
|
||||
resolver.build_test_case_names(test)
|
||||
resolver.load_parameter_sets(test, true)
|
||||
assert_that(test.is_skipped()).is_false()
|
||||
|
||||
|
||||
func assert_is_skipped(test_suite :GdUnitTestSuite, test_case :String) -> GdUnitStringAssert:
|
||||
# set actual execution context for this test suite
|
||||
test_suite.__execution_context = GdUnitExecutionContext.new(test_suite.get_name())
|
||||
var test :_TestCase = test_suite.find_child(test_case, true, false)
|
||||
if test.is_parameterized():
|
||||
# to load parameter set and force validate
|
||||
var resolver := test.parameter_set_resolver()
|
||||
resolver.build_test_case_names(test)
|
||||
resolver.load_parameter_sets(test, true)
|
||||
assert_that(test.is_skipped()).is_true()
|
||||
return assert_str(test.skip_info())
|
||||
|
||||
func get_test_case(name: String) -> _TestCase:
|
||||
return find_child(name, true, false)
|
||||
17
addons/gdUnit4/test/core/resources/Area4D.txt
Normal file
17
addons/gdUnit4/test/core/resources/Area4D.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
class Area4D extends Resource:
|
||||
|
||||
const SOUND := 1
|
||||
const ATMOSPHERE := 2
|
||||
var _meta := Dictionary()
|
||||
|
||||
func _init(_x :int, atmospere :AtmosphereData = null):
|
||||
_meta[ATMOSPHERE] = atmospere
|
||||
|
||||
func get_sound() -> SoundData:
|
||||
# sounds are optional
|
||||
if _meta.has(SOUND):
|
||||
return _meta[SOUND] as SoundData
|
||||
return null
|
||||
|
||||
func get_atmoshere() -> AtmosphereData:
|
||||
return _meta[ATMOSPHERE] as AtmosphereData
|
||||
22
addons/gdUnit4/test/core/resources/AtmosphereData.txt
Normal file
22
addons/gdUnit4/test/core/resources/AtmosphereData.txt
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
class AtmosphereData:
|
||||
enum {
|
||||
WATER,
|
||||
AIR,
|
||||
SMOKY,
|
||||
}
|
||||
var _toxigen :float
|
||||
var _type :int
|
||||
|
||||
func _init(type := AIR, toxigen := 0.0):
|
||||
_type = type
|
||||
_toxigen = toxigen
|
||||
# some comment, and an row staring with an space to simmulate invalid formatting
|
||||
|
||||
|
||||
# seter func with default values
|
||||
func set_data(type := AIR, toxigen := 0.0) :
|
||||
_type = type
|
||||
_toxigen = toxigen
|
||||
|
||||
static func to_atmosphere(_value :Dictionary) -> AtmosphereData:
|
||||
return null
|
||||
BIN
addons/gdUnit4/test/core/resources/GdUnitRunner_old_format.cfg
Normal file
BIN
addons/gdUnit4/test/core/resources/GdUnitRunner_old_format.cfg
Normal file
Binary file not shown.
5
addons/gdUnit4/test/core/resources/SoundData.txt
Normal file
5
addons/gdUnit4/test/core/resources/SoundData.txt
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
class SoundData:
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _sample :String
|
||||
@warning_ignore("unused_private_class_variable")
|
||||
var _randomnes :float
|
||||
|
|
@ -0,0 +1 @@
|
|||
xxx
|
||||
|
|
@ -0,0 +1 @@
|
|||
xxx
|
||||
|
|
@ -0,0 +1 @@
|
|||
xxx
|
||||
|
|
@ -0,0 +1 @@
|
|||
xxx
|
||||
|
|
@ -0,0 +1 @@
|
|||
xxx
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class_name PascalCaseWithClassName
|
||||
extends Resource
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
extends RefCounted
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
class_name SnakeCaseWithClassName
|
||||
extends Resource
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
extends RefCounted
|
||||
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
class_name BaseTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
func before():
|
||||
pass
|
||||
|
||||
|
||||
func after():
|
||||
pass
|
||||
|
||||
|
||||
func before_test():
|
||||
pass
|
||||
|
||||
|
||||
func after_test():
|
||||
pass
|
||||
|
||||
|
||||
func test_foo1() -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
class_name ExtendedTest
|
||||
extends BaseTest
|
||||
|
||||
|
||||
func before_test():
|
||||
pass
|
||||
|
||||
|
||||
func after_test():
|
||||
pass
|
||||
|
||||
|
||||
func test_foo2() -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
extends ExtendedTest
|
||||
|
||||
func test_foo3() -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
func test_foo1() -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
extends "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/BaseTest.gd"
|
||||
|
||||
func test_foo2() -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
extends "res://addons/gdUnit4/test/core/resources/scan_testsuite_inheritance/by_class_path/ExtendedTest.gd"
|
||||
|
||||
func test_foo3() -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
extends PanelContainer
|
||||
|
||||
|
||||
# Godot calls this method to get data that can be dragged and dropped onto controls that expect drop data.
|
||||
# Returns null if there is no data to drag.
|
||||
# Controls that want to receive drop data should implement can_drop_data() and drop_data().
|
||||
# position is local to this control. Drag may be forced with force_drag().
|
||||
func _get_drag_data(_position: Vector2) -> Variant:
|
||||
var x :TextureRect = $TextureRect
|
||||
var data: = {texture = x.texture}
|
||||
var drag_texture := x.duplicate()
|
||||
drag_texture.size = x.size
|
||||
drag_texture.position = x.global_position * -0.2
|
||||
|
||||
# set drag preview
|
||||
var control := Panel.new()
|
||||
control.add_child(drag_texture)
|
||||
# center texture relative to mouse pos
|
||||
set_drag_preview(control)
|
||||
return data
|
||||
|
||||
|
||||
# Godot calls this method to test if data from a control's get_drag_data() can be dropped at position. position is local to this control.
|
||||
func _can_drop_data(_position: Vector2, data :Variant) -> bool:
|
||||
return typeof(data) == TYPE_DICTIONARY and data.has("texture")
|
||||
|
||||
|
||||
# Godot calls this method to pass you the data from a control's get_drag_data() result.
|
||||
# Godot first calls can_drop_data() to test if data is allowed to drop at position where position is local to this control.
|
||||
func _drop_data(_position: Vector2, data :Variant) -> void:
|
||||
var drag_texture :Texture = data["texture"]
|
||||
if drag_texture != null:
|
||||
$TextureRect.texture = drag_texture
|
||||
|
||||
|
||||
# Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See accept_event().
|
||||
func _gui_input(_event):
|
||||
#prints("Panel _gui_input", _event.as_text())
|
||||
#if _event is InputEventMouseButton:
|
||||
# prints("Panel _gui_input", _event.as_text())
|
||||
pass
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://ca2rr3dan4vvw"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropControl.gd" id="1"]
|
||||
|
||||
[node name="Panel" type="PanelContainer"]
|
||||
offset_left = 245.0
|
||||
offset_top = 232.0
|
||||
offset_right = 350.0
|
||||
offset_bottom = 337.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="TextureRect" type="TextureRect" parent="."]
|
||||
layout_mode = 2
|
||||
expand_mode = 1
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
extends Control
|
||||
|
||||
@onready var texture = preload("res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/icon.png")
|
||||
|
||||
func _ready():
|
||||
# set initial drag texture
|
||||
$left/TextureRect.texture = texture
|
||||
|
||||
|
||||
# Virtual method to be implemented by the user. Use this method to process and accept inputs on UI elements. See accept_event().
|
||||
func _gui_input(_event):
|
||||
#prints("Game _gui_input", _event.as_text())
|
||||
pass
|
||||
|
||||
|
||||
func _on_Button_button_down():
|
||||
# print("BUTTON DOWN")
|
||||
pass
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://skueh3d5qn46"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropTestScene.gd" id="1"]
|
||||
[ext_resource type="PackedScene" uid="uid://ca2rr3dan4vvw" path="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/DragAndDropControl.tscn" id="2_u5ccv"]
|
||||
|
||||
[node name="DragAndDropScene" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
size_flags_horizontal = 3
|
||||
size_flags_vertical = 3
|
||||
script = ExtResource("1")
|
||||
|
||||
[node name="left" parent="." instance=ExtResource("2_u5ccv")]
|
||||
layout_mode = 0
|
||||
offset_left = 250.0
|
||||
offset_top = 240.0
|
||||
offset_right = 355.0
|
||||
offset_bottom = 345.0
|
||||
auto_translate = false
|
||||
localize_numeral_system = false
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[node name="right" parent="." instance=ExtResource("2_u5ccv")]
|
||||
layout_mode = 0
|
||||
offset_left = 370.0
|
||||
offset_top = 240.0
|
||||
offset_right = 475.0
|
||||
offset_bottom = 345.0
|
||||
|
||||
[node name="Button" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 243.0
|
||||
offset_top = 40.0
|
||||
offset_right = 479.0
|
||||
offset_bottom = 200.0
|
||||
text = "BUTTON"
|
||||
metadata/_edit_use_anchors_ = true
|
||||
|
||||
[connection signal="button_down" from="Button" to="." method="_on_Button_button_down"]
|
||||
BIN
addons/gdUnit4/test/core/resources/scenes/drag_and_drop/icon.png
Normal file
BIN
addons/gdUnit4/test/core/resources/scenes/drag_and_drop/icon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://di6ovw8bnk7wg"
|
||||
path="res://.godot/imported/icon.png-50a1939c45a5f06328a9e414b58963b1.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://addons/gdUnit4/test/core/resources/scenes/drag_and_drop/icon.png"
|
||||
dest_files=["res://.godot/imported/icon.png-50a1939c45a5f06328a9e414b58963b1.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
|
|
@ -0,0 +1,15 @@
|
|||
extends Control
|
||||
|
||||
var _player_jump_action_released := false
|
||||
|
||||
# enable for manual testing
|
||||
func __init():
|
||||
var event := InputEventKey.new()
|
||||
event.keycode = KEY_SPACE
|
||||
InputMap.add_action("player_jump")
|
||||
InputMap.action_add_event("player_jump", event)
|
||||
|
||||
|
||||
func _input(event):
|
||||
_player_jump_action_released = Input.is_action_just_released("player_jump", true)
|
||||
#prints("_input2:player_jump", Input.is_action_just_released("player_jump"), Input.is_action_just_released("player_jump", true))
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
[gd_scene load_steps=2 format=3 uid="uid://cvklb72mxqh1h"]
|
||||
|
||||
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/input_actions/InputEventTestScene.gd" id="1_wslmn"]
|
||||
|
||||
[node name="InputEventTestScene" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_wslmn")
|
||||
15
addons/gdUnit4/test/core/resources/scenes/simple_scene.gd
Normal file
15
addons/gdUnit4/test/core/resources/scenes/simple_scene.gd
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
extends Node2D
|
||||
|
||||
class Player extends Node:
|
||||
var position :Vector3 = Vector3.ZERO
|
||||
|
||||
|
||||
func _init():
|
||||
set_name("Player")
|
||||
|
||||
func is_on_floor() -> bool:
|
||||
return true
|
||||
|
||||
|
||||
func _ready():
|
||||
add_child(Player.new(), true)
|
||||
11
addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn
Normal file
11
addons/gdUnit4/test/core/resources/scenes/simple_scene.tscn
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://cn8ucy2rheu0f"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://t80a6k3vyrrd" path="res://icon.png" id="1"]
|
||||
[ext_resource type="Script" path="res://addons/gdUnit4/test/core/resources/scenes/simple_scene.gd" id="2"]
|
||||
|
||||
[node name="Node2D" type="Node2D"]
|
||||
script = ExtResource("2")
|
||||
|
||||
[node name="Sprite2D" type="Sprite2D" parent="."]
|
||||
position = Vector2(504, 252)
|
||||
texture = ExtResource("1")
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
class_name ScriptWithClassName
|
||||
extends Resource
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
extends RefCounted
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready():
|
||||
pass # Replace with function body.
|
||||
17
addons/gdUnit4/test/core/resources/sources/test_person.gd
Normal file
17
addons/gdUnit4/test/core/resources/sources/test_person.gd
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
extends RefCounted
|
||||
|
||||
var _first_name :String
|
||||
var _last_name :String
|
||||
|
||||
func _init(first_name_ :String,last_name_ :String):
|
||||
_first_name = first_name_
|
||||
_last_name = last_name_
|
||||
|
||||
func first_name() -> String:
|
||||
return _first_name
|
||||
|
||||
func last_name() -> String:
|
||||
return _last_name
|
||||
|
||||
func fully_name() -> String:
|
||||
return _first_name + " " + _last_name
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
extends Node
|
||||
|
||||
|
||||
func test_no_args():
|
||||
pass
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_timeout(timeout=2000):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_fuzzer(fuzzer := Fuzzers.rangei(-10, 22)):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_fuzzer_iterations(fuzzer := Fuzzers.rangei(-10, 22), fuzzer_iterations = 10):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_with_multible_fuzzers(fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42), fuzzer_iterations = 10):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_multiline_arguments_a(fuzzer_a := Fuzzers.rangei(-10, 22), fuzzer_b := Fuzzers.rangei(23, 42),
|
||||
fuzzer_iterations = 42):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_multiline_arguments_b(
|
||||
fuzzer_a := Fuzzers.rangei(-10, 22),
|
||||
fuzzer_b := Fuzzers.rangei(23, 42),
|
||||
fuzzer_iterations = 23
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore("unused_parameter")
|
||||
func test_multiline_arguments_c(
|
||||
timeout=2000,
|
||||
fuzzer_a := Fuzzers.rangei(-10, 22),
|
||||
fuzzer_b := Fuzzers.rangei(23, 42),
|
||||
fuzzer_iterations = 33
|
||||
) -> void:
|
||||
pass
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
# this test suite simulates long running test cases
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
|
||||
var _stack : Array
|
||||
|
||||
func before():
|
||||
# init the stack
|
||||
_stack = []
|
||||
|
||||
func before_test():
|
||||
# clean the stack before every test run
|
||||
_stack.clear()
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_multi_yielding_with_fuzzer(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 10):
|
||||
# verify the used stack is cleaned by 'before_test'
|
||||
assert_array(_stack).is_empty()
|
||||
_stack.push_back(1)
|
||||
|
||||
prints("test iteration %d" % fuzzer.iteration_index())
|
||||
prints("4")
|
||||
await get_tree().process_frame
|
||||
prints("3")
|
||||
await get_tree().process_frame
|
||||
prints("2")
|
||||
await get_tree().process_frame
|
||||
prints("1")
|
||||
await get_tree().process_frame
|
||||
prints("Go")
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_multi_yielding_with_fuzzer_fail_after_3_iterations(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 10):
|
||||
prints("test iteration %d" % fuzzer.iteration_index())
|
||||
# should never be greater than 3 because we interuppted after three iterations
|
||||
assert_int(fuzzer.iteration_index()).is_less_equal(3)
|
||||
prints("4")
|
||||
await get_tree().process_frame
|
||||
prints("3")
|
||||
await get_tree().process_frame
|
||||
prints("2")
|
||||
await get_tree().process_frame
|
||||
prints("1")
|
||||
await get_tree().process_frame
|
||||
prints("Go")
|
||||
if fuzzer.iteration_index() >= 3:
|
||||
assert_bool(true).is_false()
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
namespace GdUnit4.Tests.Resources
|
||||
{
|
||||
using static Assertions;
|
||||
|
||||
// will be ignored because of missing `[TestSuite]` anotation
|
||||
public partial class NotATestSuite
|
||||
{
|
||||
[TestCase]
|
||||
public void TestFoo()
|
||||
{
|
||||
AssertBool(true).IsEqual(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_case1(timeout = 1000, do_skip=1==1, skip_reason="do not run this"):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_case2(skip_reason="ignored"):
|
||||
pass
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# this test suite ends with success, no failures or errors
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").is_equal("suite after")
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").is_equal("test before")
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
# this test suite ends with error on testcase1 by a timeout
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").is_equal("suite after")
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").is_equal("test before")
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
# configure test with timeout of 2s
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_case1(timeout=2000):
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
# wait 3s to let the test fail by timeout
|
||||
await await_millis(3000)
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
# this test suite fails if (https://github.com/MikeSchulze/gdUnit4/issues/106) not fixed on iterating over testcases
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
add_child(auto_free(Node.new()))
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
# this test suite fails on multiple stages and detects orphans
|
||||
extends GdUnitTestSuite
|
||||
|
||||
var _orphans := Array()
|
||||
|
||||
func before():
|
||||
# create a node where never freed (orphan)
|
||||
_orphans.append(Node.new())
|
||||
|
||||
func before_test():
|
||||
# create two node where never freed (orphan)
|
||||
_orphans.append(Node.new())
|
||||
_orphans.append(Node.new())
|
||||
|
||||
|
||||
# ends with warning and 3 orphan detected
|
||||
func test_case1():
|
||||
# create three node where never freed (orphan)
|
||||
_orphans.append(Node.new())
|
||||
_orphans.append(Node.new())
|
||||
_orphans.append(Node.new())
|
||||
|
||||
# ends with error and 4 orphan detected
|
||||
func test_case2():
|
||||
# create four node where never freed (orphan)
|
||||
_orphans.append(Node.new())
|
||||
_orphans.append(Node.new())
|
||||
_orphans.append(Node.new())
|
||||
_orphans.append(Node.new())
|
||||
assert_str("test_case2").override_failure_message("faild on test_case2()").is_empty()
|
||||
|
||||
# we manually freeing the orphans from the simulated testsuite to prevent memory leaks here
|
||||
func _notification(what):
|
||||
if what == NOTIFICATION_PREDELETE:
|
||||
for orphan in _orphans:
|
||||
orphan.free()
|
||||
_orphans.clear()
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
# this test suite fails on multiple stages
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").override_failure_message("failed on after()").is_empty()
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").override_failure_message("failed on before_test()").is_empty()
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").override_failure_message("failed 1 on test_case1()").is_empty()
|
||||
assert_str("test_case1").override_failure_message("failed 2 on test_case1()").is_empty()
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# this test suite fails on stage after()
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").override_failure_message("failed on after()").is_empty()
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").is_equal("test before")
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# this test suite fails on stage after_test()
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").is_equal("suite after")
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").is_equal("test before")
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").override_failure_message("failed on after_test()").is_empty()
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# this test suite fails on stage before()
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").override_failure_message("failed on before()").is_empty()
|
||||
|
||||
func after():
|
||||
assert_str("suite after").is_equal("suite after")
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").is_equal("test before")
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# this test suite fails on stage before_test()
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").is_equal("suite after")
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").override_failure_message("failed on before_test()").is_empty()
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").is_equal("test_case1")
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
# this test suite fails on a single test case
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func before():
|
||||
assert_str("suite before").is_equal("suite before")
|
||||
|
||||
func after():
|
||||
assert_str("suite after").is_equal("suite after")
|
||||
|
||||
func before_test():
|
||||
assert_str("test before").is_equal("test before")
|
||||
|
||||
func after_test():
|
||||
assert_str("test after").is_equal("test after")
|
||||
|
||||
func test_case1():
|
||||
assert_str("test_case1").override_failure_message("failed on test_case1()").is_empty()
|
||||
|
||||
func test_case2():
|
||||
assert_str("test_case2").is_equal("test_case2")
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
# this test suite simulates long running test cases
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
|
||||
|
||||
class TestCaseStatistics:
|
||||
var _testcase_before_called := 0
|
||||
var _testcase_after_called := 0
|
||||
var _test_called := 0
|
||||
var _expected_calls :int
|
||||
|
||||
func _init(expected_calls :int):
|
||||
_expected_calls = expected_calls
|
||||
|
||||
func count_test_before_test():
|
||||
_testcase_before_called +=1
|
||||
|
||||
func count_test_after_test():
|
||||
_testcase_after_called +=1
|
||||
|
||||
func count_test():
|
||||
_test_called += 1
|
||||
|
||||
|
||||
var _metrics = {
|
||||
"test_execute_3times" : TestCaseStatistics.new(3),
|
||||
"test_execute_5times" : TestCaseStatistics.new(5)
|
||||
}
|
||||
|
||||
var _stack : Array
|
||||
var _before_called := 0
|
||||
var _after_called := 0
|
||||
|
||||
|
||||
func before():
|
||||
_before_called += 1
|
||||
# init the stack
|
||||
_stack = []
|
||||
|
||||
|
||||
func after():
|
||||
_after_called += 1
|
||||
assert_that(_before_called)\
|
||||
.override_failure_message("Expecting 'before' is called only one times")\
|
||||
.is_equal(1)
|
||||
assert_that(_after_called)\
|
||||
.override_failure_message("Expecting 'after' is called only one times")\
|
||||
.is_equal(1)
|
||||
|
||||
for test_case in _metrics.keys():
|
||||
var statistics := _metrics[test_case] as TestCaseStatistics
|
||||
assert_int(statistics._testcase_before_called)\
|
||||
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._testcase_before_called, test_case])\
|
||||
.is_equal(statistics._expected_calls)
|
||||
assert_int(statistics._test_called)\
|
||||
.override_failure_message("Expect test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._test_called, test_case])\
|
||||
.is_equal(statistics._expected_calls)
|
||||
assert_int(statistics._testcase_after_called)\
|
||||
.override_failure_message("Expect after_test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._testcase_after_called, test_case])\
|
||||
.is_equal(statistics._expected_calls)
|
||||
|
||||
|
||||
func before_test():
|
||||
_metrics[__active_test_case].count_test_before_test()
|
||||
# clean the stack before every test run
|
||||
_stack.clear()
|
||||
|
||||
|
||||
func after_test():
|
||||
_metrics[__active_test_case].count_test_after_test()
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_execute_3times(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 3):
|
||||
_metrics[__active_test_case].count_test()
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_execute_5times(fuzzer := Fuzzers.rangei(0, 1000), fuzzer_iterations = 5):
|
||||
_metrics[__active_test_case].count_test()
|
||||
pass
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
class_name TestSuiteInvalidParameterizedTests
|
||||
extends GdUnitTestSuite
|
||||
|
||||
func test_no_parameters():
|
||||
assert_that(true).is_equal(true)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_success(a: int, b :int, c :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 12],
|
||||
[6, 7, 8, 21] ]):
|
||||
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_failed(a: int, b :int, c :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):
|
||||
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_to_less_args(a: int, b :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):
|
||||
pass
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_to_many_args(a: int, b :int, c :int, d :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 21] ]):
|
||||
pass
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_to_less_args_at_index_1(a: int, b :int, expected :int, test_parameters := [
|
||||
[1, 2, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 21] ]):
|
||||
pass
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_invalid_struct(a: int, b :int, expected :int, test_parameters := [
|
||||
[1, 2, 6],
|
||||
["foo"],
|
||||
[6, 7, 21] ]):
|
||||
pass
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_invalid_args(a: int, b :int, expected :int, test_parameters := [
|
||||
[1, 2, 6],
|
||||
[3, "4", 11],
|
||||
[6, 7, 21] ]):
|
||||
pass
|
||||
|
|
@ -0,0 +1,85 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
|
||||
class TestCaseStatistics:
|
||||
var _testcase_before_called := 0
|
||||
var _testcase_after_called := 0
|
||||
var _test_called := 0
|
||||
var _expected_calls :int
|
||||
|
||||
func _init(expected_calls :int):
|
||||
_expected_calls = expected_calls
|
||||
|
||||
func count_test_before_test():
|
||||
_testcase_before_called +=1
|
||||
|
||||
func count_test_after_test():
|
||||
_testcase_after_called +=1
|
||||
|
||||
func count_test():
|
||||
_test_called += 1
|
||||
|
||||
|
||||
var _metrics = {
|
||||
"test_parameterized_2times" : TestCaseStatistics.new(2),
|
||||
"test_parameterized_5times" : TestCaseStatistics.new(5)
|
||||
}
|
||||
|
||||
var _before_called := 0
|
||||
var _after_called := 0
|
||||
|
||||
|
||||
func before():
|
||||
_before_called += 1
|
||||
|
||||
|
||||
func after():
|
||||
_after_called += 1
|
||||
assert_that(_before_called)\
|
||||
.override_failure_message("Expecting 'before' is called only one times")\
|
||||
.is_equal(1)
|
||||
assert_that(_after_called)\
|
||||
.override_failure_message("Expecting 'after' is called only one times")\
|
||||
.is_equal(1)
|
||||
|
||||
for test_case in _metrics.keys():
|
||||
var statistics := _metrics[test_case] as TestCaseStatistics
|
||||
assert_int(statistics._testcase_before_called)\
|
||||
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._testcase_before_called, test_case])\
|
||||
.is_equal(statistics._expected_calls)
|
||||
assert_int(statistics._test_called)\
|
||||
.override_failure_message("Expect test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._test_called, test_case])\
|
||||
.is_equal(statistics._expected_calls)
|
||||
assert_int(statistics._testcase_after_called)\
|
||||
.override_failure_message("Expect after_test called %s times but is %s for test case %s" % [statistics._expected_calls, statistics._testcase_after_called, test_case])\
|
||||
.is_equal(statistics._expected_calls)
|
||||
|
||||
|
||||
func before_test():
|
||||
_metrics[__active_test_case].count_test_before_test()
|
||||
|
||||
|
||||
func after_test():
|
||||
_metrics[__active_test_case].count_test_after_test()
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_2times(a: int, expected :bool, test_parameters := [
|
||||
[0, false],
|
||||
[1, true]]):
|
||||
|
||||
_metrics[__active_test_case].count_test()
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_5times(a: int, expected :bool, test_parameters := [
|
||||
[0, false],
|
||||
[1, true],
|
||||
[0, false],
|
||||
[1, true],
|
||||
[1, true]]):
|
||||
|
||||
_metrics[__active_test_case].count_test()
|
||||
|
|
@ -0,0 +1,148 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
|
||||
class TestCaseStatistics:
|
||||
var _testcase_before_called := 0
|
||||
var _testcase_after_called := 0
|
||||
var _expected_testcase_before :int
|
||||
var _expected_testcase_after :int
|
||||
|
||||
func _init(testcase_before_calls := 0, testcase_after_calls := 0):
|
||||
_expected_testcase_before = testcase_before_calls
|
||||
_expected_testcase_after = testcase_after_calls
|
||||
|
||||
func count_test_before_test():
|
||||
_testcase_before_called +=1
|
||||
|
||||
func count_test_after_test():
|
||||
_testcase_after_called +=1
|
||||
|
||||
|
||||
var _metrics = {
|
||||
"test_parameterized_bool_value" : TestCaseStatistics.new(2, 2),
|
||||
"test_parameterized_int_values" : TestCaseStatistics.new(3, 3)
|
||||
}
|
||||
|
||||
var _before_called := 0
|
||||
var _after_called := 0
|
||||
|
||||
|
||||
func before():
|
||||
_before_called += 1
|
||||
|
||||
|
||||
func after():
|
||||
_after_called += 1
|
||||
assert_that(_before_called)\
|
||||
.override_failure_message("Expecting 'before' is called only one times")\
|
||||
.is_equal(1)
|
||||
assert_that(_after_called)\
|
||||
.override_failure_message("Expecting 'after' is called only one times")\
|
||||
.is_equal(1)
|
||||
|
||||
for test_case in _metrics.keys():
|
||||
var statistics := _metrics[test_case] as TestCaseStatistics
|
||||
assert_int(statistics._testcase_before_called)\
|
||||
.override_failure_message("Expect before_test called %s times but is %s for test case %s" % [statistics._expected_testcase_before, statistics._testcase_before_called, test_case])\
|
||||
.is_equal(statistics._expected_testcase_before)
|
||||
assert_int(statistics._testcase_after_called)\
|
||||
.override_failure_message("Expect after_test called %s times but is %s for test case %s" % [statistics._expected_testcase_after, statistics._testcase_after_called, test_case])\
|
||||
.is_equal(statistics._expected_testcase_after)
|
||||
|
||||
|
||||
func before_test():
|
||||
if _metrics.has(__active_test_case):
|
||||
_metrics[__active_test_case].count_test_before_test()
|
||||
|
||||
|
||||
func after_test():
|
||||
if _metrics.has(__active_test_case):
|
||||
_metrics[__active_test_case].count_test_after_test()
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_bool_value(a: int, expected :bool, test_parameters := [
|
||||
[0, false],
|
||||
[1, true]]):
|
||||
|
||||
assert_that(bool(a)).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_int_values(a: int, b :int, c :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 12],
|
||||
[6, 7, 8, 21] ]):
|
||||
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_int_values_fail(a: int, b :int, c :int, expected :int, test_parameters := [
|
||||
[1, 2, 3, 6],
|
||||
[3, 4, 5, 11],
|
||||
[6, 7, 8, 22] ]):
|
||||
|
||||
assert_that(a+b+c).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_float_values(a: float, b :float, expected :float, test_parameters := [
|
||||
[2.2, 2.2, 4.4],
|
||||
[2.2, 2.3, 4.5],
|
||||
[3.3, 2.2, 5.5] ]):
|
||||
|
||||
assert_float(a+b).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_string_values(a: String, b :String, expected :String, test_parameters := [
|
||||
["2.2", "2.2", "2.22.2"],
|
||||
["foo", "bar", "foobar"],
|
||||
["a", "b", "ab"] ]):
|
||||
|
||||
assert_that(a+b).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_Vector2_values(a: Vector2, b :Vector2, expected :Vector2, test_parameters := [
|
||||
[Vector2.ONE, Vector2.ONE, Vector2(2, 2)],
|
||||
[Vector2.LEFT, Vector2.RIGHT, Vector2.ZERO],
|
||||
[Vector2.ZERO, Vector2.LEFT, Vector2.LEFT] ]):
|
||||
|
||||
assert_that(a+b).is_equal(expected)
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_Vector3_values(a: Vector3, b :Vector3, expected :Vector3, test_parameters := [
|
||||
[Vector3.ONE, Vector3.ONE, Vector3(2, 2, 2)],
|
||||
[Vector3.LEFT, Vector3.RIGHT, Vector3.ZERO],
|
||||
[Vector3.ZERO, Vector3.LEFT, Vector3.LEFT] ]):
|
||||
|
||||
assert_that(a+b).is_equal(expected)
|
||||
|
||||
class TestObj extends Resource:
|
||||
var _value :String
|
||||
|
||||
func _init(value :String):
|
||||
_value = value
|
||||
|
||||
func _to_string() -> String:
|
||||
return _value
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_parameterized_obj_values(a: Object, b :Object, expected :String, test_parameters := [
|
||||
[TestObj.new("abc"), TestObj.new("def"), "abcdef"]]):
|
||||
|
||||
assert_that(a.to_string()+b.to_string()).is_equal(expected)
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_dictionary_div_number_types(
|
||||
value : Dictionary,
|
||||
expected : Dictionary,
|
||||
test_parameters : Array = [
|
||||
[{ top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}, { top = 50, bottom = 50, left = 50, right = 50}],
|
||||
[{ top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}, { top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}],
|
||||
[{ top = 50, bottom = 50, left = 50, right = 50}, { top = 50.0, bottom = 50.0, left = 50.0, right = 50.0}],
|
||||
[{ top = 50, bottom = 50, left = 50, right = 50}, { top = 50, bottom = 50, left = 50, right = 50}],
|
||||
]
|
||||
) -> void:
|
||||
assert_that(value).is_equal(expected)
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
func is_skipped() -> bool:
|
||||
return true
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func before(do_skip=is_skipped(), skip_reason="do not run this"):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_case1(timeout = 1000, do_skip=1==1, skip_reason="do not run this"):
|
||||
pass
|
||||
|
||||
|
||||
@warning_ignore('unused_parameter')
|
||||
func test_case2(skip_reason="ignored"):
|
||||
pass
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
extends GdUnitTestSuite
|
||||
|
||||
|
||||
func before():
|
||||
pass
|
||||
|
||||
|
||||
func foo():
|
||||
pass
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
# GdUnit generated TestSuite
|
||||
#warning-ignore-all:unused_argument
|
||||
#warning-ignore-all:return_value_discarded
|
||||
class_name GdUnitTestSuiteTemplateTest
|
||||
extends GdUnitTestSuite
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/src/core/templates/test_suite/GdUnitTestSuiteTemplate.gd'
|
||||
|
||||
const CUSTOM_TEMPLATE = """
|
||||
# GdUnit generated TestSuite
|
||||
class_name ${suite_class_name}
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
func before() -> void:
|
||||
var ${source_var}_1 := ${source_class}.new()
|
||||
var ${source_var}_2 = load("${source_resource_path}")
|
||||
"""
|
||||
|
||||
|
||||
func after() -> void:
|
||||
GdUnitTestSuiteTemplate.reset_to_default(GdUnitTestSuiteTemplate.TEMPLATE_ID_GD)
|
||||
|
||||
|
||||
func test_default_template() -> void:
|
||||
assert_str(GdUnitTestSuiteTemplate.default_template(GdUnitTestSuiteTemplate.TEMPLATE_ID_GD)).is_equal(GdUnitTestSuiteTemplate.default_GD_template())
|
||||
|
||||
|
||||
func test_build_template_default() -> void:
|
||||
var template := GdUnitTestSuiteTemplate.build_template("res://addons/gdUnit4/test/core/resources/script_with_class_name.gd")
|
||||
var expected := """
|
||||
# GdUnit generated TestSuite
|
||||
class_name ScriptWithClassNameTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
# TestSuite generated from
|
||||
const __source = 'res://addons/gdUnit4/test/core/resources/script_with_class_name.gd'
|
||||
""".dedent().trim_prefix("\n")
|
||||
assert_str(template).is_equal(expected)
|
||||
|
||||
|
||||
# checked source with class_name definition
|
||||
func test_build_template_custom1() -> void:
|
||||
GdUnitTestSuiteTemplate.save_template(GdUnitTestSuiteTemplate.TEMPLATE_ID_GD, CUSTOM_TEMPLATE)
|
||||
var template := GdUnitTestSuiteTemplate.build_template("res://addons/gdUnit4/test/core/resources/script_with_class_name.gd")
|
||||
var expected := """
|
||||
# GdUnit generated TestSuite
|
||||
class_name ScriptWithClassNameTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
func before() -> void:
|
||||
var script_with_class_name_1 := ScriptWithClassName.new()
|
||||
var script_with_class_name_2 = load("res://addons/gdUnit4/test/core/resources/script_with_class_name.gd")
|
||||
""".dedent().trim_prefix("\n")
|
||||
assert_str(template).is_equal(expected)
|
||||
|
||||
|
||||
# checked source without class_name definition
|
||||
func test_build_template_custom2() -> void:
|
||||
GdUnitTestSuiteTemplate.save_template(GdUnitTestSuiteTemplate.TEMPLATE_ID_GD, CUSTOM_TEMPLATE)
|
||||
var template := GdUnitTestSuiteTemplate.build_template("res://addons/gdUnit4/test/core/resources/script_without_class_name.gd")
|
||||
var expected := """
|
||||
# GdUnit generated TestSuite
|
||||
class_name ScriptWithoutClassNameTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
func before() -> void:
|
||||
var script_without_class_name_1 := ScriptWithoutClassName.new()
|
||||
var script_without_class_name_2 = load("res://addons/gdUnit4/test/core/resources/script_without_class_name.gd")
|
||||
""".dedent().trim_prefix("\n")
|
||||
assert_str(template).is_equal(expected)
|
||||
|
||||
|
||||
# checked source with class_name definition pascal_case
|
||||
func test_build_template_custom3() -> void:
|
||||
GdUnitTestSuiteTemplate.save_template(GdUnitTestSuiteTemplate.TEMPLATE_ID_GD, CUSTOM_TEMPLATE)
|
||||
var template := GdUnitTestSuiteTemplate.build_template("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd")
|
||||
var expected := """
|
||||
# GdUnit generated TestSuite
|
||||
class_name PascalCaseWithClassNameTest
|
||||
extends GdUnitTestSuite
|
||||
@warning_ignore('unused_parameter')
|
||||
@warning_ignore('return_value_discarded')
|
||||
|
||||
func before() -> void:
|
||||
var pascal_case_with_class_name_1 := PascalCaseWithClassName.new()
|
||||
var pascal_case_with_class_name_2 = load("res://addons/gdUnit4/test/core/resources/naming_conventions/PascalCaseWithClassName.gd")
|
||||
""".dedent().trim_prefix("\n")
|
||||
assert_str(template).is_equal(expected)
|
||||
Loading…
Add table
Add a link
Reference in a new issue