Skip to content

Commit 5b34eea

Browse files
committed
add assertions
1 parent 1c0fd63 commit 5b34eea

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
assert(world.get_type_by_name('UnregisteredType') == (), 'Unregistered type was found')
1+
assert(false);
2+
assert(world.get_type_by_name("UnregisteredType") == (), "Unregistered type was found");

crates/languages/bevy_mod_scripting_rhai/tests/rhai_tests.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
use bevy_mod_scripting_core::AddRuntimeInitializer;
12
use bevy_mod_scripting_rhai::RhaiScriptingPlugin;
23
use libtest_mimic::{Arguments, Failed, Trial};
4+
use rhai::Dynamic;
35
use script_integration_test_harness::execute_integration_test;
46
use std::{
57
fs::{self, DirEntry},
@@ -21,6 +23,28 @@ impl Test {
2123
},
2224
|app| {
2325
app.add_plugins(RhaiScriptingPlugin::default());
26+
app.add_runtime_initializer::<RhaiScriptingPlugin>(|runtime| {
27+
runtime.register_fn("assert", |a: Dynamic, b: &str| {
28+
if !a.is::<bool>() {
29+
panic!("Expected a boolean value, but got {:?}", a);
30+
}
31+
if !a.as_bool().unwrap() {
32+
panic!("Assertion failed. {}", b);
33+
}
34+
});
35+
});
36+
37+
app.add_runtime_initializer::<RhaiScriptingPlugin>(|runtime| {
38+
runtime.register_fn("assert", |a: Dynamic| {
39+
if !a.is::<bool>() {
40+
panic!("Expected a boolean value, but got {:?}", a);
41+
}
42+
if !a.as_bool().unwrap() {
43+
panic!("Assertion failed");
44+
}
45+
});
46+
});
47+
2448
// app.add_context_initializer::<LuaScriptingPlugin>(|_,ctxt: &mut Lua| {
2549
// let globals = ctxt.globals();
2650
// globals.set(

0 commit comments

Comments
 (0)