Skip to content

Commit 29f711c

Browse files
authored
add regression test for #10385/#10389 (#10609)
Bevy introduced unintentional breaking behaviour along with the v0.12.0 release regarding the `App::set_runner` API. See: #10385, #10389 for details. We weren't able to catch this before release because this API is only used internally in one or two places (the very places which motivated the break). This commit adds a regression test to help guarantee some expected behaviour for custom runners, namely that `app::update` won't be called before the runner has a chance to initialise state.
1 parent 48d10e6 commit 29f711c

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

crates/bevy_app/src/app.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,4 +1204,36 @@ mod tests {
12041204
GenericLabel::<u64>(PhantomData).intern()
12051205
);
12061206
}
1207+
1208+
/// Custom runners should be in charge of when `app::update` gets called as they may need to
1209+
/// coordinate some state.
1210+
/// bug: <https://github.com/bevyengine/bevy/issues/10385>
1211+
/// fix: <https://github.com/bevyengine/bevy/pull/10389>
1212+
#[test]
1213+
fn regression_test_10385() {
1214+
use super::{Res, Resource};
1215+
use crate::PreUpdate;
1216+
1217+
#[derive(Resource)]
1218+
struct MyState {}
1219+
1220+
fn my_runner(mut app: App) {
1221+
let my_state = MyState {};
1222+
app.world.insert_resource(my_state);
1223+
1224+
for _ in 0..5 {
1225+
app.update();
1226+
}
1227+
}
1228+
1229+
fn my_system(_: Res<MyState>) {
1230+
// access state during app update
1231+
}
1232+
1233+
// Should not panic due to missing resource
1234+
App::new()
1235+
.set_runner(my_runner)
1236+
.add_systems(PreUpdate, my_system)
1237+
.run();
1238+
}
12071239
}

0 commit comments

Comments
 (0)