Files
moonwell-client-core/crates/benilla-mlua/tests/fork.rs
T
sindoring d1961e79fc Sync upstream through b2473e60 and retain ruRU (#8)
Integrate 182 upstream commits through b2473e60 while retaining MoonWell packaging, branding and the community ruRU pack.

Upstream replaces the C Lua/mlua host with benilla-lua/benilla-mlua and the native glue screens with stock GlueXML. The update also includes the new locale/DBC/name rules, cache and interaction handling, rendering, quest log and chat behavior, including the latest quest completion and timed-quest failure fixes. Fork adaptations use the new APIs: stock Wow.ini locales remain intact, while the ruRU overlay reads column zero and retains its ruRU authentication tag and Lua identity. Russian names keep their twelve-letter policy and Unicode roster matching; fonts, spell costs, race/class labels and translated options retain real-pack regression coverage.

Windows regression fixes keep the locale-default test valid under instrumented window overrides and the shader assertion independent of checkout line endings. The original C Lua 5.1 host, rebuilt from c0630f3d in an isolated directory, reproduces the complete Windows cos-sweep answer byte for byte; cos now uses platform-specific goldens.

Validation on Windows: scripts/gates.sh passed all automatic gates, including real-data and no-install workspace tests, reference tables, documentation, message catalog, render-pass lint, player clippy/tests and engine boots with and without data. MoonWell player clippy also passed with -D warnings. The committed tree exactly matches the full green stamp; five vendored Kira files retain the tested checkout's line endings, with normalized contents unchanged. All three actual ruRU pack regressions passed in both builds. Fifteen test archives were restored read-only from the published client and SHA-256 checked.

Each real-data/player rung skipped 31 tests because the optional addon corpus is absent (24 general, 7 Quiver). Live smoke was not run: no declared probe account; no player-account login or character creation was performed. Linux/macOS changes were not locally built.
2026-10-17 21:10:31 +03:00

122 lines
4.1 KiB
Rust

//! A fork is independent: host closures it copied act on the fork, not on the original.
use benilla_mlua::{Lua, Table};
#[test]
fn a_copied_host_closure_acts_on_its_own_fork() {
let lua = Lua::new();
let store = lua.create_table().unwrap();
store.set("n", 0).unwrap();
let held = store.clone();
let bump = lua
.create_function(move |_, ()| {
let n: i64 = held.get("n")?;
held.set("n", n + 1)
})
.unwrap();
lua.globals().set("bump", bump).unwrap();
lua.globals().set("store", store).unwrap();
lua.load("bump()").exec().unwrap();
let fork = lua.fork();
fork.load("bump() bump()").exec().unwrap();
let n = |l: &Lua| {
l.globals()
.get::<Table>("store")
.unwrap()
.get::<i64>("n")
.unwrap()
};
assert_eq!(n(&lua), 1, "the original is untouched");
assert_eq!(n(&fork), 3, "the fork's own table counted");
lua.load("bump()").exec().unwrap();
assert_eq!((n(&lua), n(&fork)), (2, 3));
}
/// A handle made after the fork names nothing in the fork: reading it from a callback the fork
/// copied is another state's value, mlua's panic, which the fork's `pcall` catches.
#[test]
fn a_handle_made_after_the_fork_is_foreign_to_it() {
use std::cell::RefCell;
use std::rc::Rc;
let lua = Lua::new();
let slot: Rc<RefCell<Option<Table>>> = Default::default();
let held = slot.clone();
let read = lua
.create_function(move |_, ()| {
let t = held.borrow().clone().expect("set before the call");
t.get::<i64>("v")
})
.unwrap();
lua.globals().set("read", read).unwrap();
let fork = lua.fork();
let t = lua.create_table().unwrap();
t.set("v", 7).unwrap();
*slot.borrow_mut() = Some(t);
assert_eq!(lua.load("return read()").eval::<i64>().unwrap(), 7);
let r: String = fork
.load("local ok, e = pcall(read) return tostring(ok) .. ' ' .. tostring(e)")
.eval()
.unwrap();
assert_eq!(
r,
"false Lua instance passed Value created from a different main Lua state"
);
}
/// A string handle is checked as a table handle is: made after the fork, it names nothing in the
/// fork, even where the fork has since rooted a string of its own under the same slot.
#[test]
fn a_string_made_after_the_fork_is_foreign_to_it() {
use benilla_mlua::String as LuaString;
use std::cell::RefCell;
use std::rc::Rc;
let lua = Lua::new();
let slot: Rc<RefCell<Option<LuaString>>> = Default::default();
let held = slot.clone();
let read = lua
.create_function(move |_, ()| {
let s = held.borrow().clone().expect("set before the call");
Ok(s.to_str()?.to_string())
})
.unwrap();
lua.globals().set("read", read).unwrap();
let fork = lua.fork();
let _fork_own = fork.create_string("FORK0").unwrap();
*slot.borrow_mut() = Some(lua.create_string("TEMPLATE").unwrap());
assert_eq!(
lua.load("return read()").eval::<String>().unwrap(),
"TEMPLATE"
);
let r: String = fork
.load("local ok, e = pcall(read) return tostring(ok) .. ' ' .. tostring(e)")
.eval()
.unwrap();
assert_eq!(
r,
"false Lua instance passed Value created from a different main Lua state"
);
}
/// A fork is made between calls: inside a callback the copy would hold frames no one returns
/// from, so it panics, and the panic resumes in Rust as a callback's panic does.
#[test]
fn a_fork_inside_a_callback_panics() {
let lua = Lua::new();
let f = lua
.create_function(|lua, ()| {
let _ = lua.fork();
Ok(())
})
.unwrap();
let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| f.call::<()>(())));
let p = r.unwrap_err();
assert_eq!(
p.downcast_ref::<&str>().copied(),
Some("a state is forked from outside its callbacks")
);
// Between calls it forks.
let copy = lua.fork();
assert_eq!(copy.load("return 1 + 1").eval::<i64>().unwrap(), 2);
}