mirror of
https://github.com/bevyengine/bevy
synced 2024-11-10 07:04:33 +00:00
Forward exit codes in default app runner (#13674)
# Objective The default app runner fabricates exit codes loosing useful info in the process. ## Solution - Make run_once extract the correct exit code from app. - Add a test to confirm it works. ## Testing - Run the `runner_returns_correct_exit_code` test. - Rejoice when it succeeds.
This commit is contained in:
parent
16207e4043
commit
1fdddf8992
1 changed files with 18 additions and 13 deletions
|
@ -842,17 +842,7 @@ fn run_once(mut app: App) -> AppExit {
|
|||
|
||||
app.update();
|
||||
|
||||
let mut exit_code_reader = ManualEventReader::default();
|
||||
if let Some(app_exit_events) = app.world().get_resource::<Events<AppExit>>() {
|
||||
if exit_code_reader
|
||||
.read(app_exit_events)
|
||||
.any(AppExit::is_error)
|
||||
{
|
||||
return AppExit::error();
|
||||
}
|
||||
}
|
||||
|
||||
AppExit::Success
|
||||
app.should_exit().unwrap_or(AppExit::Success)
|
||||
}
|
||||
|
||||
/// An event that indicates the [`App`] should exit. If one or more of these are present at the end of an update,
|
||||
|
@ -928,9 +918,9 @@ impl Termination for AppExit {
|
|||
mod tests {
|
||||
use std::{marker::PhantomData, mem};
|
||||
|
||||
use bevy_ecs::{schedule::ScheduleLabel, system::Commands};
|
||||
use bevy_ecs::{event::EventWriter, schedule::ScheduleLabel, system::Commands};
|
||||
|
||||
use crate::{App, AppExit, Plugin};
|
||||
use crate::{App, AppExit, Plugin, Update};
|
||||
|
||||
struct PluginA;
|
||||
impl Plugin for PluginA {
|
||||
|
@ -1133,6 +1123,21 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn runner_returns_correct_exit_code() {
|
||||
fn raise_exits(mut exits: EventWriter<AppExit>) {
|
||||
// Exit codes chosen by a fair dice roll.
|
||||
// Unlikely to overlap with default values.
|
||||
exits.send(AppExit::Success);
|
||||
exits.send(AppExit::from_code(4));
|
||||
exits.send(AppExit::from_code(73));
|
||||
}
|
||||
|
||||
let exit = App::new().add_systems(Update, raise_exits).run();
|
||||
|
||||
assert_eq!(exit, AppExit::from_code(4));
|
||||
}
|
||||
|
||||
/// Custom runners should be in charge of when `app::update` gets called as they may need to
|
||||
/// coordinate some state.
|
||||
/// bug: <https://github.com/bevyengine/bevy/issues/10385>
|
||||
|
|
Loading…
Reference in a new issue