Implemented Support of Java 21 VirtualThread

This commit is contained in:
UnlegitDqrk
2026-03-01 12:39:42 +01:00
parent 40831d0f2d
commit f40e89e19c
216 changed files with 2172 additions and 16083 deletions

View File

@@ -1,198 +0,0 @@
-- utilities to check that args of various types pass or fail
-- argument type checking
local ok = '-\t'
local fail = 'fail '
local needcheck = 'needcheck '
local badmsg = 'badmsg '
akey = 'aa'
astring = 'abc'
astrnum = '789'
anumber = 1.25
ainteger = 345
adouble = 12.75
aboolean = true
atable = {[akey]=456}
afunction = function() end
anil = nil
athread = coroutine.create(afunction)
anylua = { nil, astring, anumber, aboolean, atable, afunction, athread }
somestring = { astring, anumber }
somenumber = { anumber, astrnum }
someboolean = { aboolean }
sometable = { atable }
somefunction = { afunction }
somenil = { anil }
somekey = { akey }
notakey = { astring, anumber, aboolean, atable, afunction }
notastring = { nil, aboolean, atable, afunction, athread }
notanumber = { nil, astring, aboolean, atable, afunction, athread }
notaboolean = { nil, astring, anumber, atable, afunction, athread }
notatable = { nil, astring, anumber, aboolean, afunction, athread }
notafunction = { nil, astring, anumber, aboolean, atable, athread }
notathread = { nil, astring, anumber, aboolean, atable, afunction }
notanil = { astring, anumber, aboolean, atable, afunction, athread }
nonstring = { aboolean, atable, afunction, athread }
nonnumber = { astring, aboolean, atable, afunction, athread }
nonboolean = { astring, anumber, atable, afunction, athread }
nontable = { astring, anumber, aboolean, afunction, athread }
nonfunction = { astring, anumber, aboolean, atable, athread }
nonthread = { astring, anumber, aboolean, atable, afunction }
nonkey = { astring, anumber, aboolean, atable, afunction }
local structtypes = {
['table']='<table>',
['function']='<function>',
['thread']='<thread>',
['userdata']='<userdata>',
}
local function bracket(v)
return "<"..type(v)..">"
end
local function quote(v)
return "'"..v.."'"
end
local function ellipses(v)
local s = tostring(v)
return #s <= 8 and s or (string.sub(s,1,8)..'...')
end
local pretty = {
['table']=bracket,
['function']=bracket,
['thread']=bracket,
['userdata']=bracket,
['string']= quote,
['number']= ellipses,
}
local function values(list)
local t = {}
for i=1,(list.n or #list) do
local ai = list[i]
local fi = pretty[type(ai)]
t[i] = fi and fi(ai) or tostring(ai)
end
return table.concat(t,',')
end
local function types(list)
local t = {}
for i=1,(list.n or #list) do
local ai = list[i]
t[i] = type(ai)
end
return table.concat(t,',')
end
local function signature(name,arglist)
return name..'('..values(arglist)..')'
end
local function dup(t)
local s = {}
for i=1,(t.n or #t) do
s[i] = t[i]
end
return s
end
local function split(t)
local s = {}
local n = (t.n or #t)
for i=1,n-1 do
s[i] = t[i]
end
return s,t[n]
end
local function expand(argsets, typesets, ...)
local arg = table.pack(...)
local n = typesets and #typesets or 0
if n <= 0 then
table.insert(argsets,arg)
return argsets
end
local s,v = split(typesets)
for i=1,(v.n or #v) do
expand(argsets, s, v[i], table.unpack(arg,1,arg.n))
end
return argsets
end
local function arglists(typesets)
local argsets = expand({},typesets)
return ipairs(argsets)
end
function lookup( 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, table.unpack(arglist,1,arglist.n or #arglist))
end
-- messages, banners
local _print = print
local _tostring = tostring
local _find = string.find
function banner(name)
_print( '====== '.._tostring(name)..' ======' )
end
local function subbanner(name)
_print( '--- '.._tostring(name) )
end
local function pack(s,...)
return s,{...}
end
-- check that all combinations of arguments pass
function checkallpass( name, typesets, typesonly )
subbanner('checkallpass')
for i,v in arglists(typesets) do
local sig = signature(name,v)
local s,r = pack( invoke( name, v ) )
if s then
if typesonly then
_print( ok, sig, types(r) )
else
_print( ok, sig, values(r) )
end
else
_print( fail, sig, values(r) )
end
end
end
-- check that all combinations of arguments fail in some way,
-- ignore error messages
function checkallerrors( name, typesets, template )
subbanner('checkallerrors')
template = _tostring(template)
for i,v in arglists(typesets) do
local sig = signature(name,v)
local s,e = invoke( name, v )
if not s then
if _find(e, template, 1, true) then
_print( ok, sig, '...'..template..'...' )
else
_print( badmsg, sig, "template='"..template.."' actual='"..e.."'" )
end
else
_print( needcheck, sig, e )
end
end
end

View File

@@ -1,145 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg types for basic library functions
-- assert
banner('assert')
checkallpass('assert',{{true,123},anylua})
checkallerrors('assert',{{nil,false,n=2},{nil,n=1}},'assertion failed')
checkallerrors('assert',{{nil,false,n=2},{'message'}},'message')
-- collectgarbage
banner('collectgarbage')
checkallpass('collectgarbage',{{'collect','count'}},true)
checkallerrors('collectgarbage',{{astring, anumber}},'bad argument')
checkallerrors('collectgarbage',{{aboolean, atable, afunction, athread}},'string expected')
-- dofile
banner('dofile')
--checkallpass('dofile', {})
--checkallpass('dofile', {{'test/lua/errors/args.lua'}})
--checkallerrors('dofile', {{'foo.bar'}}, 'cannot open foo.bar')
--checkallerrors('dofile', {nonstring}, 'bad argument')
-- error
banner('error')
--checkallerrors('error', {{'message'},{nil,0,1,2,n=4}}, 'message')
--checkallerrors('error', {{123},{nil,1,2,n=3}}, 123)
-- getmetatable
banner('getmetatable')
checkallpass('getmetatable', {notanil})
checkallerrors('getmetatable',{},'bad argument')
-- ipairs
banner('ipairs')
checkallpass('ipairs', {sometable})
checkallerrors('ipairs', {notatable}, 'bad argument')
-- load
banner('load')
checkallpass('load', {somefunction,{nil,astring,n=2}})
checkallerrors('load', {notafunction,{nil,astring,anumber,n=3}}, 'bad argument')
checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument')
-- loadfile
banner('loadfile')
--checkallpass('loadfile', {})
--checkallpass('loadfile', {{'bogus'}})
--checkallpass('loadfile', {{'test/lua/errors/args.lua'}})
--checkallpass('loadfile', {{'args.lua'}})
--checkallerrors('loadfile', {nonstring}, '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')
checkallpass('next', {sometable,somekey})
checkallerrors('next', {notatable,{nil,1,n=2}}, 'bad argument')
checkallerrors('next', {sometable,nonkey}, 'invalid key')
-- pairs
banner('pairs')
checkallpass('pairs', {sometable})
checkallerrors('pairs', {notatable}, 'bad argument')
-- pcall
banner('pcall')
checkallpass('pcall', {notanil,anylua}, true)
checkallerrors('pcall',{},'bad argument')
-- print
banner('print')
checkallpass('print', {})
checkallpass('print', {{nil,astring,anumber,aboolean,n=4}})
-- rawequal
banner('rawequal')
checkallpass('rawequal', {notanil,notanil})
checkallerrors('rawequal', {}, 'bad argument')
checkallerrors('rawequal', {notanil}, 'bad argument')
-- rawget
banner('rawget')
checkallpass('rawget', {sometable,somekey})
checkallpass('rawget', {sometable,nonkey})
checkallerrors('rawget', {sometable,somenil},'bad argument')
checkallerrors('rawget', {notatable,notakey}, 'bad argument')
checkallerrors('rawget', {}, 'bad argument')
-- rawset
banner('rawset')
checkallpass('rawset', {sometable,somekey,notanil})
checkallpass('rawset', {sometable,nonkey,notanil})
checkallerrors('rawset', {sometable,somenil},'table index is nil')
checkallerrors('rawset', {}, 'bad argument')
checkallerrors('rawset', {notatable,somestring,somestring}, 'bad argument')
checkallerrors('rawset', {sometable,somekey}, 'bad argument')
-- select
banner('select')
checkallpass('select', {{anumber,'#'},anylua})
checkallerrors('select', {notanumber}, 'bad argument')
-- setmetatable
banner('setmetatable')
checkallpass('setmetatable', {sometable,sometable})
checkallpass('setmetatable', {sometable,{}})
checkallerrors('setmetatable',{notatable,sometable},'bad argument')
checkallerrors('setmetatable',{sometable,nontable},'bad argument')
-- tonumber
banner('tonumber')
checkallpass('tonumber',{somenumber,{nil,2,10,36,n=4}})
checkallpass('tonumber',{notanil,{nil,10,n=2}})
checkallerrors('tonumber',{{nil,afunction,atable,n=3},{2,9,11,36}},'bad argument')
checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument')
-- tostring
banner('tostring')
checkallpass('tostring',{{astring,anumber,aboolean}})
checkallpass('tostring',{{atable,afunction,athread}},true)
checkallpass('tostring',{{astring,anumber,aboolean},{'anchor'}})
checkallpass('tostring',{{atable,afunction,athread},{'anchor'}},true)
checkallerrors('tostring',{},'bad argument')
-- type
banner('type')
checkallpass('type',{notanil})
checkallpass('type',{anylua,{'anchor'}})
checkallerrors('type',{},'bad argument')
-- xpcall
banner('xpcall')
checkallpass('xpcall', {notanil,nonfunction})
checkallpass('xpcall', {notanil,{function(...)return 'aaa', 'bbb', #{...} end}})
checkallerrors('xpcall',{anylua},'bad argument')

View File

@@ -1,47 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg type tests for coroutine library functions
-- coroutine.create
banner('coroutine.create')
checkallpass('coroutine.create',{somefunction})
checkallerrors('coroutine.create',{notafunction},'bad argument')
-- coroutine.resume
banner('coroutine.resume')
local co = coroutine.create(function() while true do coroutine.yield() end end)
checkallpass('coroutine.resume',{{co},anylua})
checkallerrors('coroutine.resume',{notathread},'bad argument')
-- coroutine.running
banner('coroutine.running')
checkallpass('coroutine.running',{anylua})
-- coroutine.status
banner('coroutine.status')
checkallpass('coroutine.status',{{co}})
checkallerrors('coroutine.status',{notathread},'bad argument')
-- coroutine.wrap
banner('coroutine.wrap')
checkallpass('coroutine.wrap',{somefunction})
checkallerrors('coroutine.wrap',{notafunction},'bad argument')
-- coroutine.yield
banner('coroutine.yield')
local function f()
print( 'yield', coroutine.yield() )
print( 'yield', coroutine.yield(astring,anumber,aboolean) )
error('error within coroutine thread')
end
local co = coroutine.create( f )
print( 'status', coroutine.status(co) )
print( coroutine.resume(co,astring,anumber) )
print( 'status', coroutine.status(co) )
print( coroutine.resume(co,astring,anumber) )
print( 'status', coroutine.status(co) )
local s,e = coroutine.resume(co,astring,anumber)
print( s, string.match(e,'error within coroutine thread') or 'bad message: '..tostring(e) )
print( 'status', coroutine.status(co) )

View File

@@ -1,150 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
local alevel = {25,'25'}
local afuncorlevel = {afunction,25,'25'}
local notafuncorlevel = {nil,astring,aboolean,athread}
local notafuncorthread = {nil,astring,aboolean}
-- debug.debug()
banner('debug.debug - no tests')
-- debug.gethook ([thread])
banner('debug.gethook')
checkallpass('debug.gethook',{})
-- debug.getinfo ([thread,] f [, what])
banner('debug.getinfo')
local awhat = {"","n","flnStu"}
local notawhat = {"qzQZ"}
checkallpass('debug.getinfo',{afuncorlevel})
checkallpass('debug.getinfo',{somethread,afuncorlevel})
checkallpass('debug.getinfo',{afuncorlevel,awhat})
checkallpass('debug.getinfo',{somethread,afuncorlevel,awhat})
checkallerrors('debug.getinfo',{},'function or level')
checkallerrors('debug.getinfo',{notafuncorlevel},'function or level')
checkallerrors('debug.getinfo',{somefunction,nonstring}, 'string expected')
checkallerrors('debug.getinfo',{notafuncorthread,somefunction}, 'string expected')
checkallerrors('debug.getinfo',{nonthread,somefunction,{astring}}, 'string expected')
checkallerrors('debug.getinfo',{somethread,somefunction,notawhat}, 'invalid option')
-- debug.getlocal ([thread,] f, local)
banner('debug.getlocal')
local p,q = 'p','q';
f = function(x,y)
print('f: x,y,a,b,p,q', x, y, a, b, p, q)
local a,b = x,y
local t = coroutine.running()
checkallpass('debug.getlocal',{{f,1},{1,'2'}})
checkallpass('debug.getlocal',{{t},{f},{1}})
checkallerrors('debug.getlocal',{},'number expected')
checkallerrors('debug.getlocal',{afuncorlevel,notanumber},'number expected')
checkallerrors('debug.getlocal',{notafuncorlevel,somenumber}, 'number expected')
checkallerrors('debug.getlocal',{{t},afuncorlevel}, 'got no value')
checkallerrors('debug.getlocal',{nonthread,{f},{1,'2'}}, 'number expected')
checkallerrors('debug.getlocal',{{t},{100},{1}}, 'level out of range')
end
f(1,2)
-- debug.getmetatable (value)
banner('debug.getmetatable')
checkallpass('debug.getmetatable',{anylua})
checkallerrors('debug.getmetatable',{},'value expected')
-- debug.getregistry ()
banner('debug.getregistry')
checkallpass('debug.getregistry',{})
checkallpass('debug.getregistry',{anylua})
-- debug.getupvalue (f, up)
banner('debug.getupvalue')
checkallpass('debug.getupvalue',{{f},{1,'2'}})
checkallerrors('debug.getupvalue',{},'number expected')
checkallerrors('debug.getupvalue',{notafunction,{1,'2'}}, 'function expected')
checkallerrors('debug.getupvalue',{{f},notanumber}, 'number expected')
-- debug.getuservalue (u)
checkallpass('debug.getuservalue',{})
checkallpass('debug.getuservalue',{anylua})
-- debug.sethook ([thread,] hook, mask [, count])
local ahookstr = {"cr","l"}
checkallpass('debug.sethook',{})
checkallpass('debug.sethook',{somenil,ahookstr})
checkallpass('debug.sethook',{somefunction,ahookstr})
checkallpass('debug.sethook',{{nil,athread,n=2},somefunction,ahookstr})
checkallerrors('debug.sethook',{{astring,afunction,aboolean}},'string expected')
checkallerrors('debug.sethook',{{astring,afunction,aboolean},{nil,afunction,n=2},ahookstr},'string expected')
-- debug.setlocal ([thread,] level, local, value)
banner('debug.setlocal')
local p,q = 'p','q';
f = function(x,y)
print('f: x,y,a,b,p,q', x, y, a, b, p, q)
local a,b = x,y
local t = coroutine.running()
checkallpass('debug.setlocal',{{1},{1},{nil,'foo',n=2}})
print('f: x,y,a,b,p,q', x, y, a, b, p, q)
checkallpass('debug.setlocal',{{t},{1},{2},{nil,'bar',n=2}})
print('f: x,y,a,b,p,q', x, y, a, b, p, q)
checkallerrors('debug.setlocal',{},'number expected')
checkallerrors('debug.setlocal',{{1}},'value expected')
checkallerrors('debug.setlocal',{{1},{1}}, 'value expected')
checkallerrors('debug.setlocal',{{t},{1},{2}}, 'value expected')
checkallerrors('debug.setlocal',{{atable,astring},{1}}, 'number expected')
checkallerrors('debug.setlocal',{{1},nonnumber}, 'value expected')
checkallerrors('debug.setlocal',{{atable,astring},{1},{1},{nil,'foo',n=2}}, 'number expected')
checkallerrors('debug.setlocal',{{10},{1},{'foo'}}, 'level out of range')
return p,q
end
f(1,2)
-- debug.setmetatable (value, table)
banner('debug.setmetatable')
checkallpass('debug.setmetatable',{anylua,{atable,nil,n=2}})
checkallerrors('debug.setmetatable',{},'nil or table')
checkallerrors('debug.setmetatable',{anylua},'nil or table')
-- debug.setupvalue (f, up, value)
banner('debug.setupvalue')
checkallpass('debug.setupvalue',{{f},{2,'3'},{nil,aboolean,astring,n=3}})
print('p,q', p, q)
checkallerrors('debug.setupvalue',{},'value expected')
checkallerrors('debug.setupvalue',{{f}},'value expected')
checkallerrors('debug.setupvalue',{{f},{2}},'value expected')
checkallerrors('debug.setupvalue',{notafunction,{2}}, 'value expected')
checkallerrors('debug.setupvalue',{{f},notanumber}, 'value expected')
-- debug.setuservalue (udata, value)
banner('debug.setuservalue')
checkallerrors('debug.setuservalue',{},'userdata expected')
checkallerrors('debug.setuservalue',{anylua},'userdata expected')
checkallerrors('debug.setuservalue',{anylua,somestring},'userdata expected')
-- debug.traceback ([thread,] [message [, level]])
banner('debug.traceback')
local t = coroutine.running()
checkallpass('debug.traceback',{})
checkallpass('debug.traceback',{{astring}})
checkallpass('debug.traceback',{{astring},{anumber}})
checkallpass('debug.traceback',{{t}})
checkallpass('debug.traceback',{{t},{astring}})
checkallpass('debug.traceback',{{t},{astring},{anumber}})
checkallpass('debug.traceback',{{afunction,aboolean,atable}})
checkallpass('debug.traceback',{{afunction,aboolean,atable},notanumber})
-- debug.upvalueid (f, n)
banner('debug.upvalueid')
checkallpass('debug.upvalueid',{{f},{1,'2'}})
checkallerrors('debug.upvalueid',{},'number expected')
checkallerrors('debug.upvalueid',{notafunction,{1,'2'}}, 'function expected')
checkallerrors('debug.upvalueid',{{f},notanumber}, 'number expected')
-- debug.upvaluejoin (f1, n1, f2, n2)
banner('debug.upvaluejoin')
checkallpass('debug.upvaluejoin',{{f},{1,'2'},{f},{1,'2'}})
checkallerrors('debug.upvaluejoin',{},'number expected')
checkallerrors('debug.upvaluejoin',{notafunction,{1,'2'}}, 'function expected')
checkallerrors('debug.upvaluejoin',{{f},notanumber}, 'number expected')
checkallerrors('debug.upvaluejoin',{{f},{1},notafunction,{1,'2'}}, 'function expected')
checkallerrors('debug.upvaluejoin',{{f},{1},{f},notanumber}, 'number expected')

View File

@@ -1,85 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg type tests for io library functions
local f
-- io.close ([file])
banner('io.close')
f = io.open("abc.txt","w")
checkallpass('io.close',{{f}})
checkallerrors('io.close',{notanil},'bad argument')
-- io.input ([file])
banner('io.input')
f = io.open("abc.txt","r")
checkallpass('io.input',{{nil,f,"abc.txt",n=3}})
checkallerrors('io.input',{nonstring},'bad argument')
-- io.lines ([filename])
banner('io.lines')
io.input("abc.txt")
checkallpass('io.lines',{{"abc.txt"}})
checkallerrors('io.lines',{{f}},'bad argument')
checkallerrors('io.lines',{notastring},'bad argument')
-- io.open (filename [, mode])
banner('io.open')
checkallpass('io.open',{{"abc.txt"},{nil,"r","w","a","r+","w+","a+"}})
checkallerrors('io.open',{notastring},'bad argument')
checkallerrors('io.open',{{"abc.txt"},{nonstring}},'bad argument')
-- io.output ([file])
banner('io.output')
checkallpass('io.output',{{nil,f,"abc.txt",n=3}})
checkallerrors('io.output',{nonstring},'bad argument')
-- io.popen (prog [, mode])
banner('io.popen')
--checkallpass('io.popen',{{"hostname"},{nil,"w",n=2}})
checkallerrors('io.popen',{notastring},'bad argument')
checkallerrors('io.popen',{{"hostname"},{nonstring}},'bad argument')
-- io.read (<28><><EFBFBD>)
banner('io.read')
checkallpass('io.read',{})
checkallpass('io.read',{{2,"*n","*a","*l"}})
checkallpass('io.read',{{2,"*n","*a","*l"},{2,"*a","*l"}})
checkallerrors('io.read',{{aboolean,afunction,atable,"3"}},'bad argument')
-- io.write (<28><><EFBFBD>)
banner('io.write')
checkallpass('io.write',{})
checkallpass('io.write',{somestring})
checkallpass('io.write',{somestring,somestring})
checkallerrors('io.write',{nonstring},'bad argument')
checkallerrors('io.write',{somestring,nonstring},'bad argument')
-- file:write ()
banner('file:write')
file = io.open("seektest.txt","w")
checkallpass('file.write',{{file},somestring})
checkallpass('file.write',{{file},somestring,somestring})
checkallerrors('file.write',{},'bad argument')
checkallerrors('file.write',{{file},nonstring},'bad argument')
checkallerrors('file.write',{{file},somestring,nonstring},'bad argument')
pcall( file.close, file )
-- file:seek ([whence] [, offset])
banner('file:seek')
file = io.open("seektest.txt","r")
checkallpass('file.seek',{{file}})
checkallpass('file.seek',{{file},{"set","cur","end"}})
checkallpass('file.seek',{{file},{"set","cur","end"},{2,"3"}})
checkallerrors('file.seek',{},'bad argument')
checkallerrors('file.seek',{{file},nonstring},'bad argument')
checkallerrors('file.seek',{{file},{"set","cur","end"},nonnumber},'bad argument')
-- file:setvbuf (mode [, size])
banner('file:setvbuf')
checkallpass('file.setvbuf',{{file},{"no","full","line"}})
checkallpass('file.setvbuf',{{file},{"full"},{1024,"512"}})
checkallerrors('file.setvbuf',{},'bad argument')
checkallerrors('file.setvbuf',{{file},notastring},'bad argument')
checkallerrors('file.setvbuf',{{file},{"full"},nonnumber},'bad argument')

View File

@@ -1,112 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
local tostring = tostring
_G.tostring = function(x)
local s = tostring(x)
return type(x)=='number' and #s>4 and (s:sub(1,5)..'...') or s
end
-- arg type tests for math library functions
local somenumber = {1,0.75,'-1','-0.25'}
local somepositive = {1,0.75,'2', '2.5'}
local notanumber = {nil,astring,aboolean,afunction,atable,athread}
local nonnumber = {astring,aboolean,afunction,atable}
local singleargfunctions = {
'abs', 'acos', 'asin', 'atan', 'cos', 'cosh', 'deg', 'exp', 'floor',
'rad', 'randomseed', 'sin', 'sinh', 'tan', 'tanh', 'frexp',
}
local singleargposdomain = {
'log', 'sqrt', 'ceil',
}
local twoargfunctions = {
'atan2',
}
local twoargsposdomain = {
'pow', 'fmod',
}
-- single argument tests
for i,v in ipairs(singleargfunctions) do
local funcname = 'math.'..v
banner(funcname)
checkallpass(funcname,{somenumber})
checkallerrors(funcname,{notanumber},'bad argument')
end
-- single argument, positive domain tests
for i,v in ipairs(singleargposdomain) do
local funcname = 'math.'..v
banner(funcname)
checkallpass(funcname,{somepositive})
checkallerrors(funcname,{notanumber},'bad argument')
end
-- two-argument tests
for i,v in ipairs(twoargfunctions) do
local funcname = 'math.'..v
banner(funcname)
checkallpass(funcname,{somenumber,somenumber})
checkallerrors(funcname,{},'bad argument')
checkallerrors(funcname,{notanumber},'bad argument')
checkallerrors(funcname,{notanumber,somenumber},'bad argument')
checkallerrors(funcname,{somenumber},'bad argument')
checkallerrors(funcname,{somenumber,notanumber},'bad argument')
end
-- two-argument, positive domain tests
for i,v in ipairs(twoargsposdomain) do
local funcname = 'math.'..v
banner(funcname)
checkallpass(funcname,{somepositive,somenumber})
checkallerrors(funcname,{},'bad argument')
checkallerrors(funcname,{notanumber},'bad argument')
checkallerrors(funcname,{notanumber,somenumber},'bad argument')
checkallerrors(funcname,{somenumber},'bad argument')
checkallerrors(funcname,{somenumber,notanumber},'bad argument')
end
-- math.max
banner('math.max')
checkallpass('math.max',{somenumber})
checkallpass('math.max',{somenumber,somenumber})
checkallerrors('math.max',{},'bad argument')
checkallerrors('math.max',{nonnumber},'bad argument')
checkallerrors('math.max',{somenumber,nonnumber},'bad argument')
-- math.min
banner('math.min')
checkallpass('math.min',{somenumber})
checkallpass('math.min',{somenumber,somenumber})
checkallerrors('math.min',{},'bad argument')
checkallerrors('math.min',{nonnumber},'bad argument')
checkallerrors('math.min',{somenumber,nonnumber},'bad argument')
-- math.random
local somem = {3,4.5,'6.7'}
local somen = {8,9.10,'12.34'}
local notamn = {astring,aboolean,atable,afunction}
banner('math.random')
checkallpass('math.random',{},true)
checkallpass('math.random',{somem},true)
checkallpass('math.random',{somem,somen},true)
checkallpass('math.random',{{-4,-5.6,'-7','-8.9'},{-1,100,23.45,'-1.23'}},true)
checkallerrors('math.random',{{-4,-5.6,'-7','-8.9'}},'interval is empty')
checkallerrors('math.random',{somen,somem},'interval is empty')
checkallerrors('math.random',{notamn,somen},'bad argument')
checkallerrors('math.random',{somem,notamn},'bad argument')
-- math.ldexp
local somee = {-3,0,3,9.10,'12.34'}
local notae = {nil,astring,aboolean,atable,afunction}
banner('math.ldexp')
checkallpass('math.ldexp',{somenumber,somee})
checkallerrors('math.ldexp',{},'bad argument')
checkallerrors('math.ldexp',{notanumber},'bad argument')
checkallerrors('math.ldexp',{notanumber,somee},'bad argument')
checkallerrors('math.ldexp',{somenumber},'bad argument')
checkallerrors('math.ldexp',{somenumber,notae},'bad argument')

View File

@@ -1,21 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg type tests for module library functions
-- require
banner('require')
checkallpass('require',{{'math','coroutine','package','string','table'}},true)
checkallerrors('require',{{anumber}},'not found')
checkallerrors('require',{{anil,aboolean,afunction,atable}},'bad argument')
-- package.loadlib
banner('package.loadlib')
checkallpass('package.loadlib',{{'foo'},{'bar'}},true)
checkallerrors('package.loadlib',{notastring},'bad argument')
-- package.seeall
banner('package.seeall')
checkallpass('package.seeall',{sometable})
checkallerrors('package.seeall',{notatable},'bad argument')

View File

@@ -1,157 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg types for language operator
-- ========= unary operators: - # not
-- unary minus -
banner('unary -')
negative = function(a) return - a end
checkallpass('negative',{somenumber})
checkallerrors('negative',{notanumber},'attempt to perform arithmetic')
-- length
banner('#')
lengthop = function(a) return #a end
checkallpass('lengthop',{sometable})
checkallerrors('lengthop',{notatable},'attempt to get length of')
-- length
banner('not')
notop = function(a) return not a end
checkallpass('notop',{somenumber})
checkallpass('notop',{notanumber})
-- function call
banner( '()' )
funcop = function(a) return a() end
checkallpass('funcop',{somefunction})
checkallerrors('funcop',{notafunction},'attempt to call')
-- ========= binary ops: .. + - * / % ^ == ~= <= >= < > [] . and or
banner( '..' )
concatop = function(a,b) return a..b end
checkallpass('concatop',{somestring,somestring})
checkallerrors('concatop',{notastring,somestring},'attempt to concatenate')
checkallerrors('concatop',{somestring,notastring},'attempt to concatenate')
banner( '+' )
plusop = function(a,b) return a+b end
checkallpass('plusop',{somenumber,somenumber})
checkallerrors('plusop',{notanumber,somenumber},'attempt to perform arithmetic')
checkallerrors('plusop',{somenumber,notanumber},'attempt to perform arithmetic')
banner( '-' )
minusop = function(a,b) return a-b end
checkallpass('minusop',{somenumber,somenumber})
checkallerrors('minusop',{notanumber,somenumber},'attempt to perform arithmetic')
checkallerrors('minusop',{somenumber,notanumber},'attempt to perform arithmetic')
banner( '*' )
timesop = function(a,b) return a*b end
checkallpass('timesop',{somenumber,somenumber})
checkallerrors('timesop',{notanumber,somenumber},'attempt to perform arithmetic')
checkallerrors('timesop',{somenumber,notanumber},'attempt to perform arithmetic')
banner( '/' )
divideop = function(a,b) return a/b end
checkallpass('divideop',{somenumber,somenumber})
checkallerrors('divideop',{notanumber,somenumber},'attempt to perform arithmetic')
checkallerrors('divideop',{somenumber,notanumber},'attempt to perform arithmetic')
banner( '%' )
modop = function(a,b) return a%b end
checkallpass('modop',{somenumber,somenumber})
checkallerrors('modop',{notanumber,somenumber},'attempt to perform arithmetic')
checkallerrors('modop',{somenumber,notanumber},'attempt to perform arithmetic')
banner( '^' )
powerop = function(a,b) return a^b end
checkallpass('powerop',{{2,'2.5'},{3,'3.5'}})
checkallerrors('powerop',{notanumber,{3,'3.1'}},'attempt to perform arithmetic')
checkallerrors('powerop',{{2,'2.1'},notanumber},'attempt to perform arithmetic')
banner( '==' )
equalsop = function(a,b) return a==b end
checkallpass('equalsop',{anylua,anylua})
banner( '~=' )
noteqop = function(a,b) return a~=b end
checkallpass('noteqop',{anylua,anylua})
banner( '<=' )
leop = function(a,b) return a<=b end
checkallpass('leop',{{anumber},{anumber}})
checkallpass('leop',{{astring,astrnum},{astring,astrnum}})
checkallerrors('leop',{notanumber,{anumber}},'attempt to compare')
checkallerrors('leop',{{astrnum},{anumber}},'attempt to compare')
checkallerrors('leop',{notastring,{astring,astrnum}},'attempt to compare')
checkallerrors('leop',{{anumber},notanumber},'attempt to compare')
checkallerrors('leop',{{anumber},{astrnum}},'attempt to compare')
checkallerrors('leop',{{astring,astrnum},notastring},'attempt to compare')
banner( '>=' )
geop = function(a,b) return a>=b end
checkallpass('geop',{{anumber},{anumber}})
checkallpass('geop',{{astring,astrnum},{astring,astrnum}})
checkallerrors('geop',{notanumber,{anumber}},'attempt to compare')
checkallerrors('geop',{{astrnum},{anumber}},'attempt to compare')
checkallerrors('geop',{notastring,{astring,astrnum}},'attempt to compare')
checkallerrors('geop',{{anumber},notanumber},'attempt to compare')
checkallerrors('geop',{{anumber},{astrnum}},'attempt to compare')
checkallerrors('geop',{{astring,astrnum},notastring},'attempt to compare')
banner( '<' )
ltop = function(a,b) return a<b end
checkallpass('ltop',{{anumber},{anumber}})
checkallpass('ltop',{{astring,astrnum},{astring,astrnum}})
checkallerrors('ltop',{notanumber,{anumber}},'attempt to compare')
checkallerrors('ltop',{{astrnum},{anumber}},'attempt to compare')
checkallerrors('ltop',{notastring,{astring,astrnum}},'attempt to compare')
checkallerrors('ltop',{{anumber},notanumber},'attempt to compare')
checkallerrors('ltop',{{anumber},{astrnum}},'attempt to compare')
checkallerrors('ltop',{{astring,astrnum},notastring},'attempt to compare')
banner( '>' )
gtop = function(a,b) return a>b end
checkallpass('gtop',{{anumber},{anumber}})
checkallpass('gtop',{{astring,astrnum},{astring,astrnum}})
checkallerrors('gtop',{notanumber,{anumber}},'attempt to compare')
checkallerrors('gtop',{{astrnum},{anumber}},'attempt to compare')
checkallerrors('gtop',{notastring,{astring,astrnum}},'attempt to compare')
checkallerrors('gtop',{{anumber},notanumber},'attempt to compare')
checkallerrors('gtop',{{anumber},{astrnum}},'attempt to compare')
checkallerrors('gtop',{{astring,astrnum},notastring},'attempt to compare')
banner( '[]' )
bracketop = function(a,b) return a[b] end
checkallpass('bracketop',{sometable,notanil})
checkallerrors('bracketop',{notatable,notanil},'attempt to index')
checkallerrors('bracketop',{sometable},'attempt to index')
banner( '.' )
dotop = function(a,b) return a.b end
checkallpass('dotop',{sometable,notanil})
checkallerrors('dotop',{notatable,notanil},'attempt to index')
checkallerrors('dotop',{sometable},'attempt to index')
banner( 'and' )
types = {['table']='table',['function']='function',['thread']='thread'}
clean = function(x) return types[type(x)] or x end
andop = function(a,b) return clean(a and b) end
checkallpass('andop',{anylua,anylua})
banner( 'or' )
orop = function(a,b) return clean(a or b) end
checkallpass('orop',{anylua,anylua})
-- ========= for x in y
banner( 'for x=a,b,c' )
forop = function(a,b,c) for x=a,b,c do end end
checkallpass('forop',{{1,'1.1'},{10,'10.1'},{2,'2.1'}})
checkallerrors('forop',{notanumber,{10,'10.1'},{2,'2.1'}},"'for' initial value must be a number")
checkallerrors('forop',{{1,'1.1'},notanumber,{2,'2.1'}},"'for' limit must be a number")
checkallerrors('forop',{{1,'1.1'},{10,'10.1'},notanumber},"'for' step must be a number")

View File

@@ -1,120 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg type tests for string library functions
-- string.byte
banner('string.byte')
checkallpass('string.byte',{somestring})
checkallpass('string.byte',{somestring,somenumber})
checkallpass('string.byte',{somestring,somenumber,somenumber})
checkallerrors('string.byte',{somestring,{astring,afunction,atable}},'bad argument')
checkallerrors('string.byte',{notastring,{nil,111,n=2}},'bad argument')
-- string.char
function string_char(...)
return string.byte( string.char( ... ) )
end
banner('string_char')
checkallpass('string.char',{{60}})
checkallpass('string.char',{{60},{70}})
checkallpass('string.char',{{60},{70},{80}})
checkallpass('string_char',{{0,9,40,127,128,255,'0','9','255','9.2',9.2}})
checkallpass('string_char',{{0,127,255},{0,127,255}})
checkallerrors('string_char',{},'bad argument')
checkallerrors('string_char',{{nil,-1,256,3}},'bad argument')
checkallerrors('string_char',{notanumber,{23,'45',6.7}},'bad argument')
checkallerrors('string_char',{{23,'45',6.7},nonnumber},'bad argument')
-- string.dump
banner('string.dump')
local someupval = 435
local function funcwithupvals() return someupval end
checkallpass('string.dump',{{function() return 123 end}})
checkallpass('string.dump',{{funcwithupvals}})
checkallerrors('string.dump',{notafunction},'bad argument')
-- string.find
banner('string.find')
checkallpass('string.find',{somestring,somestring})
checkallpass('string.find',{somestring,somestring,{nil,-3,3,n=3}})
checkallpass('string.find',{somestring,somestring,somenumber,anylua})
checkallerrors('string.find',{notastring,somestring},'bad argument')
checkallerrors('string.find',{somestring,notastring},'bad argument')
checkallerrors('string.find',{somestring,somestring,nonnumber},'bad argument')
-- string.format
--local numfmts = {'%c','%d','%E','%e','%f','%g','%G','%i','%o','%u','%X','%x'}
local numfmts = {'%c','%d','%i','%o','%u','%X','%x'}
local strfmts = {'%q','%s'}
local badfmts = {'%w'}
banner('string.format')
checkallpass('string.format',{somestring,anylua})
checkallpass('string.format',{numfmts,somenumber})
checkallpass('string.format',{strfmts,somestring})
checkallerrors('string.format',{numfmts,notanumber},'bad argument')
checkallerrors('string.format',{strfmts,notastring},'bad argument')
checkallerrors('string.format',{badfmts,somestring},"invalid option '%w'")
-- string.gmatch
banner('string.gmatch')
checkallpass('string.gmatch',{somestring,somestring})
checkallerrors('string.gmatch',{notastring,somestring},'bad argument')
checkallerrors('string.gmatch',{somestring,notastring},'bad argument')
-- string.gsub
local somerepl = {astring,atable,afunction}
local notarepl = {nil,aboolean,n=2}
banner('string.gsub')
checkallpass('string.gsub',{somestring,somestring,somerepl,{nil,-1,n=2}})
checkallerrors('string.gsub',{nonstring,somestring,somerepl},'bad argument')
checkallerrors('string.gsub',{somestring,nonstring,somerepl},'bad argument')
checkallerrors('string.gsub',{{astring},{astring},notarepl},'bad argument')
checkallerrors('string.gsub',{{astring},{astring},somerepl,nonnumber},'bad argument')
-- string.len
banner('string.len')
checkallpass('string.len',{somestring})
checkallerrors('string.len',{notastring},'bad argument')
-- string.lower
banner('string.lower')
checkallpass('string.lower',{somestring})
checkallerrors('string.lower',{notastring},'bad argument')
-- string.match
banner('string.match')
checkallpass('string.match',{somestring,somestring})
checkallpass('string.match',{somestring,somestring,{nil,-3,3,n=3}})
checkallerrors('string.match',{},'bad argument')
checkallerrors('string.match',{nonstring,somestring},'bad argument')
checkallerrors('string.match',{somestring},'bad argument')
checkallerrors('string.match',{somestring,nonstring},'bad argument')
checkallerrors('string.match',{somestring,somestring,notanumber},'bad argument')
-- string.reverse
banner('string.reverse')
checkallpass('string.reverse',{somestring})
checkallerrors('string.reverse',{notastring},'bad argument')
-- string.rep
banner('string.rep')
checkallpass('string.rep',{somestring,somenumber})
checkallerrors('string.rep',{notastring,somenumber},'bad argument')
checkallerrors('string.rep',{somestring,notanumber},'bad argument')
-- string.sub
banner('string.sub')
checkallpass('string.sub',{somestring,somenumber})
checkallpass('string.sub',{somestring,somenumber,somenumber})
checkallerrors('string.sub',{},'bad argument')
checkallerrors('string.sub',{nonstring,somenumber,somenumber},'bad argument')
checkallerrors('string.sub',{somestring},'bad argument')
checkallerrors('string.sub',{somestring,nonnumber,somenumber},'bad argument')
checkallerrors('string.sub',{somestring,somenumber,nonnumber},'bad argument')
-- string.upper
banner('string.upper')
checkallpass('string.upper',{somestring})
checkallerrors('string.upper',{notastring},'bad argument')

View File

@@ -1,70 +0,0 @@
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg type tests for table library functions
-- table.concat
local somestringstable = {{8,7,6,5,4,3,2,1,}}
local somenonstringtable = {{true,true,true,true,true,true,true,true,}}
local somesep = {',',1.23}
local notasep = {aboolean,atable,afunction}
local somei = {2,'2','2.2'}
local somej = {4,'4','4.4'}
local notij = {astring,aboolean,atable,afunction}
banner('table.concat')
checkallpass('table.concat',{somestringstable})
checkallpass('table.concat',{somestringstable,somesep})
checkallpass('table.concat',{somestringstable,{'-'},somei})
checkallpass('table.concat',{somestringstable,{'-'},{2},somej})
checkallerrors('table.concat',{notatable},'bad argument')
checkallerrors('table.concat',{somenonstringtable},'boolean')
checkallerrors('table.concat',{somestringstable,notasep},'bad argument')
checkallerrors('table.concat',{somestringstable,{'-'},notij},'bad argument')
checkallerrors('table.concat',{somestringstable,{'-'},{2},notij},'bad argument')
-- table.insert
banner('table.insert')
checkallpass('table.insert',{sometable,notanil})
checkallpass('table.insert',{sometable,somei,notanil})
checkallerrors('table.insert',{notatable,somestring},'bad argument')
checkallerrors('table.insert',{sometable,notij,notanil},'bad argument')
-- table.remove
banner('table.remove')
checkallpass('table.remove',{sometable})
checkallpass('table.remove',{sometable,somei})
checkallerrors('table.remove',{notatable},'bad argument')
checkallerrors('table.remove',{notatable,somei},'bad argument')
checkallerrors('table.remove',{sometable,notij},'bad argument')
-- table.sort
local somecomp = {nil,afunction,n=2}
local notacomp = {astring,anumber,aboolean,atable}
banner('table.sort')
checkallpass('table.sort',{somestringstable,somecomp})
checkallerrors('table.sort',{sometable},'attempt to')
checkallerrors('table.sort',{notatable,somecomp},'bad argument')
checkallerrors('table.sort',{sometable,notacomp},'bad argument')
-- table get
banner('table_get - tbl[key]')
function table_get(tbl,key) return tbl[key] end
checkallpass('table_get',{sometable,anylua})
-- table set
banner('table_set - tbl[key]=val')
function table_set(tbl,key,val) tbl[key]=val end
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')