From 418f6d3cf9e9d7599b69f33e5e1b8b12e405e036 Mon Sep 17 00:00:00 2001 From: thebigG Date: Sat, 18 Mar 2023 23:25:27 -0500 Subject: [PATCH] -Fixes godot-rust/gdext#138. -Add integration tests. --- godot-core/src/builtin/meta/signature.rs | 5 +-- itest/godot/InheritTests.gd | 41 ++++++++++++++++++++++++ itest/godot/TestRunner.gd | 1 + 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 itest/godot/InheritTests.gd diff --git a/godot-core/src/builtin/meta/signature.rs b/godot-core/src/builtin/meta/signature.rs index 415f8f1d4..6f9df66e1 100644 --- a/godot-core/src/builtin/meta/signature.rs +++ b/godot-core/src/builtin/meta/signature.rs @@ -162,8 +162,9 @@ macro_rules! impl_signature_for_tuple { unsafe { <$R as sys::GodotFuncMarshal>::try_write_sys(&ret_val, ret) } .unwrap_or_else(|e| return_error::<$R>(method_name, &e)); - // FIXME is inc_ref needed here? - // std::mem::forget(ret_val); + //Note: we want to prevent the destructor from being run, since we pass ownership to the caller. + // For details look at https://github.com/godot-rust/gdext/pull/165 + std::mem::forget(ret_val); } } }; diff --git a/itest/godot/InheritTests.gd b/itest/godot/InheritTests.gd new file mode 100644 index 000000000..9921a41bd --- /dev/null +++ b/itest/godot/InheritTests.gd @@ -0,0 +1,41 @@ +extends ArrayTest + +var _assertion_failed: bool = false + +## Asserts that `what` is `true`, but does not abort the test. Returns `what` so you can return +## early from the test function if the assertion failed. +func assert_that(what: bool, message: String = "") -> bool: + if what: + return true + + _assertion_failed = true + if message: + print("assertion failed: %s" % message) + else: + print("assertion failed") + return false + +func assert_eq(left, right, message: String = "") -> bool: + if left == right: + return true + + _assertion_failed = true + if message: + print("assertion failed: %s\n left: %s\n right: %s" % [message, left, right]) + else: + print("assertion failed: `(left == right)`\n left: %s\n right: %s" % [left, right]) + return false + + + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass + +func test_vector_array_return_from_user_func(): + var array: Array = return_typed_array(2) + assert_eq(array, [1,2]) + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass diff --git a/itest/godot/TestRunner.gd b/itest/godot/TestRunner.gd index 98376e561..45008f88e 100644 --- a/itest/godot/TestRunner.gd +++ b/itest/godot/TestRunner.gd @@ -10,6 +10,7 @@ func _ready(): var gdscript_suites: Array = [ preload("res://ManualFfiTests.gd").new(), preload("res://gen/GenFfiTests.gd").new(), + preload("res://InheritTests.gd").new() ] var gdscript_tests: Array = []