Skip to content

Commit a76cda6

Browse files
authored
Merge pull request #1153 from godot-rust/qol/follow-api-change
Adjust test to account for `Node::set_name()` change (`String` -> `StringName`)
2 parents aed6925 + 0d5b577 commit a76cda6

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

itest/rust/src/object_tests/dynamic_call_test.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,17 @@
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
77

8+
use crate::framework::{expect_panic, itest, runs_release};
9+
use crate::object_tests::object_test::ObjPayload;
810
use godot::builtin::{Variant, Vector3};
911
use godot::classes::{Node, Node3D, Object};
12+
use godot::init::GdextBuild;
1013
use godot::meta::error::CallError;
1114
use godot::meta::{FromGodot, ToGodot};
1215
use godot::obj::{InstanceId, NewAlloc};
1316
use std::error::Error;
1417
use std::sync::{Arc, Mutex};
1518

16-
use crate::framework::{expect_panic, itest, runs_release};
17-
use crate::object_tests::object_test::ObjPayload;
18-
1919
#[itest]
2020
fn dynamic_call_no_args() {
2121
let mut node = Node3D::new_alloc().upcast::<Object>();
@@ -288,14 +288,22 @@ fn dynamic_call_parameter_mismatch_engine() {
288288
.try_call("set_name", &[123.to_variant()])
289289
.expect_err("expected failed call");
290290

291+
// Node::set_name() changed to accept StringName, in https://github.com/godotengine/godot/pull/76560.
292+
// Needs to check the runtime version rather than API version, because reflection calls always latest method (no compatibility method).
293+
let target_type = if GdextBuild::before_api("4.5") {
294+
"STRING"
295+
} else {
296+
"STRING_NAME"
297+
};
298+
let expected_error = format!(
299+
"godot-rust function call failed: Object::call(&\"set_name\", [va] 123)\
300+
\n Reason: parameter #1 -- cannot convert from INT to {target_type}"
301+
);
302+
291303
// Note: currently no mention of Node::set_name(). Not sure if easily possible to add.
292304
assert_eq!(call_error.class_name(), Some("Object"));
293305
assert_eq!(call_error.method_name(), "call");
294-
assert_eq!(
295-
call_error.to_string(),
296-
"godot-rust function call failed: Object::call(&\"set_name\", [va] 123)\
297-
\n Reason: parameter #1 -- cannot convert from INT to STRING"
298-
);
306+
assert_eq!(call_error.to_string(), expected_error);
299307

300308
node.free();
301309
}

itest/rust/src/object_tests/object_test.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,11 @@ fn object_engine_accept_polymorphic() {
708708
let expected_name = StringName::from("Node name");
709709
let expected_class = GString::from("Node3D");
710710

711+
// Node::set_name() changed to accept StringName, in https://github.com/godotengine/godot/pull/76560.
712+
#[cfg(before_api = "4.5")]
711713
node.set_name(expected_name.arg());
714+
#[cfg(since_api = "4.5")]
715+
node.set_name(&expected_name);
712716

713717
let actual_name = accept_node(node.clone());
714718
assert_eq!(actual_name, expected_name);

0 commit comments

Comments
 (0)