Simplify layout of lua test script locations.

This commit is contained in:
James Roseborough
2012-09-07 14:05:41 +00:00
parent 3bacea878e
commit f2d1106fe5
27 changed files with 151 additions and 166 deletions

0
test/lua/errors/abc.txt Normal file
View File

View File

@@ -122,7 +122,7 @@ local function expand(argsets, typesets, ...)
local s,v = split(typesets)
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
return argsets
end
@@ -133,13 +133,13 @@ local function arglists(typesets)
end
function lookup( name )
return loadstring('return '..name)()
return load('return '..name)()
end
function invoke( name, arglist )
local s,c = pcall(lookup, name)
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
-- messages, banners

View File

@@ -27,11 +27,6 @@ banner('error')
--checkallerrors('error', {{'message'},{nil,0,1,2,n=4}}, 'message')
--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
banner('getmetatable')
checkallpass('getmetatable', {notanil})
@@ -56,13 +51,13 @@ banner('loadfile')
--checkallpass('loadfile', {{'args.lua'}})
--checkallerrors('loadfile', {nonstring}, 'bad argument')
-- loadstring
banner('loadstring')
checkallpass('loadstring', {{'return'}})
checkallpass('loadstring', {{'return'},{'mychunk'}})
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}},true)
checkallerrors('loadstring', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument')
-- load
banner('load')
checkallpass('load', {{'return'}})
checkallpass('load', {{'return'},{'mychunk'}})
checkallpass('load', {{'return a ... b'},{'mychunk'}},true)
checkallerrors('load', {notastring,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('load', {{'return'},{afunction,atable}}, 'bad argument')
-- next
banner('next')
@@ -113,18 +108,6 @@ banner('select')
checkallpass('select', {{anumber,'#'},anylua})
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
banner('setmetatable')
checkallpass('setmetatable', {sometable,sometable})
@@ -153,15 +136,6 @@ checkallpass('type',{notanil})
checkallpass('type',{anylua,{'anchor'}})
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
banner('xpcall')
checkallpass('xpcall', {notanil,nonfunction})

View File

@@ -19,28 +19,3 @@ banner('package.seeall')
checkallpass('package.seeall',{sometable})
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')

View File

View File

@@ -63,4 +63,13 @@ function table_set_nil_key(tbl,val) tbl[nil]=val end
checkallpass('table_set',{sometable,notanil,anylua})
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')