From 420029b6d1cdee55445250fcfb2983bd9da41df6 Mon Sep 17 00:00:00 2001 From: Stepan Koltsov Date: Fri, 24 Nov 2023 18:31:36 +0000 Subject: [PATCH] bevy_mocks crate --- crates/bevy_ecs/Cargo.toml | 2 ++ crates/bevy_ecs/src/schedule/config.rs | 19 +++++++------------ crates/bevy_mocks/Cargo.toml | 17 +++++++++++++++++ crates/bevy_mocks/src/app.rs | 7 +++++++ crates/bevy_mocks/src/app_schedule.rs | 1 + crates/bevy_mocks/src/input.rs | 1 + crates/bevy_mocks/src/keyboard.rs | 3 +++ crates/bevy_mocks/src/lib.rs | 8 ++++++++ crates/bevy_mocks/src/schedule.rs | 7 +++++++ crates/bevy_mocks/src/system.rs | 1 + 10 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 crates/bevy_mocks/Cargo.toml create mode 100644 crates/bevy_mocks/src/app.rs create mode 100644 crates/bevy_mocks/src/app_schedule.rs create mode 100644 crates/bevy_mocks/src/input.rs create mode 100644 crates/bevy_mocks/src/keyboard.rs create mode 100644 crates/bevy_mocks/src/lib.rs create mode 100644 crates/bevy_mocks/src/schedule.rs create mode 100644 crates/bevy_mocks/src/system.rs diff --git a/crates/bevy_ecs/Cargo.toml b/crates/bevy_ecs/Cargo.toml index 3231e7b4101ff..bd82f9aa9fe11 100644 --- a/crates/bevy_ecs/Cargo.toml +++ b/crates/bevy_ecs/Cargo.toml @@ -31,6 +31,8 @@ serde = "1" thiserror = "1.0" [dev-dependencies] +bevy_mocks = { path = "../bevy_mocks", version = "0.12.0" } + rand = "0.8" [[example]] diff --git a/crates/bevy_ecs/src/schedule/config.rs b/crates/bevy_ecs/src/schedule/config.rs index 3ce86039ad0f8..19f5faf129a3b 100644 --- a/crates/bevy_ecs/src/schedule/config.rs +++ b/crates/bevy_ecs/src/schedule/config.rs @@ -214,19 +214,14 @@ impl NodeConfigs { /// # Examples /// /// ``` -/// # use bevy_ecs::schedule::IntoSystemConfigs; -/// # struct AppMock; -/// # struct Update; -/// # impl AppMock { -/// # pub fn add_systems( -/// # &mut self, -/// # schedule: Update, -/// # systems: impl IntoSystemConfigs, -/// # ) -> &mut Self { self } -/// # } -/// # let mut app = AppMock; +/// # use bevy_mocks::app_schedule::Update; +/// # use bevy_mocks::input::Input; +/// # use bevy_mocks::keyboard::KeyCode; +/// # use bevy_mocks::schedule::IntoSystemConfigs; +/// # use bevy_mocks::system::Res; +/// # let mut app = bevy_mocks::app::App; /// -/// fn handle_input() {} +/// fn handle_input(keys: Res>) {} /// /// fn update_camera() {} /// fn update_character() {} diff --git a/crates/bevy_mocks/Cargo.toml b/crates/bevy_mocks/Cargo.toml new file mode 100644 index 0000000000000..9121847fd61a1 --- /dev/null +++ b/crates/bevy_mocks/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "bevy_mocks" +version = "0.12.0" +edition = "2021" +description = "API mocks for Bevy for doctests" +homepage = "https://bevyengine.org" +repository = "https://github.com/bevyengine/bevy" +license = "MIT OR Apache-2.0" +keywords = ["bevy"] + +[dependencies] +# We could add dependency crates like `bevy_ecs` here, it works locally, but according to this, +# such crates cannot be published: +# https://github.com/rust-lang/cargo/issues/4242 + +[lints] +workspace = true diff --git a/crates/bevy_mocks/src/app.rs b/crates/bevy_mocks/src/app.rs new file mode 100644 index 0000000000000..3505bba8f54be --- /dev/null +++ b/crates/bevy_mocks/src/app.rs @@ -0,0 +1,7 @@ +pub struct App; + +impl App { + pub fn add_systems(&mut self, _schedule: C, _systems: S) -> &mut Self { + self + } +} diff --git a/crates/bevy_mocks/src/app_schedule.rs b/crates/bevy_mocks/src/app_schedule.rs new file mode 100644 index 0000000000000..01be2275bf19a --- /dev/null +++ b/crates/bevy_mocks/src/app_schedule.rs @@ -0,0 +1 @@ +pub struct Update; diff --git a/crates/bevy_mocks/src/input.rs b/crates/bevy_mocks/src/input.rs new file mode 100644 index 0000000000000..14e8622122f44 --- /dev/null +++ b/crates/bevy_mocks/src/input.rs @@ -0,0 +1 @@ +pub struct Input(T); diff --git a/crates/bevy_mocks/src/keyboard.rs b/crates/bevy_mocks/src/keyboard.rs new file mode 100644 index 0000000000000..b3fd47159febd --- /dev/null +++ b/crates/bevy_mocks/src/keyboard.rs @@ -0,0 +1,3 @@ +pub enum KeyCode { + A, +} diff --git a/crates/bevy_mocks/src/lib.rs b/crates/bevy_mocks/src/lib.rs new file mode 100644 index 0000000000000..cc6395ae1074b --- /dev/null +++ b/crates/bevy_mocks/src/lib.rs @@ -0,0 +1,8 @@ +//! API mocks for Bevy compile-only doctests as illustrations. + +pub mod app; +pub mod app_schedule; +pub mod input; +pub mod keyboard; +pub mod schedule; +pub mod system; diff --git a/crates/bevy_mocks/src/schedule.rs b/crates/bevy_mocks/src/schedule.rs new file mode 100644 index 0000000000000..d708e326a4f45 --- /dev/null +++ b/crates/bevy_mocks/src/schedule.rs @@ -0,0 +1,7 @@ +pub trait IntoSystemConfigs: Sized { + fn after(self, _other: T) -> Self { + self + } +} + +impl IntoSystemConfigs for T {} diff --git a/crates/bevy_mocks/src/system.rs b/crates/bevy_mocks/src/system.rs new file mode 100644 index 0000000000000..8377fea00dbe6 --- /dev/null +++ b/crates/bevy_mocks/src/system.rs @@ -0,0 +1 @@ +pub struct Res(T);