Skip to content

Commit bb08d00

Browse files
committed
Make clippy happy, add small test.
1 parent a2d4159 commit bb08d00

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

crates/bevy_app/src/app.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ impl App {
157157
self.sub_apps.update();
158158
}
159159

160-
/// Sets the update function to use for [`update`](Self::update) on the [SubApps] collection to the provided function.
160+
/// Sets the update function to use for [`update`](Self::update) on the [`SubApps`] collection to the provided function.
161161
pub fn set_update_fn(&mut self, func: impl Fn(&mut SubApps) + 'static) {
162162
self.sub_apps.update_fn = Some(Box::new(func));
163163
}
@@ -1441,8 +1441,8 @@ impl Termination for AppExit {
14411441

14421442
#[cfg(test)]
14431443
mod tests {
1444-
use core::marker::PhantomData;
1445-
use std::sync::Mutex;
1444+
use core::{marker::PhantomData, sync::atomic::AtomicBool};
1445+
use std::{boxed::Box, sync::Mutex};
14461446

14471447
use bevy_ecs::{
14481448
change_detection::{DetectChanges, ResMut},
@@ -1848,4 +1848,23 @@ mod tests {
18481848
assert_eq!(test_events.len(), 2); // Events are double-buffered, so we see 2 + 0 = 2
18491849
assert_eq!(test_events.iter_current_update_events().count(), 0);
18501850
}
1851+
1852+
#[test]
1853+
fn custom_update_fn_invoked() {
1854+
let invocation_check = &*Box::leak(Box::new(AtomicBool::new(false)));
1855+
1856+
let mut app = App::new();
1857+
1858+
app.set_update_fn(|_sub_apps| {
1859+
invocation_check.fetch_or(true, core::sync::atomic::Ordering::SeqCst);
1860+
});
1861+
1862+
app.update();
1863+
1864+
assert_eq!(
1865+
invocation_check.load(core::sync::atomic::Ordering::SeqCst),
1866+
true,
1867+
"Failed to run the app's custom update function."
1868+
);
1869+
}
18511870
}

crates/bevy_app/src/sub_app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ pub struct SubApps {
496496
/// Other, labeled sub-apps.
497497
pub sub_apps: HashMap<InternedAppLabel, SubApp>,
498498
/// The function called by [`update`](SubApps::update) to update all subapps in the collection.
499-
/// Replacing the update function can be used to customize how and when [SubApp::update] and [SubApp::extract] are called.
499+
/// Replacing the update function can be used to customize how and when [`SubApp::update`] and [`SubApp::extract`] are called.
500500
pub update_fn: Option<UpdateFn>,
501501
}
502502

@@ -543,7 +543,7 @@ impl Default for SubApps {
543543
/// Calls [`update`](SubApp::update) for the main sub-app, and then calls
544544
/// [`extract`](SubApp::extract) and [`update`](SubApp::update) for the rest.
545545
///
546-
/// This serves as the default for [SubApps::update] if none is provided.
546+
/// This serves as the default for [`SubApps::update`] if none is provided.
547547
pub fn update_subapps(sub_apps: &mut SubApps) {
548548
#[cfg(feature = "trace")]
549549
let _bevy_update_span = info_span!("update").entered();

0 commit comments

Comments
 (0)