From f24149277f044027d0c3cd6740b1f6f20a760a16 Mon Sep 17 00:00:00 2001 From: Alice Date: Mon, 7 Feb 2022 14:32:51 -0500 Subject: [PATCH] Remove assert_compont_eq --- crates/bevy_app/src/lib.rs | 1 - crates/bevy_app/src/testing_tools.rs | 71 ---------------------- crates/bevy_ecs/src/world/mod.rs | 1 - crates/bevy_ecs/src/world/testing_tools.rs | 34 ----------- tests/integration_testing.rs | 12 +++- 5 files changed, 9 insertions(+), 110 deletions(-) delete mode 100644 crates/bevy_app/src/testing_tools.rs delete mode 100644 crates/bevy_ecs/src/world/testing_tools.rs diff --git a/crates/bevy_app/src/lib.rs b/crates/bevy_app/src/lib.rs index 6dc9e850978c9..a891c5957b786 100644 --- a/crates/bevy_app/src/lib.rs +++ b/crates/bevy_app/src/lib.rs @@ -6,7 +6,6 @@ mod app; mod plugin; mod plugin_group; mod schedule_runner; -mod testing_tools; #[cfg(feature = "bevy_ci_testing")] mod ci_testing; diff --git a/crates/bevy_app/src/testing_tools.rs b/crates/bevy_app/src/testing_tools.rs deleted file mode 100644 index 508ae82c98faa..0000000000000 --- a/crates/bevy_app/src/testing_tools.rs +++ /dev/null @@ -1,71 +0,0 @@ -//! Tools for convenient integration testing of the ECS. -//! -//! Each of these methods has a corresponding method on `World`. - -use crate::App; -use bevy_ecs::component::Component; -use bevy_ecs::query::{FilterFetch, WorldQuery}; -use std::fmt::Debug; - -impl App { - /// Asserts that all components of type `C` returned by a query with the filter `F` will equal `value` - /// - /// This is commonly used with the corresponding `query_len` method to ensure that the returned query is not empty. - /// - /// WARNING: because we are constructing the query from scratch, - /// [`Changed`](bevy_ecs::query::Changed) and [`Added`](bevy_ecs::query::Added) filters - /// will always return true. - /// - /// # Example - /// ```rust - /// # use bevy_app::App; - /// # use bevy_ecs::prelude::*; - /// - /// #[derive(Component)] - /// struct Player; - /// - /// #[derive(Component, Debug, PartialEq)] - /// struct Life(usize); - /// - /// let mut app = App::new(); - /// - /// fn spawn_player(mut commands: Commands){ - /// commands.spawn().insert(Life(8)).insert(Player); - /// } - /// - /// fn regenerate_life(mut query: Query<&mut Life>){ - /// for mut life in query.iter_mut(){ - /// if life.0 < 10 { - /// life.0 += 1; - /// } - /// } - /// } - /// - /// app.add_startup_system(spawn_player).add_system(regenerate_life); - /// - /// // Run the `Schedule` once, causing our startup system to run - /// // and life to regenerate once - /// app.update(); - /// // The `()` value for `F` will result in an unfiltered query - /// app.assert_component_eq::(&Life(9)); - /// - /// app.update(); - /// // Because all of our entities with the `Life` component also - /// // have the `Player` component, these will be equivalent. - /// app.assert_component_eq::>(&Life(10)); - /// - /// app.update(); - /// // Check that life regeneration caps at 10, as intended - /// // Filtering by the component type you're looking for is useless, - /// // but it's helpful to demonstrate composing query filters here - /// app.assert_component_eq::, With)>(&Life(10)); - /// ``` - pub fn assert_component_eq(&mut self, value: &C) - where - C: Component + PartialEq + Debug, - F: WorldQuery, - ::Fetch: FilterFetch, - { - self.world.assert_component_eq::(value); - } -} diff --git a/crates/bevy_ecs/src/world/mod.rs b/crates/bevy_ecs/src/world/mod.rs index 51c3d7e573223..1935fc75041fd 100644 --- a/crates/bevy_ecs/src/world/mod.rs +++ b/crates/bevy_ecs/src/world/mod.rs @@ -1,6 +1,5 @@ mod entity_ref; mod spawn_batch; -mod testing_tools; mod world_cell; pub use crate::change_detection::Mut; diff --git a/crates/bevy_ecs/src/world/testing_tools.rs b/crates/bevy_ecs/src/world/testing_tools.rs deleted file mode 100644 index 170a0975c46ab..0000000000000 --- a/crates/bevy_ecs/src/world/testing_tools.rs +++ /dev/null @@ -1,34 +0,0 @@ -//! Tools for convenient integration testing of the ECS. -//! -//! Each of these methods has a corresponding method on `App`; -//! in many cases, these are more convenient to use. - -use crate::component::Component; -use crate::entity::Entity; -use crate::world::{FilterFetch, World, WorldQuery}; -use std::fmt::Debug; - -impl World { - /// Asserts that all components of type `C` returned by a query with the filter `F` will equal `value` - /// - /// This is commonly used with the corresponding `query_len` method to ensure that the returned query is not empty. - /// - /// WARNING: because we are constructing the query from scratch, - /// [`Changed`](crate::query::Changed) and [`Added`](crate::query::Added) filters - /// will always return true. - pub fn assert_component_eq(&mut self, value: &C) - where - C: Component + PartialEq + Debug, - F: WorldQuery, - ::Fetch: FilterFetch, - { - let mut query_state = self.query_filtered::<(Entity, &C), F>(); - for (entity, component) in query_state.iter(self) { - if component != value { - panic!( - "Found component {component:?} for {entity:?}, but was expecting {value:?}." - ); - } - } - } -} diff --git a/tests/integration_testing.rs b/tests/integration_testing.rs index e3cb28f9d145f..4453b4fbcfce3 100644 --- a/tests/integration_testing.rs +++ b/tests/integration_testing.rs @@ -171,14 +171,18 @@ fn player_does_not_fall_through_floor() { // The player should start on the floor app.update(); - app.assert_component_eq::>(&Transform::from_xyz(0.0, 0.0, 0.0)); + let mut query_state = app.world.query_filtered::<&Transform, With>(); + let player_transform = query_state.iter(&app.world).next().unwrap(); + assert_eq!(player_transform, &Transform::from_xyz(0.0, 0.0, 0.0)); // Even after some time, the player should not fall through the floor for _ in 0..3 { app.update(); } - app.assert_component_eq::>(&Transform::from_xyz(0.0, 0.0, 0.0)); + let mut query_state = app.world.query_filtered::<&Transform, With>(); + let player_transform = query_state.iter(&app.world).next().unwrap(); + assert_eq!(player_transform, &Transform::from_xyz(0.0, 0.0, 0.0)); // If we drop the player from a height, they should eventually come to rest on the floor let mut player_query = app.world.query_filtered::<&mut Transform, With>(); @@ -191,7 +195,9 @@ fn player_does_not_fall_through_floor() { } // The player should have landed by now - app.assert_component_eq::>(&Transform::from_xyz(0.0, 0.0, 0.0)); + let mut query_state = app.world.query_filtered::<&Transform, With>(); + let player_transform = query_state.iter(&app.world).next().unwrap(); + assert_eq!(player_transform, &Transform::from_xyz(0.0, 0.0, 0.0)); } #[test]