From c638d90b02632eb029e5b8ffcb70907e951202bb Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Sat, 19 Oct 2024 00:11:05 +0100 Subject: [PATCH] Fix test_inspect_stack --- tests/tests.rs | 47 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/tests/tests.rs b/tests/tests.rs index 4e4d161b..65335845 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1132,13 +1132,6 @@ fn test_inspect_stack() -> Result<()> { })?; lua.globals().set("logline", logline)?; - let stack_info = lua.create_function(|lua, ()| { - let debug = lua.inspect_stack(1).unwrap(); // caller - let stack_info = debug.stack(); - Ok(format!("{stack_info:?}")) - })?; - lua.globals().set("stack_info", stack_info)?; - lua.load( r#" local function foo() @@ -1148,21 +1141,45 @@ fn test_inspect_stack() -> Result<()> { local function bar() return foo() end + + assert(foo() == '[string "chunk"]:3 hello') + assert(bar() == '[string "chunk"]:3 hello') + assert(logline("world") == '[string "chunk"]:12 world') + "#, + ) + .set_name("chunk") + .exec()?; + + let stack_info = lua.create_function(|lua, ()| { + let debug = lua.inspect_stack(1).unwrap(); // caller + let stack_info = debug.stack(); + Ok(format!("{stack_info:?}")) + })?; + lua.globals().set("stack_info", stack_info)?; + + #[cfg(any(feature = "lua54", feature = "lua53", feature = "lua52", feature = "luau"))] + lua.load( + r#" local stack_info = stack_info local function baz(a, b, c, ...) return stack_info() end + assert(baz() == 'DebugStack { num_ups: 1, num_params: 3, is_vararg: true }') + "#, + ) + .exec()?; - assert(foo() == '[string "chunk"]:3 hello') - assert(bar() == '[string "chunk"]:3 hello') - assert(logline("world") == '[string "chunk"]:16 world') - assert( - baz() == 'DebugStack { num_ups: 1, num_params: 3, is_vararg: true }' or - baz() == 'DebugStack { num_ups: 1 }' - ) + // LuaJIT does not pass this test for some reason + #[cfg(feature = "lua51")] + lua.load( + r#" + local stack_info = stack_info + local function baz(a, b, c, ...) + return stack_info() + end + assert(baz() == 'DebugStack { num_ups: 1 }') "#, ) - .set_name("chunk") .exec()?; Ok(())