|
2 | 2 | #![allow(deprecated)]
|
3 | 3 |
|
4 | 4 | use gdnative::prelude::*;
|
| 5 | +use gdnative_core::godot_itest; |
5 | 6 |
|
6 | 7 | mod test_as_arg;
|
7 | 8 | mod test_async;
|
@@ -79,25 +80,14 @@ pub extern "C" fn run_tests(
|
79 | 80 | status &= test_variant_call_args::run_tests();
|
80 | 81 | status &= test_variant_ops::run_tests();
|
81 | 82 |
|
82 |
| - gdnative::core_types::Variant::new(status).leak() |
| 83 | + Variant::new(status).leak() |
83 | 84 | }
|
84 | 85 |
|
85 |
| -fn test_underscore_method_binding() -> bool { |
86 |
| - println!(" -- test_underscore_method_binding"); |
87 |
| - |
88 |
| - let ok = std::panic::catch_unwind(|| { |
89 |
| - let script = gdnative::api::NativeScript::new(); |
90 |
| - let result = script._new(&[]); |
91 |
| - assert_eq!(Variant::nil(), result); |
92 |
| - }) |
93 |
| - .is_ok(); |
94 |
| - |
95 |
| - if !ok { |
96 |
| - godot_error!(" !! Test test_underscore_method_binding failed"); |
97 |
| - } |
98 |
| - |
99 |
| - ok |
100 |
| -} |
| 86 | +godot_itest! { test_underscore_method_binding { |
| 87 | + let script = gdnative::api::NativeScript::new(); |
| 88 | + let result = script._new(&[]); |
| 89 | + assert_eq!(Variant::nil(), result); |
| 90 | +}} |
101 | 91 |
|
102 | 92 | #[derive(NativeClass)]
|
103 | 93 | #[inherit(Reference)]
|
@@ -152,31 +142,19 @@ impl Foo {
|
152 | 142 | }
|
153 | 143 | }
|
154 | 144 |
|
155 |
| -fn test_rust_class_construction() -> bool { |
156 |
| - println!(" -- test_rust_class_construction"); |
157 |
| - |
158 |
| - let ok = std::panic::catch_unwind(|| { |
159 |
| - let foo = Foo::new_instance(); |
| 145 | +godot_itest! { test_rust_class_construction { |
| 146 | + let foo = Foo::new_instance(); |
| 147 | + assert_eq!(Ok(42), foo.map(|foo, owner| { foo.answer(&*owner) })); |
160 | 148 |
|
161 |
| - assert_eq!(Ok(42), foo.map(|foo, owner| { foo.answer(&*owner) })); |
| 149 | + let base = foo.into_base(); |
| 150 | + assert_eq!(Some(42), unsafe { base.call("answer", &[]).to() }); |
162 | 151 |
|
163 |
| - let base = foo.into_base(); |
164 |
| - assert_eq!(Some(42), unsafe { base.call("answer", &[]).to() }); |
| 152 | + let foo = Instance::<Foo, _>::try_from_base(base).expect("should be able to downcast"); |
| 153 | + assert_eq!(Ok(42), foo.map(|foo, owner| { foo.answer(&*owner) })); |
165 | 154 |
|
166 |
| - let foo = Instance::<Foo, _>::try_from_base(base).expect("should be able to downcast"); |
167 |
| - assert_eq!(Ok(42), foo.map(|foo, owner| { foo.answer(&*owner) })); |
168 |
| - |
169 |
| - let base = foo.into_base(); |
170 |
| - assert!(Instance::<NotFoo, _>::try_from_base(base).is_err()); |
171 |
| - }) |
172 |
| - .is_ok(); |
173 |
| - |
174 |
| - if !ok { |
175 |
| - godot_error!(" !! Test test_rust_class_construction failed"); |
176 |
| - } |
177 |
| - |
178 |
| - ok |
179 |
| -} |
| 155 | + let base = foo.into_base(); |
| 156 | + assert!(Instance::<NotFoo, _>::try_from_base(base).is_err()); |
| 157 | +}} |
180 | 158 |
|
181 | 159 | #[derive(NativeClass)]
|
182 | 160 | #[inherit(Reference)]
|
@@ -205,60 +183,49 @@ impl OptionalArgs {
|
205 | 183 | }
|
206 | 184 | }
|
207 | 185 |
|
208 |
| -fn test_from_instance_id() -> bool { |
209 |
| - println!(" -- test_from_instance_id"); |
| 186 | +godot_itest! { test_from_instance_id { |
| 187 | + assert!(unsafe { Node::try_from_instance_id(22).is_none() }); |
| 188 | + assert!(unsafe { Node::try_from_instance_id(42).is_none() }); |
| 189 | + assert!(unsafe { Node::try_from_instance_id(503).is_none() }); |
210 | 190 |
|
211 |
| - let ok = std::panic::catch_unwind(|| { |
212 |
| - assert!(unsafe { Node::try_from_instance_id(22).is_none() }); |
213 |
| - assert!(unsafe { Node::try_from_instance_id(42).is_none() }); |
214 |
| - assert!(unsafe { Node::try_from_instance_id(503).is_none() }); |
| 191 | + let instance_id; |
215 | 192 |
|
216 |
| - let instance_id; |
| 193 | + { |
| 194 | + let foo = unsafe { Node::new().into_shared().assume_safe() }; |
| 195 | + foo.set_name("foo"); |
217 | 196 |
|
218 |
| - { |
219 |
| - let foo = unsafe { Node::new().into_shared().assume_safe() }; |
220 |
| - foo.set_name("foo"); |
| 197 | + instance_id = foo.get_instance_id(); |
221 | 198 |
|
222 |
| - instance_id = foo.get_instance_id(); |
223 |
| - |
224 |
| - assert!(unsafe { Reference::try_from_instance_id(instance_id).is_none() }); |
225 |
| - |
226 |
| - let reconstructed = unsafe { Node::from_instance_id(instance_id) }; |
227 |
| - assert_eq!("foo", reconstructed.name().to_string()); |
228 |
| - |
229 |
| - unsafe { foo.assume_unique().free() }; |
230 |
| - } |
| 199 | + assert!(unsafe { Reference::try_from_instance_id(instance_id).is_none() }); |
231 | 200 |
|
232 |
| - assert!(unsafe { Node::try_from_instance_id(instance_id).is_none() }); |
| 201 | + let reconstructed = unsafe { Node::from_instance_id(instance_id) }; |
| 202 | + assert_eq!("foo", reconstructed.name().to_string()); |
233 | 203 |
|
234 |
| - let instance_id; |
| 204 | + unsafe { foo.assume_unique().free() }; |
| 205 | + } |
235 | 206 |
|
236 |
| - { |
237 |
| - let foo = Reference::new().into_shared(); |
238 |
| - let foo = unsafe { foo.assume_safe() }; |
239 |
| - foo.set_meta("foo", "bar"); |
| 207 | + assert!(unsafe { Node::try_from_instance_id(instance_id).is_none() }); |
240 | 208 |
|
241 |
| - instance_id = foo.get_instance_id(); |
| 209 | + let instance_id; |
242 | 210 |
|
243 |
| - assert!(unsafe { Node::try_from_instance_id(instance_id).is_none() }); |
| 211 | + { |
| 212 | + let foo = Reference::new().into_shared(); |
| 213 | + let foo = unsafe { foo.assume_safe() }; |
| 214 | + foo.set_meta("foo", "bar"); |
244 | 215 |
|
245 |
| - let reconstructed = unsafe { Reference::from_instance_id(instance_id) }; |
246 |
| - assert_eq!( |
247 |
| - "bar", |
248 |
| - String::from_variant(&reconstructed.get_meta("foo")).unwrap() |
249 |
| - ); |
250 |
| - } |
| 216 | + instance_id = foo.get_instance_id(); |
251 | 217 |
|
252 |
| - assert!(unsafe { Reference::try_from_instance_id(instance_id).is_none() }); |
253 |
| - }) |
254 |
| - .is_ok(); |
| 218 | + assert!(unsafe { Node::try_from_instance_id(instance_id).is_none() }); |
255 | 219 |
|
256 |
| - if !ok { |
257 |
| - godot_error!(" !! Test test_from_instance_id failed"); |
| 220 | + let reconstructed = unsafe { Reference::from_instance_id(instance_id) }; |
| 221 | + assert_eq!( |
| 222 | + "bar", |
| 223 | + String::from_variant(&reconstructed.get_meta("foo")).unwrap() |
| 224 | + ); |
258 | 225 | }
|
259 | 226 |
|
260 |
| - ok |
261 |
| -} |
| 227 | + assert!(unsafe { Reference::try_from_instance_id(instance_id).is_none() }); |
| 228 | +}} |
262 | 229 |
|
263 | 230 | fn init(handle: InitHandle) {
|
264 | 231 | handle.add_class::<Foo>();
|
|
0 commit comments