Add coroutine library argument type check tests.

This commit is contained in:
James Roseborough
2008-07-15 22:13:12 +00:00
parent bc279c7a9b
commit 07b9297adc
2 changed files with 53 additions and 7 deletions

View File

@@ -53,16 +53,19 @@ notatable = except(sometable)
notafunction = except(somefunction)
notanil = except(somenil)
local structtypes = {
['table']='<table>',
['function']='<function>',
['thread']='<thread>',
['userdata']='<userdata>',
}
local function signature(name,arglist)
local t = {}
for i=1,#arglist do
if type(arglist[i]) == 'table' then
t[i] = 'table'
elseif type(arglist[i]) == 'function' then
t[i] = 'function'
else
t[i] = tostring(arglist[i])
end
local ai = arglist[i]
local ti = type(ai)
t[i] = structtypes[ti] or tostring(ai)
end
return name..'('..table.concat(t,',')..')'
end

View 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'