Enhance debug tests, fix debug lib off-by-one erros.

This commit is contained in:
James Roseborough
2009-03-25 14:43:24 +00:00
parent 643af145d3
commit 4bdd4a6ea2
5 changed files with 83 additions and 16 deletions

View File

@@ -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");
}

View File

@@ -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");

View File

@@ -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") )
--]]