@@ -315,7 +315,7 @@ mod __rust_begin_short_backtrace {
315
315
#[ cfg( test) ]
316
316
mod tests {
317
317
use crate :: {
318
- prelude:: { Component , Resource , Schedule } ,
318
+ prelude:: { Component , In , IntoSystem , Resource , Schedule } ,
319
319
schedule:: ExecutorKind ,
320
320
system:: { Populated , Res , ResMut , Single } ,
321
321
world:: World ,
@@ -336,6 +336,9 @@ mod tests {
336
336
single_ran : bool ,
337
337
}
338
338
339
+ #[ derive( Resource , Default ) ]
340
+ struct Counter ( u8 ) ;
341
+
339
342
fn set_single_state ( mut _single : Single < & TestComponent > , mut state : ResMut < TestState > ) {
340
343
state. single_ran = true ;
341
344
}
@@ -408,4 +411,162 @@ mod tests {
408
411
schedule. add_systems ( look_for_missing_resource) ;
409
412
schedule. run ( & mut world) ;
410
413
}
414
+
415
+ #[ test]
416
+ fn piped_systems_first_system_skipped ( ) {
417
+ // This system should be skipped when run due to no matching entity
418
+ fn pipe_out ( _single : Single < & TestComponent > ) -> u8 {
419
+ 42
420
+ }
421
+
422
+ fn pipe_in ( _input : In < u8 > , mut counter : ResMut < Counter > ) {
423
+ counter. 0 += 1 ;
424
+ }
425
+
426
+ let mut world = World :: new ( ) ;
427
+ world. init_resource :: < Counter > ( ) ;
428
+ let mut schedule = Schedule :: default ( ) ;
429
+
430
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
431
+ schedule. run ( & mut world) ;
432
+
433
+ let counter = world. resource :: < Counter > ( ) ;
434
+ assert_eq ! ( counter. 0 , 0 ) ;
435
+ }
436
+
437
+ #[ test]
438
+ fn piped_system_second_system_skipped ( ) {
439
+ fn pipe_out ( mut counter : ResMut < Counter > ) -> u8 {
440
+ counter. 0 += 1 ;
441
+ 42
442
+ }
443
+
444
+ // This system should be skipped when run due to no matching entity
445
+ fn pipe_in ( _input : In < u8 > , _single : Single < & TestComponent > ) { }
446
+
447
+ let mut world = World :: new ( ) ;
448
+ world. init_resource :: < Counter > ( ) ;
449
+ let mut schedule = Schedule :: default ( ) ;
450
+
451
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
452
+ schedule. run ( & mut world) ;
453
+ let counter = world. resource :: < Counter > ( ) ;
454
+ assert_eq ! ( counter. 0 , 0 ) ;
455
+ }
456
+
457
+ #[ test]
458
+ #[ should_panic]
459
+ fn piped_system_first_system_panics ( ) {
460
+ // This system should panic when run because the resource is missing
461
+ fn pipe_out ( _res : Res < TestState > ) -> u8 {
462
+ 42
463
+ }
464
+
465
+ fn pipe_in ( _input : In < u8 > ) { }
466
+
467
+ let mut world = World :: new ( ) ;
468
+ let mut schedule = Schedule :: default ( ) ;
469
+
470
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
471
+ schedule. run ( & mut world) ;
472
+ }
473
+
474
+ #[ test]
475
+ #[ should_panic]
476
+ fn piped_system_second_system_panics ( ) {
477
+ fn pipe_out ( ) -> u8 {
478
+ 42
479
+ }
480
+
481
+ // This system should panic when run because the resource is missing
482
+ fn pipe_in ( _input : In < u8 > , _res : Res < TestState > ) { }
483
+
484
+ let mut world = World :: new ( ) ;
485
+ let mut schedule = Schedule :: default ( ) ;
486
+
487
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
488
+ schedule. run ( & mut world) ;
489
+ }
490
+
491
+ // This test runs without panicking because we've
492
+ // decided to use early-out behavior for piped systems
493
+ #[ test]
494
+ fn piped_system_skip_and_panic ( ) {
495
+ // This system should be skipped when run due to no matching entity
496
+ fn pipe_out ( _single : Single < & TestComponent > ) -> u8 {
497
+ 42
498
+ }
499
+
500
+ // This system should panic when run because the resource is missing
501
+ fn pipe_in ( _input : In < u8 > , _res : Res < TestState > ) { }
502
+
503
+ let mut world = World :: new ( ) ;
504
+ let mut schedule = Schedule :: default ( ) ;
505
+
506
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
507
+ schedule. run ( & mut world) ;
508
+ }
509
+
510
+ #[ test]
511
+ #[ should_panic]
512
+ fn piped_system_panic_and_skip ( ) {
513
+ // This system should panic when run because the resource is missing
514
+
515
+ fn pipe_out ( _res : Res < TestState > ) -> u8 {
516
+ 42
517
+ }
518
+
519
+ // This system should be skipped when run due to no matching entity
520
+ fn pipe_in ( _input : In < u8 > , _single : Single < & TestComponent > ) { }
521
+
522
+ let mut world = World :: new ( ) ;
523
+ let mut schedule = Schedule :: default ( ) ;
524
+
525
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
526
+ schedule. run ( & mut world) ;
527
+ }
528
+
529
+ #[ test]
530
+ #[ should_panic]
531
+ fn piped_system_panic_and_panic ( ) {
532
+ // This system should panic when run because the resource is missing
533
+
534
+ fn pipe_out ( _res : Res < TestState > ) -> u8 {
535
+ 42
536
+ }
537
+
538
+ // This system should panic when run because the resource is missing
539
+ fn pipe_in ( _input : In < u8 > , _res : Res < TestState > ) { }
540
+
541
+ let mut world = World :: new ( ) ;
542
+ let mut schedule = Schedule :: default ( ) ;
543
+
544
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
545
+ schedule. run ( & mut world) ;
546
+ }
547
+
548
+ #[ test]
549
+ fn piped_system_skip_and_skip ( ) {
550
+ // This system should be skipped when run due to no matching entity
551
+
552
+ fn pipe_out ( _single : Single < & TestComponent > , mut counter : ResMut < Counter > ) -> u8 {
553
+ counter. 0 += 1 ;
554
+ 42
555
+ }
556
+
557
+ // This system should be skipped when run due to no matching entity
558
+ fn pipe_in ( _input : In < u8 > , _single : Single < & TestComponent > , mut counter : ResMut < Counter > ) {
559
+ counter. 0 += 1 ;
560
+ }
561
+
562
+ let mut world = World :: new ( ) ;
563
+ world. init_resource :: < Counter > ( ) ;
564
+ let mut schedule = Schedule :: default ( ) ;
565
+
566
+ schedule. add_systems ( pipe_out. pipe ( pipe_in) ) ;
567
+ schedule. run ( & mut world) ;
568
+
569
+ let counter = world. resource :: < Counter > ( ) ;
570
+ assert_eq ! ( counter. 0 , 0 ) ;
571
+ }
411
572
}
0 commit comments