Skip to content

Commit 3a61256

Browse files
committed
refactor: Bring test harness in line.
1 parent 13d3514 commit 3a61256

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

crates/languages/bevy_mod_scripting_lua/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,14 @@ mod test {
275275
#[test]
276276
fn test_reload_doesnt_overwrite_old_context() {
277277
let lua = Lua::new();
278-
let script_id = ScriptId::from("asd.lua");
278+
let script_id: ScriptId = ScriptId::from(uuid::Uuid::new_v4());
279279
let initializers = vec![];
280280
let pre_handling_initializers = vec![];
281281
let mut old_ctxt = lua.clone();
282+
let handle = Handle::Weak(script_id);
282283

283284
lua_context_load(
284-
&script_id,
285+
&handle,
285286
"function hello_world_from_first_load()
286287
287288
end"
@@ -293,7 +294,7 @@ mod test {
293294
.unwrap();
294295

295296
lua_context_reload(
296-
&script_id,
297+
&handle,
297298
"function hello_world_from_second_load()
298299
299300
end"

crates/testing_crates/script_integration_test_harness/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ publish = false
66

77
[features]
88
default = ["lua", "rhai"]
9-
lua = ["bevy_mod_scripting_lua", "bevy_mod_scripting_functions/lua_bindings"]
9+
lua = ["bevy_mod_scripting_lua", "bevy_mod_scripting_functions/lua_bindings", "bevy_mod_scripting_lua/lua54"]
1010
rhai = ["bevy_mod_scripting_rhai", "bevy_mod_scripting_functions/rhai_bindings"]
1111

1212
[dependencies]
@@ -23,3 +23,4 @@ bevy_mod_scripting_rhai = { path = "../../languages/bevy_mod_scripting_rhai", op
2323
criterion = "0.5"
2424
rand = "0.9"
2525
rand_chacha = "0.9"
26+
uuid = "1.11"

crates/testing_crates/script_integration_test_harness/src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ fn run_test_callback<P: IntoScriptPluginParams, C: IntoCallbackLabel>(
309309
}
310310

311311
let res = handler_ctxt.call::<C>(
312-
&script_id,
312+
&Handle::Weak(*script_id),
313313
Entity::from_raw(0),
314314
vec![],
315315
guard.clone(),
@@ -505,14 +505,15 @@ pub fn run_plugin_script_load_benchmark<
505505
|| {
506506
let mut rng = RNG.lock().unwrap();
507507
let is_reload = rng.random_range(0f32..=1f32) < reload_probability;
508-
let random_id = if is_reload { 0 } else { rng.random::<u64>() };
508+
let random_id = if is_reload { 0 } else { rng.random::<u128>() };
509509

510-
let random_script_id = script_id_generator(random_id);
510+
// let random_script_id = script_id_generator(random_id);
511+
let random_script_id: ScriptId = ScriptId::from(uuid::Builder::from_random_bytes(random_id.to_le_bytes()).into_uuid());
511512
// we manually load the script inside a command
512513
let content = content.to_string().into_boxed_str();
513514
(
514515
CreateOrUpdateScript::<P>::new(
515-
random_script_id,
516+
Handle::Weak(random_script_id),
516517
content.clone().into(),
517518
None,
518519
),

tests/script_tests.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ use std::path::PathBuf;
44

55
use libtest_mimic::{Arguments, Failed, Trial};
66
use script_integration_test_harness::{
7-
execute_lua_integration_test, execute_rhai_integration_test,
7+
execute_lua_integration_test,
8+
#[cfg(feature = "rhai")]
9+
execute_rhai_integration_test,
810
};
911

1012
use test_utils::{discover_all_tests, Test, TestKind};
@@ -20,7 +22,13 @@ impl TestExecutor for Test {
2022

2123
match self.kind {
2224
TestKind::Lua => execute_lua_integration_test(&self.path.to_string_lossy())?,
23-
TestKind::Rhai => execute_rhai_integration_test(&self.path.to_string_lossy())?,
25+
TestKind::Rhai => {
26+
#[cfg(feature = "rhai")]
27+
execute_rhai_integration_test(&self.path.to_string_lossy())?
28+
#[cfg(not(feature = "rhai"))]
29+
panic!("no 'rhai' feature")
30+
},
31+
2432
}
2533

2634
Ok(())

0 commit comments

Comments
 (0)