@@ -651,6 +651,18 @@ mod tests {
651
651
assert_eq ! ( output, NonCopy ( 3 ) ) ;
652
652
}
653
653
654
+ #[ test]
655
+ fn fallible_system ( ) {
656
+ fn four ( ) -> Result < i32 > {
657
+ Ok ( 4 )
658
+ }
659
+
660
+ let mut world = World :: new ( ) ;
661
+ let fallible_system_id = world. register_system ( four) ;
662
+ let output = world. run_system ( fallible_system_id) ;
663
+ assert ! ( matches!( output, Ok ( Ok ( x) ) if x == four( ) . unwrap( ) ) ) ;
664
+ }
665
+
654
666
#[ test]
655
667
fn exclusive_system ( ) {
656
668
let mut world = World :: new ( ) ;
@@ -751,19 +763,53 @@ mod tests {
751
763
assert ! ( matches!( output, Ok ( x) if x == four( ) ) ) ;
752
764
}
753
765
766
+ #[ test]
767
+ fn cached_fallible_system ( ) {
768
+ fn four ( ) -> Result < i32 > {
769
+ Ok ( 4 )
770
+ }
771
+
772
+ let mut world = World :: new ( ) ;
773
+ let fallible_system_id = world. register_system_cached ( four) ;
774
+ let output = world. run_system ( fallible_system_id) ;
775
+ assert ! ( matches!( output, Ok ( Ok ( x) ) if x == four( ) . unwrap( ) ) ) ;
776
+ let output = world. run_system_cached ( four) ;
777
+ assert ! ( matches!( output, Ok ( Ok ( x) ) if x == four( ) . unwrap( ) ) ) ;
778
+ let output = world. run_system_cached_with ( four, ( ) ) ;
779
+ assert ! ( matches!( output, Ok ( Ok ( x) ) if x == four( ) . unwrap( ) ) ) ;
780
+ }
781
+
754
782
#[ test]
755
783
fn cached_system_commands ( ) {
756
- fn sys ( mut counter : ResMut < Counter > ) {
757
- counter. 0 = 1 ;
784
+ fn increase ( mut counter : ResMut < Counter > ) {
785
+ counter. 0 + = 1 ;
758
786
}
759
787
760
788
let mut world = World :: new ( ) ;
761
789
world. insert_resource ( Counter ( 0 ) ) ;
762
-
763
- world. commands ( ) . run_system_cached ( sys) ;
790
+ world. commands ( ) . run_system_cached ( increase) ;
791
+ world. flush_commands ( ) ;
792
+ assert_eq ! ( world. resource:: <Counter >( ) . 0 , 1 ) ;
793
+ world. commands ( ) . run_system_cached_with ( increase, ( ) ) ;
764
794
world. flush_commands ( ) ;
795
+ assert_eq ! ( world. resource:: <Counter >( ) . 0 , 2 ) ;
796
+ }
765
797
798
+ #[ test]
799
+ fn cached_fallible_system_commands ( ) {
800
+ fn increase ( mut counter : ResMut < Counter > ) -> Result {
801
+ counter. 0 += 1 ;
802
+ Ok ( ( ) )
803
+ }
804
+
805
+ let mut world = World :: new ( ) ;
806
+ world. insert_resource ( Counter ( 0 ) ) ;
807
+ world. commands ( ) . run_system_cached ( increase) ;
808
+ world. flush_commands ( ) ;
766
809
assert_eq ! ( world. resource:: <Counter >( ) . 0 , 1 ) ;
810
+ world. commands ( ) . run_system_cached_with ( increase, ( ) ) ;
811
+ world. flush_commands ( ) ;
812
+ assert_eq ! ( world. resource:: <Counter >( ) . 0 , 2 ) ;
767
813
}
768
814
769
815
#[ test]
0 commit comments