Skip to content

Commit 1c0fd63

Browse files
committed
setup rhai tests
1 parent 25c3bc7 commit 1c0fd63

File tree

5 files changed

+68
-60
lines changed

5 files changed

+68
-60
lines changed

crates/languages/bevy_mod_scripting_lua/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ smol_str = "0.2.2"
4747
smallvec = "1.13"
4848

4949
[dev-dependencies]
50-
# test_utils = { workspace = true }
5150
script_integration_test_harness = { workspace = true }
5251
bevy_mod_scripting_functions = { workspace = true, features = [
5352
"core_functions",

crates/languages/bevy_mod_scripting_rhai/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@ bevy_mod_scripting_functions = { workspace = true, features = [
2323
], default-features = false }
2424

2525
[dev-dependencies]
26+
script_integration_test_harness = { workspace = true }
2627
bevy_mod_scripting_functions = { workspace = true, features = [
28+
"core_functions",
29+
"bevy_bindings",
2730
"test_functions",
2831
] }
29-
test_utils = { workspace = true }
3032
libtest-mimic = "0.8"
3133
regex = "1.11"
3234

Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert(world.get_type_by_name('UnregisteredType') == (), 'Unregistered type was found')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
local type = world.get_type_by_name('TestComponent')
2+
3+
local expected = {
4+
type_name = 'test_utils::test_data::TestComponent',
5+
short_name = 'TestComponent',
6+
}
7+
8+
local received = {
9+
type_name = type:type_name(),
10+
short_name = type:short_name(),
11+
}
12+
13+
assert(type != (), 'Type not found')
14+
assert(received.type_name == expected.type_name, 'type_name mismatch, expected: ' .. expected.type_name .. ', got: ' .. received.type_name)
15+
assert(received.short_name == expected.short_name, 'short_name mismatch, expected: ' .. expected.short_name .. ', got: ' .. received.short_name)

crates/languages/bevy_mod_scripting_rhai/tests/rhai_tests.rs

Lines changed: 49 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,11 @@
1-
// use bevy::app::App;
2-
// use bevy_mod_scripting_functions::ScriptFunctionsPlugin;
3-
// use bevy_mod_scripting_rhai::RhaiScriptingPlugin;
1+
use bevy_mod_scripting_rhai::RhaiScriptingPlugin;
42
use libtest_mimic::{Arguments, Failed, Trial};
3+
use script_integration_test_harness::execute_integration_test;
54
use std::{
65
fs::{self, DirEntry},
76
io, panic,
87
path::{Path, PathBuf},
98
};
10-
// use test_utils::test_data::setup_integration_test;
11-
12-
// Initializes world for tests
13-
// fn init_app() -> App {
14-
// let mut app = setup_integration_test(|_, _| {});
15-
16-
// app.add_plugins(RhaiScriptingPlugin::default())
17-
// .add_plugins(ScriptFunctionsPlugin);
18-
19-
// app.finish();
20-
// app.cleanup();
21-
22-
// app
23-
// }
249

2510
struct Test {
2611
code: String,
@@ -29,51 +14,57 @@ struct Test {
2914

3015
impl Test {
3116
fn execute(self) -> Result<(), Failed> {
32-
println!("Running test: {}", self.name());
33-
println!("Code: {}", self.code);
34-
// let lua = Lua::new();
35-
// set file information
36-
// let mut app = init_app();
37-
// app.add_systems(schedule, systems);
38-
39-
// let mut lua = lua_context_load(
40-
// &(self.name()).into(),
41-
// self.code.as_bytes(),
42-
// &context_settings.context_initializers,
43-
// &context_settings.context_pre_handling_initializers,
44-
// app.world_mut(),
45-
// &mut (),
46-
// )
47-
// .map_err(|e| {
48-
// let world = app.world_mut();
49-
// let world = WorldAccessGuard::new(world);
50-
// let msg = e.display_with_world(Arc::new(world));
51-
// Failed::from(msg)
52-
// })?;
53-
54-
// lua_handler(
55-
// vec![ScriptValue::Unit],
56-
// Entity::from_raw(1),
57-
// &(self.name()).into(),
58-
// &CallbackLabel::new("on_test").ok_or("invalid callback label")?,
59-
// &mut lua,
60-
// &context_settings.context_pre_handling_initializers,
61-
// &mut (),
62-
// app.world_mut(),
63-
// )
64-
// .map_err(|e| {
65-
// let world = app.world_mut();
66-
// let world = WorldAccessGuard::new(world);
67-
// let msg = e.display_with_world(Arc::new(world));
68-
// Failed::from(msg)
69-
// })?;
70-
71-
Ok(())
17+
execute_integration_test::<RhaiScriptingPlugin, _, _>(
18+
|world, type_registry| {
19+
let _ = world;
20+
let _ = type_registry;
21+
},
22+
|app| {
23+
app.add_plugins(RhaiScriptingPlugin::default());
24+
// app.add_context_initializer::<LuaScriptingPlugin>(|_,ctxt: &mut Lua| {
25+
// let globals = ctxt.globals();
26+
// globals.set(
27+
// "assert_throws",
28+
// ctxt.create_function(|lua, (f, reg): (Function, String)| {
29+
// let world = lua.get_world();
30+
// let result = f.call::<()>(MultiValue::new());
31+
// let err = match result {
32+
// Ok(_) => {
33+
// return Err(mlua::Error::external(
34+
// "Expected function to throw error, but it did not.",
35+
// ))
36+
// }
37+
// Err(e) =>
38+
// ScriptError::from_mlua_error(e).display_with_world(world)
39+
// ,
40+
// };
41+
42+
// let regex = regex::Regex::new(&reg).unwrap();
43+
// if regex.is_match(&err) {
44+
// Ok(())
45+
// } else {
46+
// Err(mlua::Error::external(
47+
// format!(
48+
// "Expected error message to match the regex: \n{}\n\nBut got:\n{}",
49+
// regex.as_str(),
50+
// err
51+
// ),
52+
// ))
53+
// }
54+
// })?,
55+
// )?;
56+
// Ok(())
57+
// });
58+
},
59+
self.path.as_os_str().to_str().unwrap(),
60+
self.code.as_bytes(),
61+
)
62+
.map_err(Failed::from)
7263
}
7364

7465
fn name(&self) -> String {
7566
format!(
76-
"lua_test - {}",
67+
"script_test - lua - {}",
7768
self.path
7869
.to_string_lossy()
7970
.split(&format!("tests{}data", std::path::MAIN_SEPARATOR))

0 commit comments

Comments
 (0)