Files
moonwell-client-core/crates/benilla-lua/tests/unwind.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

73 lines
2.9 KiB
Rust

//! A Rust panic that unwinds out of the VM leaves it as it was when the host called in.
fn boom(_: &mut benilla_lua::Vm, _: usize) -> Result<usize, benilla_lua::LuaError> {
panic!("a native broke")
}
#[test]
fn a_panic_through_the_vm_leaves_it_usable() {
let mut vm = benilla_lua::new_state();
vm.register("boom", boom);
vm.exec(
b"function deep(n) if n == 0 then return boom() end return deep(n - 1) + 1 end",
b"=t",
)
.unwrap();
for _ in 0..300 {
let r = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
let _ = vm.exec(b"local t = setmetatable({}, {__index = function() return deep(20) end}) return t.x", b"=t");
}));
assert!(r.is_err());
}
// No frame, depth or handler leaked: a chunk still compiles and deep calls still run.
let r = vm
.exec(b"local function f(n) if n == 0 then return 0 end return 1 + f(n - 1) end return f(4000)", b"=t")
.unwrap();
assert_eq!(vm.display(r[0]), "4000");
let caught = vm.exec(b"return pcall(error, 'x')", b"=t").unwrap();
assert_eq!(vm.display(caught[0]), "false");
}
/// A panic that passes a protected call leaves its handler behind no more: a native that
/// catches the panic and raises runs no handler of a call that already ended.
#[test]
fn a_panic_through_xpcall_leaves_no_stale_handler() {
fn boom(_: &mut benilla_lua::Vm, _: usize) -> Result<usize, benilla_lua::LuaError> {
panic!("boom");
}
fn catcher(vm: &mut benilla_lua::Vm, nargs: usize) -> Result<usize, benilla_lua::LuaError> {
let f = vm.arg(nargs, 0);
let r =
std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| vm.pcall_value(f, &[], 0)));
assert!(r.is_err(), "the panic reached the catcher");
Err(vm.rt_error("after"))
}
let mut vm = benilla_lua::new_state();
vm.register("boom", boom);
vm.register("catcher", catcher);
let r = vm
.exec(
b"local ok, e = pcall(catcher, function() xpcall(boom, function(m) Hit = true return m end) end) \
return ok, e, Hit == nil",
b"=t",
)
.unwrap();
let got: Vec<String> = r.into_iter().map(|v| vm.display(v)).collect();
assert_eq!(got, ["false", "after", "true"]);
}
/// A type error the host's own call or index raises, with no Lua frame running, names no
/// variable, a register given or not: there is no function whose register it could be.
#[test]
fn a_type_error_with_no_frame_running_names_no_variable() {
use benilla_lua::value::Value;
let mut vm = benilla_lua::new_state();
let e = vm.pcall_value(Value::Bool(true), &[], 0).unwrap_err();
assert_eq!(vm.display(e), "attempt to call a boolean value");
let key = Value::Str(vm.heap.intern(b"x"));
for reg in [None, Some(0)] {
let e = vm.index(Value::Bool(true), key, reg).unwrap_err().value;
assert_eq!(vm.display(e), "attempt to index a boolean value");
}
}