Skip to content

Commit

Permalink
Add regression test.
Browse files Browse the repository at this point in the history
  • Loading branch information
chescock committed Mar 11, 2023
1 parent 50470da commit 384fcdf
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion crates/bevy_ecs/src/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl<T> DebugCheckedUnwrap for Option<T> {
#[cfg(test)]
mod tests {
use super::{ReadOnlyWorldQuery, WorldQuery};
use crate::prelude::{AnyOf, Entity, Or, QueryState, With, Without};
use crate::prelude::{AnyOf, Changed, Entity, Or, QueryState, With, Without};
use crate::query::{ArchetypeFilter, QueryCombinationIter};
use crate::system::{IntoSystem, Query, System, SystemState};
use crate::{self as bevy_ecs, component::Component, world::World};
Expand Down Expand Up @@ -749,4 +749,37 @@ mod tests {
let _: [&Foo; 1] = q.many([e]);
let _: &Foo = q.single();
}

#[test]
fn par_iter_mut_change_detection() {
let mut world = World::new();
world.spawn((A(1), B(1)));

fn propagate_system(mut query: Query<(&A, &mut B), Changed<A>>) {
query.par_iter_mut().for_each_mut(|(a, mut b)| {
b.0 = a.0;
});
}
let mut propagate_system = IntoSystem::into_system(propagate_system);
propagate_system.initialize(&mut world);

fn modify_system(mut query: Query<&mut A>) {
for mut a in &mut query {
a.0 = 2;
}
}
let mut modify_system = IntoSystem::into_system(modify_system);
modify_system.initialize(&mut world);

propagate_system.run((), &mut world);
modify_system.run((), &mut world);
world.clear_trackers();

propagate_system.run((), &mut world);
modify_system.run((), &mut world);
world.clear_trackers();

let values = world.query::<&B>().iter(&world).collect::<Vec<&B>>();
assert_eq!(values, vec![&B(2)]);
}
}

0 comments on commit 384fcdf

Please sign in to comment.