Add coroutine library argument type check tests.
This commit is contained in:
@@ -53,16 +53,19 @@ notatable = except(sometable)
|
|||||||
notafunction = except(somefunction)
|
notafunction = except(somefunction)
|
||||||
notanil = except(somenil)
|
notanil = except(somenil)
|
||||||
|
|
||||||
|
local structtypes = {
|
||||||
|
['table']='<table>',
|
||||||
|
['function']='<function>',
|
||||||
|
['thread']='<thread>',
|
||||||
|
['userdata']='<userdata>',
|
||||||
|
}
|
||||||
|
|
||||||
local function signature(name,arglist)
|
local function signature(name,arglist)
|
||||||
local t = {}
|
local t = {}
|
||||||
for i=1,#arglist do
|
for i=1,#arglist do
|
||||||
if type(arglist[i]) == 'table' then
|
local ai = arglist[i]
|
||||||
t[i] = 'table'
|
local ti = type(ai)
|
||||||
elseif type(arglist[i]) == 'function' then
|
t[i] = structtypes[ti] or tostring(ai)
|
||||||
t[i] = 'function'
|
|
||||||
else
|
|
||||||
t[i] = tostring(arglist[i])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return name..'('..table.concat(t,',')..')'
|
return name..'('..table.concat(t,',')..')'
|
||||||
end
|
end
|
||||||
|
|||||||
43
src/test/errors/coroutinelibargs.lua
Normal file
43
src/test/errors/coroutinelibargs.lua
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
package.path = "?.lua;src/test/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',{anylua},'bad argument')
|
||||||
|
|
||||||
|
-- coroutine.running
|
||||||
|
banner('coroutine.running')
|
||||||
|
checkallpass('coroutine.running',{anylua})
|
||||||
|
|
||||||
|
-- coroutine.status
|
||||||
|
banner('coroutine.status')
|
||||||
|
checkallpass('coroutine.status',{{co}})
|
||||||
|
checkallerrors('coroutine.status',{anylua},'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) )
|
||||||
|
print( 'yield', coroutine.yield(anumber) )
|
||||||
|
print( 'yield', coroutine.yield(aboolean) )
|
||||||
|
end
|
||||||
|
local co = coroutine.create( f )
|
||||||
|
repeat
|
||||||
|
print( 'resume', coroutine.resume(co,astring,anumber) )
|
||||||
|
until coroutine.status(co) ~= 'suspended'
|
||||||
|
|
||||||
Reference in New Issue
Block a user