Files
luaj/test/lua/errors/baselibargs.lua

146 lines
4.7 KiB
Lua
Raw Permalink Normal View History

2010-05-09 23:51:46 +00:00
package.path = "?.lua;test/lua/errors/?.lua"
require 'args'
-- arg types for basic library functions
-- assert
banner('assert')
checkallpass('assert',{{true,123},anylua})
2010-05-09 23:51:46 +00:00
checkallerrors('assert',{{nil,false,n=2},{nil,n=1}},'assertion failed')
checkallerrors('assert',{{nil,false,n=2},{'message'}},'message')
-- collectgarbage
banner('collectgarbage')
2008-07-22 01:20:25 +00:00
checkallpass('collectgarbage',{{'collect','count'}},true)
2010-05-12 05:00:09 +00:00
checkallerrors('collectgarbage',{{astring, anumber}},'bad argument')
2010-05-10 00:07:54 +00:00
checkallerrors('collectgarbage',{{aboolean, atable, afunction, athread}},'string expected')
2008-07-17 01:23:33 +00:00
-- 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})
2010-05-12 05:00:09 +00:00
checkallerrors('getmetatable',{},'bad argument')
-- ipairs
banner('ipairs')
checkallpass('ipairs', {sometable})
2010-05-12 05:00:09 +00:00
checkallerrors('ipairs', {notatable}, 'bad argument')
-- load
banner('load')
2010-05-15 21:56:29 +00:00
checkallpass('load', {somefunction,{nil,astring,n=2}})
checkallerrors('load', {notafunction,{nil,astring,anumber,n=3}}, 'bad argument')
2010-05-12 05:00:09 +00:00
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})
2010-05-15 21:56:29 +00:00
checkallerrors('next', {notatable,{nil,1,n=2}}, 'bad argument')
2008-07-17 01:23:33 +00:00
checkallerrors('next', {sometable,nonkey}, 'invalid key')
-- pairs
banner('pairs')
checkallpass('pairs', {sometable})
2010-05-12 05:00:09 +00:00
checkallerrors('pairs', {notatable}, 'bad argument')
-- pcall
banner('pcall')
2008-07-22 14:56:13 +00:00
checkallpass('pcall', {notanil,anylua}, true)
2010-05-12 05:00:09 +00:00
checkallerrors('pcall',{},'bad argument')
-- print
banner('print')
checkallpass('print', {})
2010-05-15 21:56:29 +00:00
checkallpass('print', {{nil,astring,anumber,aboolean,n=4}})
-- rawequal
banner('rawequal')
checkallpass('rawequal', {notanil,notanil})
2010-05-12 05:00:09 +00:00
checkallerrors('rawequal', {}, 'bad argument')
checkallerrors('rawequal', {notanil}, 'bad argument')
-- rawget
banner('rawget')
checkallpass('rawget', {sometable,somekey})
2008-07-17 01:23:33 +00:00
checkallpass('rawget', {sometable,nonkey})
2010-05-12 05:00:09 +00:00
checkallerrors('rawget', {sometable,somenil},'bad argument')
checkallerrors('rawget', {notatable,notakey}, 'bad argument')
checkallerrors('rawget', {}, 'bad argument')
-- rawset
banner('rawset')
checkallpass('rawset', {sometable,somekey,notanil})
2008-07-17 01:23:33 +00:00
checkallpass('rawset', {sometable,nonkey,notanil})
checkallerrors('rawset', {sometable,somenil},'table index is nil')
2010-05-12 05:00:09 +00:00
checkallerrors('rawset', {}, 'bad argument')
checkallerrors('rawset', {notatable,somestring,somestring}, 'bad argument')
checkallerrors('rawset', {sometable,somekey}, 'bad argument')
-- select
banner('select')
checkallpass('select', {{anumber,'#'},anylua})
2010-05-12 05:00:09 +00:00
checkallerrors('select', {notanumber}, 'bad argument')
-- setmetatable
banner('setmetatable')
checkallpass('setmetatable', {sometable,sometable})
2008-07-22 14:56:13 +00:00
checkallpass('setmetatable', {sometable,{}})
2010-05-12 05:00:09 +00:00
checkallerrors('setmetatable',{notatable,sometable},'bad argument')
2010-05-16 05:09:47 +00:00
checkallerrors('setmetatable',{sometable,nontable},'bad argument')
-- tonumber
banner('tonumber')
2010-05-15 21:56:29 +00:00
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')
2010-05-12 05:00:09 +00:00
checkallerrors('tonumber',{somenumber,{1,37,atable,afunction,aboolean}},'bad argument')
-- tostring
banner('tostring')
2008-07-22 01:20:25 +00:00
checkallpass('tostring',{{astring,anumber,aboolean}})
checkallpass('tostring',{{atable,afunction,athread}},true)
checkallpass('tostring',{{astring,anumber,aboolean},{'anchor'}})
checkallpass('tostring',{{atable,afunction,athread},{'anchor'}},true)
2010-05-12 05:00:09 +00:00
checkallerrors('tostring',{},'bad argument')
-- type
banner('type')
checkallpass('type',{notanil})
checkallpass('type',{anylua,{'anchor'}})
checkallerrors('type',{},'bad argument')
-- xpcall
banner('xpcall')
2008-07-22 01:20:25 +00:00
checkallpass('xpcall', {notanil,nonfunction})
checkallpass('xpcall', {notanil,{function(...)return 'aaa', 'bbb', #{...} end}})
2010-05-12 05:00:09 +00:00
checkallerrors('xpcall',{anylua},'bad argument')