@@ -92,9 +92,8 @@ func test_export_dyn_gd_should_fail_for_wrong_type():
92
92
var dyn_gd_exporter = RefcDynGdVarDeclarer.new()
93
93
var refc = RefcHealth.new()
94
94
95
- disable_error_messages()
96
- dyn_gd_exporter.second = refc # Should fail.
97
- enable_error_messages()
95
+ expect_fail()
96
+ dyn_gd_exporter.second = refc # Causes current function to fail. Following code unreachable.
98
97
99
98
assert_fail(" `DynGdExporter.second` should only accept NodeHealth and only if it implements `InstanceIdProvider` trait" )
100
99
@@ -310,19 +309,19 @@ func test_custom_property_wrong_values_1():
310
309
return
311
310
312
311
var has_property: HasCustomProperty = HasCustomProperty.new()
313
- disable_error_messages ()
314
- has_property.some_c_style_enum = 10 # Should fail.
315
- enable_error_messages()
312
+ expect_fail ()
313
+ has_property.some_c_style_enum = 10 # Causes current function to fail. Following code unreachable .
314
+
316
315
assert_fail(" HasCustomProperty.some_c_style_enum should only accept integers in the range `(0 ..= 2)`" )
317
316
318
317
func test_custom_property_wrong_values_2():
319
318
if runs_release():
320
319
return
321
320
322
321
var has_property: HasCustomProperty = HasCustomProperty.new()
323
- disable_error_messages ()
324
- has_property.not_exportable = { " a" : " hello" , " b" : Callable()} # Should fail.
325
- enable_error_messages()
322
+ expect_fail ()
323
+ has_property.not_exportable = { " a" : " hello" , " b" : Callable()} # Causes current function to fail. Following code unreachable .
324
+
326
325
assert_fail(" HasCustomProperty.not_exportable should only accept dictionaries with float values" )
327
326
328
327
func test_option_export():
@@ -482,3 +481,58 @@ func test_renamed_func_get_set():
482
481
assert_eq(obj.f1(), 84 )
483
482
484
483
obj.free()
484
+
485
+ # -----------------------------------------------------------------------------------------------------------------------------------------------
486
+ # Tests below verify the following:
487
+ # Calling a typed Rust function with a Variant that cannot be converted to the Rust type will cause a failed function call on _GDScript_ side,
488
+ # meaning the GDScript function aborts immediately. This happens because a `Variant -> T` conversion occurs dynamically *on GDScript side*,
489
+ # before the Rust function is called.In contrast, panics inside the Rust function (e.g. variant.to::<T>()) just cause the *Rust* function to fail.
490
+ #
491
+ # Store arguments as Variant, as GDScript wouldn't parse script otherwise. Results in varcall being used.
492
+
493
+ func test_marshalling_fail_variant_type():
494
+ if runs_release():
495
+ return
496
+
497
+ # Expects Object, pass GString.
498
+ var obj := ObjectTest.new()
499
+ var arg: Variant = " not an object"
500
+ expect_fail()
501
+ obj.pass_object(arg) # Causes current function to fail. Following code unreachable.
502
+
503
+ assert_fail(" GDScript function should fail after marshalling error (bad variant type)" )
504
+
505
+ func test_marshalling_fail_non_null():
506
+ if runs_release():
507
+ return
508
+
509
+ # Expects Object, pass null.
510
+ var obj := ObjectTest.new()
511
+
512
+ expect_fail()
513
+ obj.pass_object(null) # Causes current function to fail. Following code unreachable.
514
+
515
+ assert_fail(" GDScript function should fail after marshalling error (required non-null)" )
516
+
517
+ func test_marshalling_fail_integer_overflow():
518
+ if runs_release():
519
+ return
520
+
521
+ # Expects i32. This overflows.
522
+ var obj := ObjectTest.new()
523
+ var arg: Variant = 9223372036854775807
524
+
525
+ expect_fail()
526
+ obj.pass_i32(arg) # Causes current function to fail. Following code unreachable.
527
+
528
+ assert_fail(" GDScript function should fail after marshalling error (int overflow)" )
529
+
530
+ func test_marshalling_continues_on_panic():
531
+ mark_test_pending()
532
+
533
+ # Expects i32. This overflows.
534
+ var obj := ObjectTest.new()
535
+ var result = obj.cause_panic() # Fails in Rust, current function continues.
536
+
537
+ assert_eq(result, Vector3.ZERO, " Default value returned on failed function call" )
538
+ mark_test_succeeded()
0 commit comments