conditional doctests
This commit is contained in:
parent
469e9aca15
commit
db573426da
4 changed files with 64 additions and 13 deletions
|
|
@ -120,7 +120,7 @@ Add the following to your `Cargo.toml`:
|
|||
|
||||
```toml
|
||||
[dependencies]
|
||||
bevy_scriptum = { version = "0.7", features = ["lua"] }
|
||||
bevy_scriptum = { version = "0.8", features = ["lua"] }
|
||||
```
|
||||
|
||||
or execute `cargo add bevy_scriptum --features lua` from your project directory.
|
||||
|
|
|
|||
2
assets/tests/ruby/eval_that_causes_runtime_error.rb
Normal file
2
assets/tests/ruby/eval_that_causes_runtime_error.rb
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
mark_called
|
||||
# puts("foo" + 1)
|
||||
15
src/lib.rs
15
src/lib.rs
|
|
@ -21,8 +21,10 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -42,11 +44,13 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! #[derive(Component)]
|
||||
//! struct Player;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -66,8 +70,10 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -89,9 +95,11 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! struct MyPlugin;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! impl Plugin for MyPlugin {
|
||||
//! fn build(&self, app: &mut App) {
|
||||
//! app.add_scripting_api::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -102,6 +110,7 @@
|
|||
//! }
|
||||
//! }
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|_| {
|
||||
|
|
@ -128,8 +137,10 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -154,8 +165,10 @@
|
|||
//! ```no_run
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
@ -209,8 +222,10 @@
|
|||
//! ```
|
||||
//! use bevy::prelude::*;
|
||||
//! use bevy_scriptum::prelude::*;
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! use bevy_scriptum::runtimes::lua::prelude::*;
|
||||
//!
|
||||
//! # #[cfg(feature = "lua")]
|
||||
//! App::new()
|
||||
//! .add_plugins(DefaultPlugins)
|
||||
//! .add_scripting::<LuaRuntime>(|runtime| {
|
||||
|
|
|
|||
|
|
@ -11,6 +11,24 @@ use bevy_scriptum::{FuncArgs, Runtime, prelude::*};
|
|||
#[cfg(any(feature = "rhai", feature = "lua", feature = "ruby"))]
|
||||
static TRACING_SUBSCRIBER: OnceLock<()> = OnceLock::new();
|
||||
|
||||
#[cfg(any(feature = "rhai", feature = "lua", feature = "ruby"))]
|
||||
#[derive(Default, Resource)]
|
||||
struct TimesCalled {
|
||||
times_called: u8,
|
||||
}
|
||||
|
||||
macro_rules! assert_n_times_called {
|
||||
($app: expr, $count: expr) => {
|
||||
assert_eq!(
|
||||
$app.world()
|
||||
.get_resource::<TimesCalled>()
|
||||
.unwrap()
|
||||
.times_called,
|
||||
$count
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "rhai", feature = "lua", feature = "ruby"))]
|
||||
fn build_test_app() -> App {
|
||||
let mut app = App::new();
|
||||
|
|
@ -224,6 +242,33 @@ macro_rules! scripting_tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn eval_that_casues_runtime_error_doesnt_panic() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
app.add_scripting::<$runtime>(|r| {
|
||||
r.add_function(
|
||||
String::from("mark_called"),
|
||||
|mut times_called: ResMut<TimesCalled>| {
|
||||
times_called.times_called += 1;
|
||||
},
|
||||
);
|
||||
})
|
||||
.init_resource::<TimesCalled>();
|
||||
|
||||
run_script::<$runtime, _, _>(
|
||||
&mut app,
|
||||
format!(
|
||||
"tests/{}/eval_that_causes_runtime_error.{}",
|
||||
$script, $extension
|
||||
)
|
||||
.to_string(),
|
||||
|| {},
|
||||
);
|
||||
|
||||
assert_n_times_called!(app, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn call_script_function_that_casues_runtime_error() {
|
||||
let mut app = build_test_app();
|
||||
|
|
@ -347,11 +392,6 @@ macro_rules! scripting_tests {
|
|||
fn rust_function_gets_called_from_script() {
|
||||
let mut app = build_test_app();
|
||||
|
||||
#[derive(Default, Resource)]
|
||||
struct TimesCalled {
|
||||
times_called: u8,
|
||||
}
|
||||
|
||||
app.world_mut().init_resource::<TimesCalled>();
|
||||
|
||||
app.add_scripting::<$runtime>(|runtime| {
|
||||
|
|
@ -370,13 +410,7 @@ macro_rules! scripting_tests {
|
|||
call_script_on_update_from_rust::<$runtime>,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
app.world()
|
||||
.get_resource::<TimesCalled>()
|
||||
.unwrap()
|
||||
.times_called,
|
||||
1
|
||||
);
|
||||
assert_n_times_called!(app, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
Loading…
Reference in a new issue