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:
JoJoJet 2023-03-30 17:47:36 -04:00 committed by GitHub
parent 300b275edc
commit 98954311b3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1563,11 +1563,13 @@ mod tests {
use crate::{
self as bevy_ecs, // Necessary for the `SystemParam` Derive when used inside `bevy_ecs`.
query::{ReadOnlyWorldQuery, WorldQuery},
system::Query,
system::{assert_is_system, Query},
};
use std::marker::PhantomData;
// Compile test for https://github.com/bevyengine/bevy/pull/2838.
#[test]
fn system_param_generic_bounds() {
#[derive(SystemParam)]
pub struct SpecialQuery<
'w,
@ -1578,8 +1580,13 @@ mod tests {
_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)]
pub struct SpecialRes<'w, T: Resource> {
_res: Res<'w, T>,
@ -1590,16 +1597,33 @@ mod tests {
_local: Local<'s, T>,
}
#[derive(Resource)]
struct R;
fn my_system(_: SpecialRes<R>, _: SpecialLocal<u32>) {}
assert_is_system(my_system);
}
#[derive(Resource)]
pub struct R<const I: usize>;
// Compile test for https://github.com/bevyengine/bevy/pull/7001.
#[test]
fn system_param_const_generics() {
#[derive(SystemParam)]
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.
#[test]
fn system_param_field_limit() {
#[derive(SystemParam)]
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>>,
_r1: Res<'w, R<1>>,
_r2: Res<'w, R<2>>,
@ -1619,13 +1643,14 @@ mod tests {
_r16: Res<'w, R<16>>,
}
#[allow(dead_code)]
fn long_system(_param: LongParam) {
crate::system::assert_is_system(long_system);
fn long_system(_: LongParam) {}
assert_is_system(long_system);
}
// Compile test for https://github.com/bevyengine/bevy/pull/6919.
// Regression test for https://github.com/bevyengine/bevy/issues/7447.
#[test]
fn system_param_phantom_data() {
#[derive(SystemParam)]
struct IgnoredParam<'w, T: Resource, Marker: 'static> {
_foo: Res<'w, T>,
@ -1634,8 +1659,13 @@ mod tests {
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)]
pub struct UnitParam;
@ -1645,14 +1675,26 @@ mod tests {
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)]
struct PrivateResource;
// Regression test for https://github.com/bevyengine/bevy/issues/4200.
#[derive(SystemParam)]
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.
#[test]
fn system_param_where_clause() {
#[derive(SystemParam)]
pub struct WhereParam<'w, 's, Q>
where
@ -1661,18 +1703,34 @@ mod tests {
_q: Query<'w, 's, Q, ()>,
}
fn my_system(_: WhereParam<()>) {}
assert_is_system(my_system);
}
// Regression test for https://github.com/bevyengine/bevy/issues/1727.
#[test]
fn system_param_name_collision() {
#[derive(Resource)]
pub struct FetchState;
#[derive(SystemParam)]
pub struct Collide<'w> {
_x: Res<'w, FetchState>,
}
#[derive(Resource)]
pub struct FetchState;
fn my_system(_: Collide) {}
assert_is_system(my_system);
}
// Regression test for https://github.com/bevyengine/bevy/issues/8192.
#[test]
fn system_param_invariant_lifetime() {
#[derive(SystemParam)]
pub struct InvariantParam<'w, 's> {
_set: ParamSet<'w, 's, (Query<'w, 's, ()>,)>,
}
fn my_system(_: InvariantParam) {}
assert_is_system(my_system);
}
}