Skip to content

Commit

Permalink
bevy_mocks crate
Browse files Browse the repository at this point in the history
  • Loading branch information
stepancheg committed Nov 24, 2023
1 parent 1065028 commit 420029b
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 12 deletions.
2 changes: 2 additions & 0 deletions crates/bevy_ecs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ serde = "1"
thiserror = "1.0"

[dev-dependencies]
bevy_mocks = { path = "../bevy_mocks", version = "0.12.0" }

rand = "0.8"

[[example]]
Expand Down
19 changes: 7 additions & 12 deletions crates/bevy_ecs/src/schedule/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,19 +214,14 @@ impl<T> NodeConfigs<T> {
/// # Examples
///
/// ```
/// # use bevy_ecs::schedule::IntoSystemConfigs;
/// # struct AppMock;
/// # struct Update;
/// # impl AppMock {
/// # pub fn add_systems<M>(
/// # &mut self,
/// # schedule: Update,
/// # systems: impl IntoSystemConfigs<M>,
/// # ) -> &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<Input<KeyCode>>) {}
///
/// fn update_camera() {}
/// fn update_character() {}
Expand Down
17 changes: 17 additions & 0 deletions crates/bevy_mocks/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions crates/bevy_mocks/src/app.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub struct App;

impl App {
pub fn add_systems<C, S>(&mut self, _schedule: C, _systems: S) -> &mut Self {
self
}
}
1 change: 1 addition & 0 deletions crates/bevy_mocks/src/app_schedule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Update;
1 change: 1 addition & 0 deletions crates/bevy_mocks/src/input.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Input<T>(T);
3 changes: 3 additions & 0 deletions crates/bevy_mocks/src/keyboard.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub enum KeyCode {
A,
}
8 changes: 8 additions & 0 deletions crates/bevy_mocks/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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;
7 changes: 7 additions & 0 deletions crates/bevy_mocks/src/schedule.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pub trait IntoSystemConfigs: Sized {
fn after<T>(self, _other: T) -> Self {
self
}
}

impl<T> IntoSystemConfigs for T {}
1 change: 1 addition & 0 deletions crates/bevy_mocks/src/system.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub struct Res<T>(T);

0 comments on commit 420029b

Please sign in to comment.