Skip to content

Commit 55c0868

Browse files
committed
add side-effectful test demonstrating InMut
1 parent 8467283 commit 55c0868

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

crates/bevy_ecs/src/system/system_registry.rs

+30
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,11 @@ mod tests {
463463
#[derive(Resource, Default, PartialEq, Debug)]
464464
struct Counter(u8);
465465

466+
#[derive(Event)]
467+
struct MyEvent {
468+
cancelled: bool,
469+
}
470+
466471
#[test]
467472
fn change_detection() {
468473
#[derive(Resource, Default)]
@@ -664,4 +669,29 @@ mod tests {
664669
world.run_system_with_input(id, &2).unwrap();
665670
assert_eq!(*world.resource::<Counter>(), Counter(2));
666671
}
672+
673+
#[test]
674+
fn system_with_input_mut() {
675+
fn post(InMut(event): InMut<MyEvent>, counter: ResMut<Counter>) {
676+
if counter.0 > 0 {
677+
event.cancelled = true;
678+
}
679+
}
680+
681+
let mut world = World::new();
682+
world.insert_resource(Counter(0));
683+
let post_system = world.register_system(post);
684+
685+
let mut event = MyEvent { cancelled: false };
686+
world
687+
.run_system_with_input(post_system, &mut event)
688+
.unwrap();
689+
assert!(!event.cancelled);
690+
691+
world.resource_mut::<Counter>().0 = 1;
692+
world
693+
.run_system_with_input(post_system, &mut event)
694+
.unwrap();
695+
assert!(event.cancelled);
696+
}
667697
}

0 commit comments

Comments
 (0)