Enhance debug tests, fix debug lib off-by-one erros.
This commit is contained in:
@@ -76,6 +76,10 @@ public class CompatibiltyTest extends ScriptDrivenTest {
|
||||
runTest("compare");
|
||||
}
|
||||
|
||||
public void testDebugLib() throws IOException, InterruptedException {
|
||||
runTest("debuglib");
|
||||
}
|
||||
|
||||
public void testErrors() throws IOException, InterruptedException {
|
||||
runTest("errors");
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import junit.framework.TestCase;
|
||||
|
||||
import org.luaj.compiler.LuaC;
|
||||
import org.luaj.lib.BaseLib;
|
||||
import org.luaj.lib.DebugLib;
|
||||
import org.luaj.platform.J2sePlatform;
|
||||
|
||||
abstract
|
||||
@@ -35,6 +36,9 @@ public class ScriptDrivenTest extends TestCase {
|
||||
// install the compiler
|
||||
LuaC.install();
|
||||
|
||||
// install debug lib
|
||||
DebugLib.install( state );
|
||||
|
||||
// load the file
|
||||
LPrototype p = loadScript(state, testName);
|
||||
p.source = LString.valueOf("stdin");
|
||||
|
||||
@@ -1,7 +1,54 @@
|
||||
|
||||
local print = print
|
||||
local print,tostring,_G = print,tostring,_G
|
||||
local e,f,g,h,s
|
||||
print( 'has debug', debug~=nil )
|
||||
|
||||
-- debug.getfenv, debug.setfenv
|
||||
print( '----- debug.getfenv, debug.setfenv' )
|
||||
f = function(a)
|
||||
return 'f:'..tostring(a)..'|'..tostring(b)
|
||||
end
|
||||
s,e,g = pcall( debug.getfenv, f )
|
||||
print( s, type(e), type(g), (e==G), pcall( f, 'abc' ) )
|
||||
s,e,g = pcall( debug.setfenv, f, {b='def'} )
|
||||
print( s, type(e), type(g), (e==G), pcall( f, 'abc' ) )
|
||||
s,e,g = pcall( debug.getfenv, f )
|
||||
print( s, type(e), type(g), (e==G), pcall( f, 'abc' ) )
|
||||
|
||||
|
||||
print( '----- debug.getlocal, debug.setlocal' )
|
||||
h = function(v,i,n)
|
||||
s = 'h-'..v..'-'..i
|
||||
local x = debug.getlocal(v,i)
|
||||
local y = debug.setlocal(v,i,n)
|
||||
return s..' -> '..v..'-'..i..' '..
|
||||
'old='..tostring(x)..'('..tostring(y)..')'..' '..
|
||||
'new='..tostring(n)
|
||||
end
|
||||
g = function(...)
|
||||
local p,q,r=7,8,9
|
||||
local t = h(...)
|
||||
local b = table.concat({...},',')
|
||||
return t..'\tg locals='..p..','..q..','..r..' tbl={'..b..'}'
|
||||
end
|
||||
f = function(a,b,c)
|
||||
local d,e,f = 4,5,6
|
||||
local t = g(a,b,c)
|
||||
return t..'\tf locals='..','..a..','..b..','..c..','..d..','..e..','..f
|
||||
end
|
||||
for lvl=1,3 do
|
||||
for lcl=0,7 do
|
||||
print( pcall( f, lvl, lcl, '#' ) )
|
||||
end
|
||||
end
|
||||
|
||||
--[[
|
||||
local f = function(a)
|
||||
return 'f:'..tostring(a)..'|'..tostring(b)
|
||||
end
|
||||
local s,e
|
||||
|
||||
|
||||
local printinfo = function(...)
|
||||
for i,a in ipairs(arg) do
|
||||
if type(a) == 'table' then
|
||||
@@ -38,3 +85,4 @@ print( 'e,f,g', e, type(f), type(g) )
|
||||
printinfo( 'debug.getinfo(f,"Sl")', pcall(debug.getinfo, f, "Sl") )
|
||||
printinfo( 'debug.getinfo(g,"Sl")', pcall(debug.getinfo, g, "Sl") )
|
||||
printinfo( 'debug.getinfo(test,"Sl")', pcall(debug.getinfo, test, "Sl") )
|
||||
--]]
|
||||
Reference in New Issue
Block a user