Improve error tests

This commit is contained in:
James Roseborough
2010-05-12 05:00:09 +00:00
parent 38acf6a75e
commit d3dcd4bdf3
4 changed files with 64 additions and 64 deletions

View File

@@ -12,7 +12,7 @@ checkallerrors('assert',{{nil,false,n=2},{'message'}},'message')
-- collectgarbage
banner('collectgarbage')
checkallpass('collectgarbage',{{'collect','count'}},true)
checkallerrors('collectgarbage',{{astring, anumber}},'bad argument #1')
checkallerrors('collectgarbage',{{astring, anumber}},'bad argument')
checkallerrors('collectgarbage',{{aboolean, atable, afunction, athread}},'string expected')
-- dofile
@@ -20,7 +20,7 @@ banner('dofile')
checkallpass('dofile', {})
checkallpass('dofile', {{'test/lua/errors/args.lua'}})
checkallerrors('dofile', {{'args.lua'}}, 'cannot open args.lua')
checkallerrors('dofile', {nonstring}, 'bad argument #1')
checkallerrors('dofile', {nonstring}, 'bad argument')
-- error
banner('error')
@@ -30,23 +30,23 @@ checkallerrors('error', {{123},{nil,1,2}}, 123)
-- getfenv
banner('getfenv')
checkallpass('getfenv', {{nil,print,function()end,0,1,2}})
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument #1')
checkallerrors('getfenv', {{true,{},'abc'}}, 'bad argument')
-- getmetatable
banner('getmetatable')
checkallpass('getmetatable', {notanil})
checkallerrors('getmetatable',{},'bad argument #1')
checkallerrors('getmetatable',{},'bad argument')
-- ipairs
banner('ipairs')
checkallpass('ipairs', {sometable})
checkallerrors('ipairs', {notatable}, 'bad argument #1')
checkallerrors('ipairs', {notatable}, 'bad argument')
-- load
banner('load')
checkallpass('load', {somefunction,{nil,astring}})
checkallerrors('load', {notafunction,{nil,astring,anumber}}, 'bad argument #1')
checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument #2')
checkallerrors('load', {notafunction,{nil,astring,anumber}}, 'bad argument')
checkallerrors('load', {somefunction,{afunction,atable}}, 'bad argument')
-- loadfile
banner('loadfile')
@@ -54,7 +54,7 @@ checkallpass('loadfile', {})
checkallpass('loadfile', {{'bogus'}})
checkallpass('loadfile', {{'test/lua/errors/args.lua'}})
checkallpass('loadfile', {{'args.lua'}})
checkallerrors('loadfile', {nonstring}, 'bad argument #1')
checkallerrors('loadfile', {nonstring}, 'bad argument')
-- loadstring
banner('loadstring')
@@ -62,24 +62,24 @@ checkallpass('loadstring', {{'return'}})
checkallpass('loadstring', {{'return'},{'mychunk'}})
checkallpass('loadstring', {{'return a ... b'},{'mychunk'}},true)
checkallerrors('loadstring', {{'return a ... b'},{'mychunk'}},'hello')
checkallerrors('loadstring', {notastring,{nil,astring,anumber}}, 'bad argument #1')
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument #2')
checkallerrors('loadstring', {notastring,{nil,astring,anumber}}, 'bad argument')
checkallerrors('loadstring', {{'return'},{afunction,atable}}, 'bad argument')
-- next
banner('next')
checkallpass('next', {sometable,somekey})
checkallerrors('next', {notatable,{nil,1}}, 'bad argument #1')
checkallerrors('next', {notatable,{nil,1}}, 'bad argument')
checkallerrors('next', {sometable,nonkey}, 'invalid key')
-- pairs
banner('pairs')
checkallpass('pairs', {sometable})
checkallerrors('pairs', {notatable}, 'bad argument #1')
checkallerrors('pairs', {notatable}, 'bad argument')
-- pcall
banner('pcall')
checkallpass('pcall', {notanil,anylua}, true)
checkallerrors('pcall',{},'bad argument #1')
checkallerrors('pcall',{},'bad argument')
-- print
banner('print')
@@ -89,30 +89,30 @@ checkallpass('print', {{nil,astring,anumber,aboolean}})
-- rawequal
banner('rawequal')
checkallpass('rawequal', {notanil,notanil})
checkallerrors('rawequal', {}, 'bad argument #1')
checkallerrors('rawequal', {notanil}, 'bad argument #2')
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 #2')
checkallerrors('rawget', {notatable,notakey}, 'bad argument #1')
checkallerrors('rawget', {}, 'bad argument #1')
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 #1')
checkallerrors('rawset', {notatable,somestring,somestring}, 'bad argument #1')
checkallerrors('rawset', {sometable,somekey}, 'bad argument #3')
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 #1')
checkallerrors('select', {notanumber}, 'bad argument')
-- setfenv
banner('setfenv')
@@ -121,24 +121,24 @@ 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 #1')
checkallerrors('setfenv', {notafunction}, 'bad argument #2')
checkallerrors('setfenv', {anylua}, 'bad argument #2')
checkallerrors('setfenv', {{function()end},notatable}, 'bad argument #2')
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})
checkallpass('setmetatable', {sometable,{}})
checkallerrors('setmetatable',{notatable,sometable},'bad argument #1')
checkallerrors('setmetatable',{sometable,notatable},'bad argument #2')
checkallerrors('setmetatable',{notatable,sometable},'bad argument')
checkallerrors('setmetatable',{sometable,notatable},'bad argument')
-- tonumber
banner('tonumber')
checkallpass('tonumber',{somenumber,{nil,2,10,36}})
checkallpass('tonumber',{notanil,{nil,10}})
checkallerrors('tonumber',{{nil,afunction,atable},{2,9,11,36}},'bad argument #1')
checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument #2')
checkallerrors('tonumber',{{nil,afunction,atable},{2,9,11,36}},'bad argument')
checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument')
-- tostring
banner('tostring')
@@ -146,7 +146,7 @@ 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 #1')
checkallerrors('tostring',{},'bad argument')
-- type
banner('type')
@@ -159,14 +159,14 @@ banner('unpack')
checkallpass('unpack',{sometable})
checkallpass('unpack',{sometable,somenumber})
checkallpass('unpack',{sometable,somenumber,somenumber})
checkallerrors('unpack',{notatable,somenumber,somenumber},'bad argument #1')
checkallerrors('unpack',{sometable,nonnumber,somenumber},'bad argument #2')
checkallerrors('unpack',{sometable,somenumber,nonnumber},'bad argument #3')
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})
checkallpass('xpcall', {notanil,{function(...)return 'aaa', 'bbb', #{...} end}})
checkallerrors('xpcall',{anylua},'bad argument #2')
checkallerrors('xpcall',{anylua},'bad argument')

View File

@@ -12,7 +12,7 @@ checkallerrors('coroutine.create',{notafunction},'bad argument')
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 #1')
checkallerrors('coroutine.resume',{notathread},'bad argument')
-- coroutine.running
banner('coroutine.running')
@@ -21,12 +21,12 @@ checkallpass('coroutine.running',{anylua})
-- coroutine.status
banner('coroutine.status')
checkallpass('coroutine.status',{{co}})
checkallerrors('coroutine.status',{notathread},'bad argument #1')
checkallerrors('coroutine.status',{notathread},'bad argument')
-- coroutine.wrap
banner('coroutine.wrap')
checkallpass('coroutine.wrap',{somefunction})
checkallerrors('coroutine.wrap',{notafunction},'bad argument #1')
checkallerrors('coroutine.wrap',{notafunction},'bad argument')
-- coroutine.yield
banner('coroutine.yield')

View File

@@ -8,54 +8,54 @@ local f
banner('io.close')
f = io.open("abc.txt","w")
checkallpass('io.close',{{f}})
checkallerrors('io.close',{notanil},'bad argument #1')
checkallerrors('io.close',{notanil},'bad argument')
-- io.input ([file])
f = io.open("abc.txt","r")
checkallpass('io.input',{{nil,f,"abc.txt"}})
checkallerrors('io.input',{nonstring},'bad argument #1')
checkallpass('io.input',{{nil,f,"abc.txt",n=3}})
checkallerrors('io.input',{nonstring},'bad argument')
-- io.lines ([filename])
io.input("abc.txt")
checkallpass('io.lines',{{nil,"abc.txt"}})
checkallerrors('io.lines',{{f}},'bad argument #1')
checkallerrors('io.lines',{nonstring},'bad argument #1')
checkallpass('io.lines',{{nil,"abc.txt",n=2}})
checkallerrors('io.lines',{{f}},'bad argument')
checkallerrors('io.lines',{nonstring},'bad argument')
-- io.open (filename [, mode])
checkallpass('io.open',{{"abc.txt"},{nil,"r","w","a","r+","w+","a+"}})
checkallerrors('io.open',{notastring},'bad argument #1')
checkallerrors('io.open',{{"abc.txt"},{nonstring}},'bad argument #2')
checkallerrors('io.open',{notastring},'bad argument')
checkallerrors('io.open',{{"abc.txt"},{nonstring}},'bad argument')
-- io.output ([file])
checkallpass('io.output',{{nil,f,"abc.txt"}})
checkallerrors('io.output',{nonstring},'bad argument #1')
checkallpass('io.output',{{nil,f,"abc.txt",n=3}})
checkallerrors('io.output',{nonstring},'bad argument')
-- io.popen (prog [, mode])
checkallpass('io.popen',{{"hostname"},{nil,"r","w","a","r+","w+","a+"}})
checkallerrors('io.popen',{notastring},'bad argument #1')
checkallerrors('io.popen',{{"hostname"},{nonstring}},'bad argument #2')
checkallpass('io.popen',{{"hostname"},{nil,"w",n=2}})
checkallerrors('io.popen',{notastring},'bad argument')
checkallerrors('io.popen',{{"hostname"},{nonstring}},'bad argument')
-- io.read (···)
local areadfmt = {2,"*n","*a","*l","3"}
checkallpass('io.read',{})
checkallpass('io.read',{areadfmt})
checkallpass('io.read',{areadfmt,areadfmt})
checkallerrors('io.read',{{aboolean,afunction,atable}},'bad argument #1')
checkallerrors('io.read',{{aboolean,afunction,atable}},'bad argument')
-- io.read (···)
checkallpass('io.write',{})
checkallpass('io.write',{somestring})
checkallpass('io.write',{somestring,somestring})
checkallerrors('io.write',{nonstring},'bad argument #1')
checkallerrors('io.write',{somestring,nonstring},'bad argument #2')
checkallerrors('io.write',{nonstring},'bad argument')
checkallerrors('io.write',{somestring,nonstring},'bad argument')
-- file:write ()
file = io.open("seektest.txt","w")
checkallpass('file.write',{{file},somestring})
checkallpass('file.write',{{file},somestring,somestring})
checkallerrors('file.write',{},'bad argument #1')
checkallerrors('file.write',{{file},nonstring},'bad argument #1')
checkallerrors('file.write',{{file},somestring,nonstring},'bad argument #2')
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])
@@ -63,14 +63,14 @@ 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 #1')
checkallerrors('file.seek',{{file},nonstring},'bad argument #1')
checkallerrors('file.seek',{{file},{"set","cur","end"},nonnumber},'bad argument #2')
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])
checkallpass('file.setvbuf',{{file},{"no","full","line"}})
checkallpass('file.setvbuf',{{file},{"full"},{1024,"512"}})
checkallerrors('file.setvbuf',{},'bad argument #1')
checkallerrors('file.setvbuf',{{file},notastring},'bad argument #1')
checkallerrors('file.setvbuf',{{file},{"full"},nonnumber},'bad argument #2')
checkallerrors('file.setvbuf',{},'bad argument')
checkallerrors('file.setvbuf',{{file},notastring},'bad argument')
checkallerrors('file.setvbuf',{{file},{"full"},nonnumber},'bad argument')