@@ -157,7 +157,7 @@ impl App {
157
157
self . sub_apps . update ( ) ;
158
158
}
159
159
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.
161
161
pub fn set_update_fn ( & mut self , func : impl Fn ( & mut SubApps ) + ' static ) {
162
162
self . sub_apps . update_fn = Some ( Box :: new ( func) ) ;
163
163
}
@@ -1441,8 +1441,8 @@ impl Termination for AppExit {
1441
1441
1442
1442
#[ cfg( test) ]
1443
1443
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 } ;
1446
1446
1447
1447
use bevy_ecs:: {
1448
1448
change_detection:: { DetectChanges , ResMut } ,
@@ -1848,4 +1848,23 @@ mod tests {
1848
1848
assert_eq ! ( test_events. len( ) , 2 ) ; // Events are double-buffered, so we see 2 + 0 = 2
1849
1849
assert_eq ! ( test_events. iter_current_update_events( ) . count( ) , 0 ) ;
1850
1850
}
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
+ }
1851
1870
}
0 commit comments