Skip to content

Commit abdb32b

Browse files
committed
add some tests for panics
1 parent 6a61f5f commit abdb32b

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

crates/bevy_ecs/src/query/state.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,8 @@ impl<D: QueryData, F: QueryFilter> QueryState<D, F> {
430430
let mut new_filter_component_access = FilteredAccess::default();
431431
NewF::update_component_access(&new_filter_state, &mut new_filter_component_access);
432432

433+
component_access.extend(&new_filter_component_access);
434+
433435
let mut joined_component_access = self.component_access.clone();
434436
joined_component_access.extend(&other.component_access);
435437

@@ -1874,6 +1876,19 @@ mod tests {
18741876
assert_eq!(entity_a, detection_query.single(&world));
18751877
}
18761878

1879+
#[test]
1880+
#[should_panic(
1881+
expected = "Transmuted state for (bevy_ecs::entity::Entity, bevy_ecs::query::filter::Changed<bevy_ecs::query::state::tests::B>) attempts to access terms that are not allowed by original state (&bevy_ecs::query::state::tests::A, ())."
1882+
)]
1883+
fn cannot_transmute_changed_without_access() {
1884+
let mut world = World::new();
1885+
world.init_component::<A>();
1886+
world.init_component::<B>();
1887+
let query = QueryState::<&A>::new(&mut world);
1888+
let _new_query = query.transmute_filtered::<Entity, Changed<B>>(&world);
1889+
1890+
}
1891+
18771892
#[test]
18781893
fn join() {
18791894
let mut world = World::new();
@@ -1888,4 +1903,28 @@ mod tests {
18881903

18891904
assert_eq!(new_query.single(&world), entity_ab);
18901905
}
1906+
1907+
#[test]
1908+
#[should_panic(
1909+
expected = "Transmuted state for (&bevy_ecs::query::state::tests::C, ()) attempts to access terms that are not allowed by original state (&bevy_ecs::query::state::tests::A, ())."
1910+
)]
1911+
fn cannot_join_wrong_fetch() {
1912+
let mut world = World::new();
1913+
world.init_component::<C>();
1914+
let query_1 = QueryState::<&A>::new(&mut world);
1915+
let query_2 = QueryState::<&B>::new(&mut world);
1916+
let _query: QueryState<&C> = query_1.join(&world, &query_2);
1917+
}
1918+
1919+
#[test]
1920+
#[should_panic(
1921+
expected = "Transmuted state for (bevy_ecs::entity::Entity, bevy_ecs::query::filter::Changed<bevy_ecs::query::state::tests::C>) attempts to access terms that are not allowed by original state (&bevy_ecs::query::state::tests::A, bevy_ecs::query::filter::Without<bevy_ecs::query::state::tests::C>)."
1922+
)]
1923+
fn cannot_join_wrong_filter() {
1924+
let mut world = World::new();
1925+
let query_1 = QueryState::<&A, Without<C>>::new(&mut world);
1926+
let query_2 = QueryState::<&B, Without<C>>::new(&mut world);
1927+
let _: QueryState<Entity, Changed<C>> = query_1.join_filtered(&world, &query_2);
1928+
1929+
}
18911930
}

0 commit comments

Comments
 (0)