Use actual tests for SystemParam regression tests (#8270)
# Objective Our regression tests for `SystemParam` currently consist of a bunch of loosely dispersed struct definitions. This is messy, and doesn't fully test their functionality. ## Solution Group the struct definitions into functions annotated with `#[test]`. This not only makes the module more organized, but it allows us to call `assert_is_system`, which has the potential to catch some bugs that would have been missed with the old approach. Also, this approach is consistent with how `WorldQuery` regression tests are organized.
This commit is contained in:
parent
300b275edc
commit
98954311b3
@ -1563,11 +1563,13 @@ mod tests {
|
|||||||
use crate::{
|
use crate::{
|
||||||
self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`.
|
self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`.
|
||||||
query::{ReadOnlyWorldQuery, WorldQuery},
|
query::{ReadOnlyWorldQuery, WorldQuery},
|
||||||
system::Query,
|
system::{assert_is_system, Query},
|
||||||
};
|
};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
|
|
||||||
// Compile test for https://github.com/bevyengine/bevy/pull/2838.
|
// Compile test for https://github.com/bevyengine/bevy/pull/2838.
|
||||||
|
#[test]
|
||||||
|
fn system_param_generic_bounds() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct SpecialQuery<
|
pub struct SpecialQuery<
|
||||||
'w,
|
'w,
|
||||||
@ -1578,8 +1580,13 @@ mod tests {
|
|||||||
_query: Query<'w, 's, Q, F>,
|
_query: Query<'w, 's, Q, F>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile tests for https://github.com/bevyengine/bevy/pull/6694.
|
fn my_system(_: SpecialQuery<(), ()>) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile tests for https://github.com/bevyengine/bevy/pull/6694.
|
||||||
|
#[test]
|
||||||
|
fn system_param_flexibility() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct SpecialRes<'w, T: Resource> {
|
pub struct SpecialRes<'w, T: Resource> {
|
||||||
_res: Res<'w, T>,
|
_res: Res<'w, T>,
|
||||||
@ -1590,16 +1597,33 @@ mod tests {
|
|||||||
_local: Local<'s, T>,
|
_local: Local<'s, T>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Resource)]
|
||||||
|
struct R;
|
||||||
|
|
||||||
|
fn my_system(_: SpecialRes<R>, _: SpecialLocal<u32>) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct R<const I: usize>;
|
pub struct R<const I: usize>;
|
||||||
|
|
||||||
// Compile test for https://github.com/bevyengine/bevy/pull/7001.
|
// Compile test for https://github.com/bevyengine/bevy/pull/7001.
|
||||||
|
#[test]
|
||||||
|
fn system_param_const_generics() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct ConstGenericParam<'w, const I: usize>(Res<'w, R<I>>);
|
pub struct ConstGenericParam<'w, const I: usize>(Res<'w, R<I>>);
|
||||||
|
|
||||||
|
fn my_system(_: ConstGenericParam<0>, _: ConstGenericParam<1000>) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
// Compile test for https://github.com/bevyengine/bevy/pull/6867.
|
// Compile test for https://github.com/bevyengine/bevy/pull/6867.
|
||||||
|
#[test]
|
||||||
|
fn system_param_field_limit() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct LongParam<'w> {
|
pub struct LongParam<'w> {
|
||||||
|
// Each field should be a distinct type so there will
|
||||||
|
// be an error if the derive messes up the field order.
|
||||||
_r0: Res<'w, R<0>>,
|
_r0: Res<'w, R<0>>,
|
||||||
_r1: Res<'w, R<1>>,
|
_r1: Res<'w, R<1>>,
|
||||||
_r2: Res<'w, R<2>>,
|
_r2: Res<'w, R<2>>,
|
||||||
@ -1619,13 +1643,14 @@ mod tests {
|
|||||||
_r16: Res<'w, R<16>>,
|
_r16: Res<'w, R<16>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
fn long_system(_: LongParam) {}
|
||||||
fn long_system(_param: LongParam) {
|
assert_is_system(long_system);
|
||||||
crate::system::assert_is_system(long_system);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile test for https://github.com/bevyengine/bevy/pull/6919.
|
// Compile test for https://github.com/bevyengine/bevy/pull/6919.
|
||||||
// Regression test for https://github.com/bevyengine/bevy/issues/7447.
|
// Regression test for https://github.com/bevyengine/bevy/issues/7447.
|
||||||
|
#[test]
|
||||||
|
fn system_param_phantom_data() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
struct IgnoredParam<'w, T: Resource, Marker: 'static> {
|
struct IgnoredParam<'w, T: Resource, Marker: 'static> {
|
||||||
_foo: Res<'w, T>,
|
_foo: Res<'w, T>,
|
||||||
@ -1634,8 +1659,13 @@ mod tests {
|
|||||||
marker2: PhantomData<&'w Marker>,
|
marker2: PhantomData<&'w Marker>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compile tests for https://github.com/bevyengine/bevy/pull/6957.
|
fn my_system(_: IgnoredParam<R<0>, ()>) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Compile tests for https://github.com/bevyengine/bevy/pull/6957.
|
||||||
|
#[test]
|
||||||
|
fn system_param_struct_variants() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct UnitParam;
|
pub struct UnitParam;
|
||||||
|
|
||||||
@ -1645,14 +1675,26 @@ mod tests {
|
|||||||
Local<'s, L>,
|
Local<'s, L>,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
fn my_system(_: UnitParam, _: TupleParam<R<0>, u32>) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Regression test for https://github.com/bevyengine/bevy/issues/4200.
|
||||||
|
#[test]
|
||||||
|
fn system_param_private_fields() {
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct PrivateResource;
|
struct PrivateResource;
|
||||||
|
|
||||||
// Regression test for https://github.com/bevyengine/bevy/issues/4200.
|
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct EncapsulatedParam<'w>(Res<'w, PrivateResource>);
|
pub struct EncapsulatedParam<'w>(Res<'w, PrivateResource>);
|
||||||
|
|
||||||
|
fn my_system(_: EncapsulatedParam) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/bevyengine/bevy/issues/7103.
|
// Regression test for https://github.com/bevyengine/bevy/issues/7103.
|
||||||
|
#[test]
|
||||||
|
fn system_param_where_clause() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct WhereParam<'w, 's, Q>
|
pub struct WhereParam<'w, 's, Q>
|
||||||
where
|
where
|
||||||
@ -1661,18 +1703,34 @@ mod tests {
|
|||||||
_q: Query<'w, 's, Q, ()>,
|
_q: Query<'w, 's, Q, ()>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn my_system(_: WhereParam<()>) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/bevyengine/bevy/issues/1727.
|
// Regression test for https://github.com/bevyengine/bevy/issues/1727.
|
||||||
|
#[test]
|
||||||
|
fn system_param_name_collision() {
|
||||||
|
#[derive(Resource)]
|
||||||
|
pub struct FetchState;
|
||||||
|
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct Collide<'w> {
|
pub struct Collide<'w> {
|
||||||
_x: Res<'w, FetchState>,
|
_x: Res<'w, FetchState>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
fn my_system(_: Collide) {}
|
||||||
pub struct FetchState;
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
|
|
||||||
// Regression test for https://github.com/bevyengine/bevy/issues/8192.
|
// Regression test for https://github.com/bevyengine/bevy/issues/8192.
|
||||||
|
#[test]
|
||||||
|
fn system_param_invariant_lifetime() {
|
||||||
#[derive(SystemParam)]
|
#[derive(SystemParam)]
|
||||||
pub struct InvariantParam<'w, 's> {
|
pub struct InvariantParam<'w, 's> {
|
||||||
_set: ParamSet<'w, 's, (Query<'w, 's, ()>,)>,
|
_set: ParamSet<'w, 's, (Query<'w, 's, ()>,)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn my_system(_: InvariantParam) {}
|
||||||
|
assert_is_system(my_system);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user