Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bevy_mocks crate #10726

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
Loading