mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Add conformance test for lua_getupvalue() without debug info
This commit is contained in:
parent
85764fc7ea
commit
1db8ef3f97
2 changed files with 41 additions and 0 deletions
|
@ -691,6 +691,34 @@ TEST_CASE("Debugger")
|
|||
CHECK(stephits > 100); // note; this will depend on number of instructions which can vary, so we just make sure the callback gets hit often
|
||||
}
|
||||
|
||||
TEST_CASE("NDebugGetUpValue")
|
||||
{
|
||||
lua_CompileOptions copts = defaultOptions();
|
||||
copts.debugLevel = 0;
|
||||
// Don't optimize away any upvalues
|
||||
copts.optimizationLevel = 0;
|
||||
|
||||
runConformance(
|
||||
"ndebug_upvalues.lua",
|
||||
nullptr,
|
||||
[](lua_State* L) {
|
||||
lua_checkstack(L, LUA_MINSTACK);
|
||||
|
||||
// push the second frame's closure to the stack
|
||||
lua_Debug ar = {};
|
||||
REQUIRE(lua_getinfo(L, 1, "f", &ar));
|
||||
|
||||
// get the first upvalue
|
||||
const char* u = lua_getupvalue(L, -1, 1);
|
||||
REQUIRE(u);
|
||||
// upvalue name is unknown without debug info
|
||||
CHECK(strcmp(u, "") == 0);
|
||||
CHECK(lua_tointeger(L, -1) == 5);
|
||||
lua_pop(L, 2);
|
||||
},
|
||||
nullptr, &copts, /* skipCodegen */ false);
|
||||
}
|
||||
|
||||
TEST_CASE("SameHash")
|
||||
{
|
||||
extern unsigned int luaS_hash(const char* str, size_t len); // internal function, declared in lstring.h - not exposed via lua.h
|
||||
|
|
13
tests/conformance/ndebug_upvalues.lua
Normal file
13
tests/conformance/ndebug_upvalues.lua
Normal file
|
@ -0,0 +1,13 @@
|
|||
-- This file is part of the Luau programming language and is licensed under MIT License; see LICENSE.txt for details
|
||||
-- This tests that the lua_*upval() APIs work correctly even with debug info disabled
|
||||
local foo = 5
|
||||
function clo_test()
|
||||
-- so `foo` gets captured as an upval
|
||||
print(foo)
|
||||
-- yield so we can look at clo_test's upvalues
|
||||
coroutine.yield()
|
||||
end
|
||||
|
||||
clo_test()
|
||||
|
||||
return 'OK'
|
Loading…
Add table
Reference in a new issue