Skip to content

Commit

Permalink
Fix test_inspect_stack
Browse files Browse the repository at this point in the history
  • Loading branch information
khvzak committed Oct 18, 2024
1 parent 930fd9c commit c638d90
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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(())
Expand Down

0 comments on commit c638d90

Please sign in to comment.