Simplify layout of lua test script locations.
This commit is contained in:
@@ -715,4 +715,31 @@ public class LuaTable extends LuaValue {
|
|||||||
LuaValue valmt = val.getmetatable();
|
LuaValue valmt = val.getmetatable();
|
||||||
return valmt!=null && LuaValue.eqmtcall(this, m_metatable, val, valmt);
|
return valmt!=null && LuaValue.eqmtcall(this, m_metatable, val, valmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Unpack all the elements of this table */
|
||||||
|
public Varargs unpack() {
|
||||||
|
return unpack(1, this.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unpack all the elements of this table from element i */
|
||||||
|
public Varargs unpack(int i) {
|
||||||
|
return unpack(i, this.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Unpack the elements from i to j inclusive */
|
||||||
|
public Varargs unpack(int i, int j) {
|
||||||
|
int n = j + 1 - i;
|
||||||
|
switch (n) {
|
||||||
|
case 0: return NONE;
|
||||||
|
case 1: return get(i);
|
||||||
|
case 2: return varargsOf(get(i), get(i+1));
|
||||||
|
default:
|
||||||
|
if (n < 0)
|
||||||
|
return NONE;
|
||||||
|
LuaValue[] v = new LuaValue[n];
|
||||||
|
while (--n >= 0)
|
||||||
|
v[n] = get(i+n);
|
||||||
|
return varargsOf(v);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,19 +119,12 @@ public class TableLib extends OneArgFunction {
|
|||||||
}
|
}
|
||||||
case 6: // "unpack", // (list [,i [,j]]) -> result1, ...
|
case 6: // "unpack", // (list [,i [,j]]) -> result1, ...
|
||||||
{
|
{
|
||||||
int na = args.narg();
|
|
||||||
LuaTable t = args.checktable(1);
|
LuaTable t = args.checktable(1);
|
||||||
int n = t.length();
|
switch (args.narg()) {
|
||||||
int i = na>=2? args.checkint(2): 1;
|
case 1: return t.unpack();
|
||||||
int j = na>=3? args.checkint(3): n;
|
case 2: return t.unpack(args.checkint(2));
|
||||||
n = j-i+1;
|
default: return t.unpack(args.checkint(2), args.checkint(3));
|
||||||
if ( n<0 ) return NONE;
|
}
|
||||||
if ( n==1 ) return t.get(i);
|
|
||||||
if ( n==2 ) return varargsOf(t.get(i),t.get(j));
|
|
||||||
LuaValue[] v = new LuaValue[n];
|
|
||||||
for ( int k=0; k<n; k++ )
|
|
||||||
v[k] = t.get(i+k);
|
|
||||||
return varargsOf(v);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return NONE;
|
return NONE;
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ public class lua {
|
|||||||
} else {
|
} else {
|
||||||
System.out.println( "Not a LuaClosure: "+c);
|
System.out.println( "Not a LuaClosure: "+c);
|
||||||
}
|
}
|
||||||
|
Print.print(((LuaClosure)c).p);
|
||||||
} finally {
|
} finally {
|
||||||
script.close();
|
script.close();
|
||||||
}
|
}
|
||||||
@@ -219,8 +220,7 @@ public class lua {
|
|||||||
LuaTable arg = LuaValue.tableOf();
|
LuaTable arg = LuaValue.tableOf();
|
||||||
for ( int j=0; j<args.length; j++ )
|
for ( int j=0; j<args.length; j++ )
|
||||||
arg.set( j-i, LuaValue.valueOf(args[j]) );
|
arg.set( j-i, LuaValue.valueOf(args[j]) );
|
||||||
_G.set( "arg", arg );
|
return arg.unpack();
|
||||||
return _G.get("unpack").invoke(arg);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void interactiveMode( ) throws IOException {
|
private static void interactiveMode( ) throws IOException {
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ import org.luaj.vm2.lib.VarArgFunction;
|
|||||||
* _G.load(new BaseLib());
|
* _G.load(new BaseLib());
|
||||||
* _G.load(new PackageLib());
|
* _G.load(new PackageLib());
|
||||||
* _G.load(new LuajavaLib());
|
* _G.load(new LuajavaLib());
|
||||||
* _G.get("loadstring").call( LuaValue.valueOf(
|
* _G.get("load").call( LuaValue.valueOf(
|
||||||
* "sys = luajava.bindClass('java.lang.System')\n"+
|
* "sys = luajava.bindClass('java.lang.System')\n"+
|
||||||
* "print ( sys:currentTimeMillis() )\n" ) ).call();
|
* "print ( sys:currentTimeMillis() )\n" ) ).call();
|
||||||
* } </pre>
|
* } </pre>
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ abstract public class AbstractUnitTests extends TestCase {
|
|||||||
private final String jar;
|
private final String jar;
|
||||||
private LuaTable _G;
|
private LuaTable _G;
|
||||||
|
|
||||||
public AbstractUnitTests(String zipfile, String dir) {
|
public AbstractUnitTests(String zipdir, String zipfile, String dir) {
|
||||||
URL zip = null;
|
URL zip = null;
|
||||||
zip = getClass().getResource(zipfile);
|
zip = getClass().getResource(zipfile);
|
||||||
if ( zip == null ) {
|
if ( zip == null ) {
|
||||||
File file = new File("test/junit/org/luaj/vm2/compiler/"+zipfile);
|
File file = new File(zipdir+"/"+zipfile);
|
||||||
try {
|
try {
|
||||||
if ( file.exists() )
|
if ( file.exists() )
|
||||||
zip = file.toURI().toURL();
|
zip = file.toURI().toURL();
|
||||||
@@ -71,7 +71,7 @@ abstract public class AbstractUnitTests extends TestCase {
|
|||||||
String actual = protoToString(p);
|
String actual = protoToString(p);
|
||||||
|
|
||||||
// load expected value from jar
|
// load expected value from jar
|
||||||
byte[] luac = bytesFromJar(path + "c");
|
byte[] luac = bytesFromJar(path.substring(0, path.length()-4)+".lc");
|
||||||
Prototype e = loadFromBytes(luac, file);
|
Prototype e = loadFromBytes(luac, file);
|
||||||
String expected = protoToString(e);
|
String expected = protoToString(e);
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ package org.luaj.vm2.compiler;
|
|||||||
public class CompilerUnitTests extends AbstractUnitTests {
|
public class CompilerUnitTests extends AbstractUnitTests {
|
||||||
|
|
||||||
public CompilerUnitTests() {
|
public CompilerUnitTests() {
|
||||||
super("lua5.2.1-tests.zip", "lua5.2.1-tests");
|
super("test/lua", "luaj3.0-tests.zip", "lua5.2.1-tests");
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAll() { doTest("all.lua"); }
|
public void testAll() { doTest("all.lua"); }
|
||||||
|
|||||||
@@ -17,8 +17,7 @@ package org.luaj.vm2.compiler;
|
|||||||
public class RegressionTests extends AbstractUnitTests {
|
public class RegressionTests extends AbstractUnitTests {
|
||||||
|
|
||||||
public RegressionTests() {
|
public RegressionTests() {
|
||||||
super( "regressions.zip",
|
super( "test/lua", "luaj3.0-tests.zip", "regressions" );
|
||||||
"regressions" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testModulo() { doTest("modulo.lua"); }
|
public void testModulo() { doTest("modulo.lua"); }
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
@@ -196,7 +196,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
|||||||
public void testExceptionMessage() {
|
public void testExceptionMessage() {
|
||||||
String script = "local c = luajava.bindClass( \""+SomeClass.class.getName()+"\" )\n" +
|
String script = "local c = luajava.bindClass( \""+SomeClass.class.getName()+"\" )\n" +
|
||||||
"return pcall( c.someMethod, c )";
|
"return pcall( c.someMethod, c )";
|
||||||
Varargs vresult = _G.get("loadstring").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
|
Varargs vresult = _G.get("load").call(LuaValue.valueOf(script)).invoke(LuaValue.NONE);
|
||||||
LuaValue status = vresult.arg1();
|
LuaValue status = vresult.arg1();
|
||||||
LuaValue message = vresult.arg(2);
|
LuaValue message = vresult.arg(2);
|
||||||
assertEquals( LuaValue.FALSE, status );
|
assertEquals( LuaValue.FALSE, status );
|
||||||
@@ -206,7 +206,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
|||||||
|
|
||||||
public void testLuaErrorCause() {
|
public void testLuaErrorCause() {
|
||||||
String script = "luajava.bindClass( \""+SomeClass.class.getName()+"\"):someMethod()";
|
String script = "luajava.bindClass( \""+SomeClass.class.getName()+"\"):someMethod()";
|
||||||
LuaValue chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
|
LuaValue chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||||
try {
|
try {
|
||||||
chunk.invoke(LuaValue.NONE);
|
chunk.invoke(LuaValue.NONE);
|
||||||
fail( "call should not have succeeded" );
|
fail( "call should not have succeeded" );
|
||||||
@@ -235,7 +235,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
|||||||
" ) or '-nil')\n" +
|
" ) or '-nil')\n" +
|
||||||
" end,\n" +
|
" end,\n" +
|
||||||
"} )\n";
|
"} )\n";
|
||||||
Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
|
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||||
if ( ! chunk.arg1().toboolean() )
|
if ( ! chunk.arg1().toboolean() )
|
||||||
fail( chunk.arg(2).toString() );
|
fail( chunk.arg(2).toString() );
|
||||||
LuaValue result = chunk.arg1().call();
|
LuaValue result = chunk.arg1().call();
|
||||||
@@ -260,7 +260,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
|||||||
//"print(bigNumB:toString())\n" +
|
//"print(bigNumB:toString())\n" +
|
||||||
//"print(bigNumC:toString())\n" +
|
//"print(bigNumC:toString())\n" +
|
||||||
"return bigNumA:toString(), bigNumB:toString(), bigNumC:toString()";
|
"return bigNumA:toString(), bigNumB:toString(), bigNumC:toString()";
|
||||||
Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
|
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||||
if ( ! chunk.arg1().toboolean() )
|
if ( ! chunk.arg1().toboolean() )
|
||||||
fail( chunk.arg(2).toString() );
|
fail( chunk.arg(2).toString() );
|
||||||
Varargs results = chunk.arg1().invoke();
|
Varargs results = chunk.arg1().invoke();
|
||||||
@@ -345,7 +345,7 @@ public class LuaJavaCoercionTest extends TestCase {
|
|||||||
"local b = a:set(a:get"+typename+"())\n" +
|
"local b = a:set(a:get"+typename+"())\n" +
|
||||||
"local c = a:setr(a:get"+typename+"())\n" +
|
"local c = a:setr(a:get"+typename+"())\n" +
|
||||||
"return b,c";
|
"return b,c";
|
||||||
Varargs chunk = _G.get("loadstring").call(LuaValue.valueOf(script));
|
Varargs chunk = _G.get("load").call(LuaValue.valueOf(script));
|
||||||
if ( ! chunk.arg1().toboolean() )
|
if ( ! chunk.arg1().toboolean() )
|
||||||
fail( chunk.arg(2).toString() );
|
fail( chunk.arg(2).toString() );
|
||||||
Varargs results = chunk.arg1().invoke();
|
Varargs results = chunk.arg1().invoke();
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ c,e = load(f)
|
|||||||
if c then print('load: ', pcall(c)) else print('load failed:', e) end
|
if c then print('load: ', pcall(c)) else print('load failed:', e) end
|
||||||
|
|
||||||
-- loadfile
|
-- loadfile
|
||||||
-- loadstring
|
-- load
|
||||||
local lst = "print(3+4); return 8"
|
local lst = "print(3+4); return 8"
|
||||||
local chunk, err = loadstring( lst )
|
local chunk, err = load( lst )
|
||||||
print( 'loadstring("'..lst..'")', chunk, err )
|
print( 'load("'..lst..'")', chunk, err )
|
||||||
print( 'loadstring("'..lst..'")()', chunk() )
|
print( 'load("'..lst..'")()', chunk() )
|
||||||
|
|
||||||
-- pairs
|
-- pairs
|
||||||
print( 'pcall(pairs)', pcall(pairs) )
|
print( 'pcall(pairs)', pcall(pairs) )
|
||||||
@@ -98,7 +98,6 @@ print( 'la()', la() )
|
|||||||
function ga() return pcall(type) end
|
function ga() return pcall(type) end
|
||||||
print( 'ga()', ga() )
|
print( 'ga()', ga() )
|
||||||
|
|
||||||
-- getfenv, setfenv: tested in setfenv.lua
|
|
||||||
-- getmetatable, setmetatable
|
-- getmetatable, setmetatable
|
||||||
ta = { aa1="aaa1", aa2="aaa2" }
|
ta = { aa1="aaa1", aa2="aaa2" }
|
||||||
tb = { bb1="bbb1", bb2="bbb2" }
|
tb = { bb1="bbb1", bb2="bbb2" }
|
||||||
@@ -255,51 +254,6 @@ print( 'tostring(tostring)', type(tostring(tostring)) )
|
|||||||
print( 'tostring(function() end)', type(tostring(function() end)) )
|
print( 'tostring(function() end)', type(tostring(function() end)) )
|
||||||
print( 'tostring({"one","two",a="aa",b="bb"})', type(tostring({"one","two",a="aa",b="bb"})) )
|
print( 'tostring({"one","two",a="aa",b="bb"})', type(tostring({"one","two",a="aa",b="bb"})) )
|
||||||
|
|
||||||
-- unpack
|
|
||||||
print( 'pcall(unpack)', pcall(unpack) );
|
|
||||||
print( 'pcall(unpack,nil)', pcall(unpack,nil) );
|
|
||||||
print( 'pcall(unpack,"abc")', pcall(unpack,"abc") );
|
|
||||||
print( 'pcall(unpack,1)', pcall(unpack,1) );
|
|
||||||
print( 'unpack({"aa"})', unpack({"aa"}) );
|
|
||||||
print( 'unpack({"aa","bb"})', unpack({"aa","bb"}) );
|
|
||||||
print( 'unpack({"aa","bb","cc"})', unpack({"aa","bb","cc"}) );
|
|
||||||
local t = {"aa","bb","cc","dd","ee","ff"}
|
|
||||||
print( 'pcall(unpack,t)', pcall(unpack,t) );
|
|
||||||
print( 'pcall(unpack,t,2)', pcall(unpack,t,2) );
|
|
||||||
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
|
|
||||||
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
|
|
||||||
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
|
|
||||||
print( 'pcall(unpack,t,1)', pcall(unpack,t,1) );
|
|
||||||
print( 'pcall(unpack,t,1,5)', pcall(unpack,t,1,5) );
|
|
||||||
print( 'pcall(unpack,t,1,6)', pcall(unpack,t,1,6) );
|
|
||||||
print( 'pcall(unpack,t,1,7)', pcall(unpack,t,1,7) );
|
|
||||||
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
|
|
||||||
print( 'pcall(unpack,t,0,5)', pcall(unpack,t,0,5) );
|
|
||||||
print( 'pcall(unpack,t,0,6)', pcall(unpack,t,0,6) );
|
|
||||||
print( 'pcall(unpack,t,0,7)', pcall(unpack,t,0,7) );
|
|
||||||
print( 'pcall(unpack,t,-1)', pcall(unpack,t,-1) );
|
|
||||||
print( 'pcall(unpack,t,-1,5)', pcall(unpack,t,-1,5) );
|
|
||||||
print( 'pcall(unpack,t,-1,6)', pcall(unpack,t,-1,6) );
|
|
||||||
print( 'pcall(unpack,t,-1,7)', pcall(unpack,t,-1,7) );
|
|
||||||
print( 'pcall(unpack,t,2,4)', pcall(unpack,t,2,4) );
|
|
||||||
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
|
|
||||||
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
|
|
||||||
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
|
|
||||||
print( 'pcall(unpack,t,2,8)', pcall(unpack,t,2,8) );
|
|
||||||
print( 'pcall(unpack,t,2,2)', pcall(unpack,t,2,0) );
|
|
||||||
print( 'pcall(unpack,t,2,1)', pcall(unpack,t,2,0) );
|
|
||||||
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
|
|
||||||
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
|
|
||||||
t[0] = 'zz'
|
|
||||||
t[-1] = 'yy'
|
|
||||||
t[-2] = 'xx'
|
|
||||||
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
|
|
||||||
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
|
|
||||||
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
|
|
||||||
print( 'pcall(unpack,t,"3")', pcall(unpack,t,"3") );
|
|
||||||
print( 'pcall(unpack,t,"a")', pcall(unpack,t,"a") );
|
|
||||||
print( 'pcall(unpack,t,function() end)', pcall(unpack,t,function() end) );
|
|
||||||
|
|
||||||
-- _VERSION
|
-- _VERSION
|
||||||
print( '_VERSION', type(_VERSION) )
|
print( '_VERSION', type(_VERSION) )
|
||||||
|
|
||||||
|
|||||||
@@ -80,10 +80,10 @@ local echo = function(msg,...)
|
|||||||
return ...
|
return ...
|
||||||
end
|
end
|
||||||
local echocr = function(...)
|
local echocr = function(...)
|
||||||
echo('(echocr) first args', unpack(arg,1,arg.n))
|
echo('(echocr) first args', table.unpack(arg,1,arg.n))
|
||||||
local a = arg
|
local a = arg
|
||||||
while true do
|
while true do
|
||||||
a = { echo( '(echoch) yield returns', coroutine.yield( unpack(a) ) ) }
|
a = { echo( '(echoch) yield returns', coroutine.yield( table.unpack(a) ) ) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
local c = coroutine.create( echocr )
|
local c = coroutine.create( echocr )
|
||||||
|
|||||||
@@ -4,17 +4,6 @@ local e,f,g,h,s
|
|||||||
print( 'has debug', debug~=nil )
|
print( 'has debug', debug~=nil )
|
||||||
if not debug then error( 'no debug' ) end
|
if not debug then error( 'no debug' ) end
|
||||||
|
|
||||||
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' )
|
print( '----- debug.getlocal, debug.setlocal' )
|
||||||
h = function(v,i,n)
|
h = function(v,i,n)
|
||||||
|
|||||||
0
test/lua/errors/abc.txt
Normal file
0
test/lua/errors/abc.txt
Normal file
@@ -122,7 +122,7 @@ local function expand(argsets, typesets, ...)
|
|||||||
|
|
||||||
local s,v = split(typesets)
|
local s,v = split(typesets)
|
||||||
for i=1,(v.n or #v) do
|
for i=1,(v.n or #v) do
|
||||||
expand(argsets, s, v[i], unpack(arg,1,arg.n))
|
expand(argsets, s, v[i], table.unpack(arg,1,arg.n))
|
||||||
end
|
end
|
||||||
return argsets
|
return argsets
|
||||||
end
|
end
|
||||||
@@ -133,13 +133,13 @@ local function arglists(typesets)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function lookup( name )
|
function lookup( name )
|
||||||
return loadstring('return '..name)()
|
return load('return '..name)()
|
||||||
end
|
end
|
||||||
|
|
||||||
function invoke( name, arglist )
|
function invoke( name, arglist )
|
||||||
local s,c = pcall(lookup, name)
|
local s,c = pcall(lookup, name)
|
||||||
if not s then return s,c end
|
if not s then return s,c end
|
||||||
return pcall(c, unpack(arglist,1,arglist.n or #arglist))
|
return pcall(c, table.unpack(arglist,1,arglist.n or #arglist))
|
||||||
end
|
end
|
||||||
|
|
||||||
-- messages, banners
|
-- messages, banners
|
||||||
|
|||||||
@@ -27,11 +27,6 @@ banner('error')
|
|||||||
--checkallerrors('error', {{'message'},{nil,0,1,2,n=4}}, 'message')
|
--checkallerrors('error', {{'message'},{nil,0,1,2,n=4}}, 'message')
|
||||||
--checkallerrors('error', {{123},{nil,1,2,n=3}}, 123)
|
--checkallerrors('error', {{123},{nil,1,2,n=3}}, 123)
|
||||||
|
|
||||||
-- getfenv
|
|
||||||
banner('getfenv')
|
|
||||||
checkallpass('getfenv', {{nil,print,function()end,0,1,2,n=5}})
|
|
||||||
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument')
|
|
||||||
|
|
||||||
-- getmetatable
|
-- getmetatable
|
||||||
banner('getmetatable')
|
banner('getmetatable')
|
||||||
checkallpass('getmetatable', {notanil})
|
checkallpass('getmetatable', {notanil})
|
||||||
@@ -56,13 +51,13 @@ banner('loadfile')
|
|||||||
--checkallpass('loadfile', {{'args.lua'}})
|
--checkallpass('loadfile', {{'args.lua'}})
|
||||||
--checkallerrors('loadfile', {nonstring}, 'bad argument')
|
--checkallerrors('loadfile', {nonstring}, 'bad argument')
|
||||||
|
|
||||||
-- loadstring
|
-- load
|
||||||
banner('loadstring')
|
banner('load')
|
||||||
checkallpass('loadstring', {{'return'}})
|
checkallpass('load', {{'return'}})
|
||||||
checkallpass('loadstring', {{'return'},{'mychunk'}})
|
checkallpass('load', {{'return'},{'mychunk'}})
|
||||||
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}},true)
|
checkallpass('load', {{'return a ... b'},{'mychunk'}},true)
|
||||||
checkallerrors('loadstring', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
|
checkallerrors('load', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
|
||||||
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument')
|
checkallerrors('load', {{'return'},{afunction,atable}}, 'bad argument')
|
||||||
|
|
||||||
-- next
|
-- next
|
||||||
banner('next')
|
banner('next')
|
||||||
@@ -113,18 +108,6 @@ banner('select')
|
|||||||
checkallpass('select', {{anumber,'#'},anylua})
|
checkallpass('select', {{anumber,'#'},anylua})
|
||||||
checkallerrors('select', {notanumber}, 'bad argument')
|
checkallerrors('select', {notanumber}, 'bad argument')
|
||||||
|
|
||||||
-- setfenv
|
|
||||||
banner('setfenv')
|
|
||||||
local g = _G
|
|
||||||
checkallpass('setfenv', {{function()end},sometable})
|
|
||||||
checkallerrors('setfenv', {{-1, '-2'},{g}}, 'level must be non-negative')
|
|
||||||
checkallerrors('setfenv', {{10, '11'},{g}}, 'invalid level')
|
|
||||||
checkallerrors('setfenv', {{rawset},{g}}, 'cannot change environment of given object')
|
|
||||||
checkallerrors('setfenv', {{atable,athread,aboolean,astring},{g}}, 'bad argument')
|
|
||||||
checkallerrors('setfenv', {notafunction}, 'bad argument')
|
|
||||||
checkallerrors('setfenv', {anylua}, 'bad argument')
|
|
||||||
checkallerrors('setfenv', {{function()end},notatable}, 'bad argument')
|
|
||||||
|
|
||||||
-- setmetatable
|
-- setmetatable
|
||||||
banner('setmetatable')
|
banner('setmetatable')
|
||||||
checkallpass('setmetatable', {sometable,sometable})
|
checkallpass('setmetatable', {sometable,sometable})
|
||||||
@@ -153,15 +136,6 @@ checkallpass('type',{notanil})
|
|||||||
checkallpass('type',{anylua,{'anchor'}})
|
checkallpass('type',{anylua,{'anchor'}})
|
||||||
checkallerrors('type',{},'bad argument')
|
checkallerrors('type',{},'bad argument')
|
||||||
|
|
||||||
-- unpack
|
|
||||||
banner('unpack')
|
|
||||||
checkallpass('unpack',{sometable})
|
|
||||||
checkallpass('unpack',{sometable,{3,'5'}})
|
|
||||||
checkallpass('unpack',{sometable,{3,'5'},{1.25,'7'}})
|
|
||||||
checkallerrors('unpack',{notatable,somenumber,somenumber},'bad argument')
|
|
||||||
checkallerrors('unpack',{sometable,nonnumber,somenumber},'bad argument')
|
|
||||||
checkallerrors('unpack',{sometable,somenumber,nonnumber},'bad argument')
|
|
||||||
|
|
||||||
-- xpcall
|
-- xpcall
|
||||||
banner('xpcall')
|
banner('xpcall')
|
||||||
checkallpass('xpcall', {notanil,nonfunction})
|
checkallpass('xpcall', {notanil,nonfunction})
|
||||||
|
|||||||
@@ -19,28 +19,3 @@ banner('package.seeall')
|
|||||||
checkallpass('package.seeall',{sometable})
|
checkallpass('package.seeall',{sometable})
|
||||||
checkallerrors('package.seeall',{notatable},'bad argument')
|
checkallerrors('package.seeall',{notatable},'bad argument')
|
||||||
|
|
||||||
|
|
||||||
-- module tests - require special rigging
|
|
||||||
banner('module')
|
|
||||||
checkallerrors('module',{{20001},{nil,package.seeall,n=2},{nil,function()end,n=2}},"'module' not called from a Lua function")
|
|
||||||
checkallerrors('module',{{'testmodule1'},{nil,'pqrs',aboolean,athread,atable}},"'module' not called from a Lua function")
|
|
||||||
checkallerrors('module',{{aboolean,atable,function() end}},'bad argument')
|
|
||||||
checkallerrors('module',{{aboolean,atable,function() end},{package.seeall}},'bad argument')
|
|
||||||
|
|
||||||
-- enclose each invokation in its own function
|
|
||||||
function invoke( name, arglist )
|
|
||||||
assert( name=='module', 'module rig used for '..name )
|
|
||||||
local func = function()
|
|
||||||
module( unpack(arglist,1,arglist.n or #arglist) )
|
|
||||||
end
|
|
||||||
return pcall( func )
|
|
||||||
end
|
|
||||||
checkallpass('module',{{'foo1',20001}})
|
|
||||||
checkallpass('module',{{'foo2',20002},{package.seeall}})
|
|
||||||
checkallpass('module',{{'foo3',20003},{package.seeall},{function() end}})
|
|
||||||
checkallerrors('module',{{aboolean,atable,function() end}},'bad argument')
|
|
||||||
checkallerrors('module',{{aboolean,atable,function() end},{package.seeall}},'bad argument')
|
|
||||||
checkallerrors('module',{{'testmodule2'},{'pqrs'}},'attempt to call')
|
|
||||||
checkallerrors('module',{{'testmodule3'},{aboolean}},'attempt to call')
|
|
||||||
checkallerrors('module',{{'testmodule4'},{athread}},'attempt to call')
|
|
||||||
checkallerrors('module',{{'testmodule5'},{atable}},'attempt to call')
|
|
||||||
|
|||||||
0
test/lua/errors/seektest.txt
Normal file
0
test/lua/errors/seektest.txt
Normal file
@@ -63,4 +63,13 @@ function table_set_nil_key(tbl,val) tbl[nil]=val end
|
|||||||
checkallpass('table_set',{sometable,notanil,anylua})
|
checkallpass('table_set',{sometable,notanil,anylua})
|
||||||
checkallerrors('table_set_nil_key',{sometable,anylua},'table index')
|
checkallerrors('table_set_nil_key',{sometable,anylua},'table index')
|
||||||
|
|
||||||
|
-- table.unpack
|
||||||
|
banner('table.unpack')
|
||||||
|
checkallpass('table.unpack',{sometable})
|
||||||
|
checkallpass('table.unpack',{sometable,{3,'5'}})
|
||||||
|
checkallpass('table.unpack',{sometable,{3,'5'},{1.25,'7'}})
|
||||||
|
checkallerrors('table.unpack',{notatable,somenumber,somenumber},'bad argument')
|
||||||
|
checkallerrors('table.unpack',{sometable,nonnumber,somenumber},'bad argument')
|
||||||
|
checkallerrors('table.unpack',{sometable,somenumber,nonnumber},'bad argument')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
@@ -33,5 +33,5 @@ t[200] = [[
|
|||||||
|
|
||||||
local s = table.concat(t)
|
local s = table.concat(t)
|
||||||
print(s)
|
print(s)
|
||||||
f = loadstring(s)
|
f = load(s)
|
||||||
f()
|
f()
|
||||||
|
|||||||
@@ -100,9 +100,9 @@ end
|
|||||||
|
|
||||||
local function eval( expr, script )
|
local function eval( expr, script )
|
||||||
script = script or ('return '..expr)
|
script = script or ('return '..expr)
|
||||||
local s,a,b = loadstring( script, 'expr' )
|
local s,a,b = load( script, 'expr' )
|
||||||
if s then print( expr, pcall( s ) )
|
if s then print( expr, pcall( s ) )
|
||||||
else print( expr, 'loadstring:', a ) end
|
else print( expr, 'load:', a ) end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- misc tests
|
-- misc tests
|
||||||
@@ -191,7 +191,7 @@ end
|
|||||||
-- random tests
|
-- random tests
|
||||||
print("----------- Random number tests")
|
print("----------- Random number tests")
|
||||||
local function testrandom(string,lo,hi)
|
local function testrandom(string,lo,hi)
|
||||||
local c,e = loadstring('return '..string)
|
local c,e = load('return '..string)
|
||||||
for i=1,5 do
|
for i=1,5 do
|
||||||
local s,e = pcall(c)
|
local s,e = pcall(c)
|
||||||
if s then
|
if s then
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ local function fannkuch(n)
|
|||||||
-- Print max. 30 permutations.
|
-- Print max. 30 permutations.
|
||||||
if check < 30 then
|
if check < 30 then
|
||||||
if not p[n] then return maxflips end -- Catch n = 0, 1, 2.
|
if not p[n] then return maxflips end -- Catch n = 0, 1, 2.
|
||||||
io.write(unpack(p)); io.write("\n")
|
io.write(table.unpack(p)); io.write("\n")
|
||||||
check = check + 1
|
check = check + 1
|
||||||
end
|
end
|
||||||
-- Copy and flip.
|
-- Copy and flip.
|
||||||
|
|||||||
@@ -1,18 +1,39 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#unzip -o luaj3.0-tests.zip
|
#
|
||||||
|
# unpack the luaj test archive, compile and run it locally, and repack the results
|
||||||
|
|
||||||
|
# unzip existing archive
|
||||||
|
unzip -n luaj3.0-tests.zip
|
||||||
|
rm *.lc *.out */*.lc */*.out
|
||||||
|
|
||||||
|
# compile tests for compiler and save binary files
|
||||||
|
for DIR in "lua5.2.1-tests" "regressions"; do
|
||||||
|
cd ${DIR}
|
||||||
|
FILES=`ls -1 *.lua | awk 'BEGIN { FS="." } ; { print $1 }'`
|
||||||
|
for FILE in $FILES ; do
|
||||||
|
echo 'compiling' `pwd` $FILE
|
||||||
|
luac ${FILE}.lua
|
||||||
|
mv luac.out ${FILE}.lc
|
||||||
|
done
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
|
||||||
|
# run test lua scripts and save output
|
||||||
for DIR in "errors" "perf" "."; do
|
for DIR in "errors" "perf" "."; do
|
||||||
cd ${DIR}
|
cd ${DIR}
|
||||||
FILES=`ls -1 *.lua | awk 'BEGIN { FS="." } ; { print $1 }'`
|
FILES=`ls -1 *.lua | awk 'BEGIN { FS="." } ; { print $1 }'`
|
||||||
echo "FILES" $FILES
|
|
||||||
for FILE in $FILES ; do
|
for FILE in $FILES ; do
|
||||||
echo "executing ${FILE}.lua"
|
echo 'executing' `pwd` $FILE
|
||||||
luac ${FILE}.lua
|
|
||||||
mv luac.out ${FILE}.lc
|
|
||||||
lua ${FILE}.lua > ${FILE}.out
|
lua ${FILE}.lua > ${FILE}.out
|
||||||
done
|
done
|
||||||
rm abc.txt
|
|
||||||
cd ..
|
cd ..
|
||||||
done
|
done
|
||||||
cd lua
|
cd lua
|
||||||
rm -f luaj3.0-tests.zip
|
|
||||||
|
# create new zipfile
|
||||||
|
rm -f luaj3.0-tests.zip regressions
|
||||||
zip -9 luaj3.0-tests.zip *.lua *.lc *.out */*.lua */*.lc */*.out
|
zip -9 luaj3.0-tests.zip *.lua *.lc *.out */*.lua */*.lc */*.out
|
||||||
|
|
||||||
|
# cleanup
|
||||||
|
rm *.out */*.lc */*.out
|
||||||
|
rm -r lua5.2.1-tests
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ strtests('lower', string.lower, s )
|
|||||||
strtests('upper', string.upper, s )
|
strtests('upper', string.upper, s )
|
||||||
strtests('reverse', string.reverse, s )
|
strtests('reverse', string.reverse, s )
|
||||||
strtests('char', string.char, 92, 60, 61, 93 )
|
strtests('char', string.char, 92, 60, 61, 93 )
|
||||||
strtests('dump', string.dump, loadstring('print("hello, world")', 'sample') )
|
strtests('dump', string.dump, load('print("hello, world")', 'sample') )
|
||||||
|
|
||||||
|
|
||||||
-- floating point formats (not supported yet)
|
-- floating point formats (not supported yet)
|
||||||
|
|||||||
@@ -164,8 +164,16 @@ testbothpairs(t)
|
|||||||
--]]
|
--]]
|
||||||
|
|
||||||
-- tests of setlist table constructors
|
-- tests of setlist table constructors
|
||||||
-- length and unpack are tested elsewhere
|
-- length is tested elsewhere
|
||||||
print('----- unpack tests -------')
|
print('----- unpack tests -------')
|
||||||
|
local unpack = table.unpack
|
||||||
|
print( 'pcall(unpack)', pcall(unpack) );
|
||||||
|
print( 'pcall(unpack,nil)', pcall(unpack,nil) );
|
||||||
|
print( 'pcall(unpack,"abc")', pcall(unpack,"abc") );
|
||||||
|
print( 'pcall(unpack,1)', pcall(unpack,1) );
|
||||||
|
print( 'unpack({"aa"})', unpack({"aa"}) );
|
||||||
|
print( 'unpack({"aa","bb"})', unpack({"aa","bb"}) );
|
||||||
|
print( 'unpack({"aa","bb","cc"})', unpack({"aa","bb","cc"}) );
|
||||||
local function a(...) return ... end
|
local function a(...) return ... end
|
||||||
print('unpack -',unpack({}))
|
print('unpack -',unpack({}))
|
||||||
print('unpack a',unpack({'a'}))
|
print('unpack a',unpack({'a'}))
|
||||||
@@ -195,6 +203,42 @@ print('unpack (..b)',unpack({a(nil, nil, 'b')},1,3))
|
|||||||
print('unpack (a..)',unpack({a('a', nil, nil)},1,3))
|
print('unpack (a..)',unpack({a('a', nil, nil)},1,3))
|
||||||
print('unpack (.b.)',unpack({a(nil, 'b', nil)},1,3))
|
print('unpack (.b.)',unpack({a(nil, 'b', nil)},1,3))
|
||||||
print('unpack (...)',unpack({a(nil, nil, nil)},1,3))
|
print('unpack (...)',unpack({a(nil, nil, nil)},1,3))
|
||||||
|
local t = {"aa","bb","cc","dd","ee","ff"}
|
||||||
|
print( 'pcall(unpack,t)', pcall(unpack,t) );
|
||||||
|
print( 'pcall(unpack,t,2)', pcall(unpack,t,2) );
|
||||||
|
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
|
||||||
|
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
|
||||||
|
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
|
||||||
|
print( 'pcall(unpack,t,1)', pcall(unpack,t,1) );
|
||||||
|
print( 'pcall(unpack,t,1,5)', pcall(unpack,t,1,5) );
|
||||||
|
print( 'pcall(unpack,t,1,6)', pcall(unpack,t,1,6) );
|
||||||
|
print( 'pcall(unpack,t,1,7)', pcall(unpack,t,1,7) );
|
||||||
|
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
|
||||||
|
print( 'pcall(unpack,t,0,5)', pcall(unpack,t,0,5) );
|
||||||
|
print( 'pcall(unpack,t,0,6)', pcall(unpack,t,0,6) );
|
||||||
|
print( 'pcall(unpack,t,0,7)', pcall(unpack,t,0,7) );
|
||||||
|
print( 'pcall(unpack,t,-1)', pcall(unpack,t,-1) );
|
||||||
|
print( 'pcall(unpack,t,-1,5)', pcall(unpack,t,-1,5) );
|
||||||
|
print( 'pcall(unpack,t,-1,6)', pcall(unpack,t,-1,6) );
|
||||||
|
print( 'pcall(unpack,t,-1,7)', pcall(unpack,t,-1,7) );
|
||||||
|
print( 'pcall(unpack,t,2,4)', pcall(unpack,t,2,4) );
|
||||||
|
print( 'pcall(unpack,t,2,5)', pcall(unpack,t,2,5) );
|
||||||
|
print( 'pcall(unpack,t,2,6)', pcall(unpack,t,2,6) );
|
||||||
|
print( 'pcall(unpack,t,2,7)', pcall(unpack,t,2,7) );
|
||||||
|
print( 'pcall(unpack,t,2,8)', pcall(unpack,t,2,8) );
|
||||||
|
print( 'pcall(unpack,t,2,2)', pcall(unpack,t,2,0) );
|
||||||
|
print( 'pcall(unpack,t,2,1)', pcall(unpack,t,2,0) );
|
||||||
|
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
|
||||||
|
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
|
||||||
|
t[0] = 'zz'
|
||||||
|
t[-1] = 'yy'
|
||||||
|
t[-2] = 'xx'
|
||||||
|
print( 'pcall(unpack,t,0)', pcall(unpack,t,0) );
|
||||||
|
print( 'pcall(unpack,t,2,0)', pcall(unpack,t,2,0) );
|
||||||
|
print( 'pcall(unpack,t,2,-1)', pcall(unpack,t,2,-1) );
|
||||||
|
print( 'pcall(unpack,t,"3")', pcall(unpack,t,"3") );
|
||||||
|
print( 'pcall(unpack,t,"a")', pcall(unpack,t,"a") );
|
||||||
|
print( 'pcall(unpack,t,function() end)', pcall(unpack,t,function() end) );
|
||||||
|
|
||||||
-- misc tests
|
-- misc tests
|
||||||
print('----- misc table initializer tests -------')
|
print('----- misc table initializer tests -------')
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ local function all(f)
|
|||||||
for n=0,3 do
|
for n=0,3 do
|
||||||
t = {}
|
t = {}
|
||||||
for m=1,5 do
|
for m=1,5 do
|
||||||
print( "--f, n, unpack(t)", f, n, unpack(t) )
|
print( "--f, n, table.unpack(t)", f, n, table.unpack(t) )
|
||||||
print( pcall( f, n, unpack(t)) )
|
print( pcall( f, n, table.unpack(t)) )
|
||||||
t[m] = m
|
t[m] = m
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user