2010-05-09 23:51:46 +00:00
|
|
|
|
package.path = "?.lua;test/lua/errors/?.lua"
|
2008-12-05 01:47:50 +00:00
|
|
|
|
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}})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('io.close',{notanil},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.input ([file])
|
2008-12-05 22:29:07 +00:00
|
|
|
|
f = io.open("abc.txt","r")
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallpass('io.input',{{nil,f,"abc.txt",n=3}})
|
|
|
|
|
|
checkallerrors('io.input',{nonstring},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.lines ([filename])
|
|
|
|
|
|
io.input("abc.txt")
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallpass('io.lines',{{nil,"abc.txt",n=2}})
|
|
|
|
|
|
checkallerrors('io.lines',{{f}},'bad argument')
|
|
|
|
|
|
checkallerrors('io.lines',{nonstring},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.open (filename [, mode])
|
|
|
|
|
|
checkallpass('io.open',{{"abc.txt"},{nil,"r","w","a","r+","w+","a+"}})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('io.open',{notastring},'bad argument')
|
|
|
|
|
|
checkallerrors('io.open',{{"abc.txt"},{nonstring}},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.output ([file])
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallpass('io.output',{{nil,f,"abc.txt",n=3}})
|
|
|
|
|
|
checkallerrors('io.output',{nonstring},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.popen (prog [, mode])
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallpass('io.popen',{{"hostname"},{nil,"w",n=2}})
|
|
|
|
|
|
checkallerrors('io.popen',{notastring},'bad argument')
|
|
|
|
|
|
checkallerrors('io.popen',{{"hostname"},{nonstring}},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.read (<28><><EFBFBD>)
|
|
|
|
|
|
local areadfmt = {2,"*n","*a","*l","3"}
|
|
|
|
|
|
checkallpass('io.read',{})
|
|
|
|
|
|
checkallpass('io.read',{areadfmt})
|
|
|
|
|
|
checkallpass('io.read',{areadfmt,areadfmt})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('io.read',{{aboolean,afunction,atable}},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- io.read (<28><><EFBFBD>)
|
|
|
|
|
|
checkallpass('io.write',{})
|
|
|
|
|
|
checkallpass('io.write',{somestring})
|
|
|
|
|
|
checkallpass('io.write',{somestring,somestring})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('io.write',{nonstring},'bad argument')
|
|
|
|
|
|
checkallerrors('io.write',{somestring,nonstring},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
|
|
|
|
|
-- file:write ()
|
|
|
|
|
|
file = io.open("seektest.txt","w")
|
|
|
|
|
|
checkallpass('file.write',{{file},somestring})
|
|
|
|
|
|
checkallpass('file.write',{{file},somestring,somestring})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('file.write',{},'bad argument')
|
|
|
|
|
|
checkallerrors('file.write',{{file},nonstring},'bad argument')
|
|
|
|
|
|
checkallerrors('file.write',{{file},somestring,nonstring},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
pcall( file.close, file )
|
|
|
|
|
|
|
|
|
|
|
|
-- file:seek ([whence] [, offset])
|
|
|
|
|
|
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"}})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('file.seek',{},'bad argument')
|
|
|
|
|
|
checkallerrors('file.seek',{{file},nonstring},'bad argument')
|
|
|
|
|
|
checkallerrors('file.seek',{{file},{"set","cur","end"},nonnumber},'bad argument')
|
2008-12-05 01:47:50 +00:00
|
|
|
|
|
2008-12-05 18:25:30 +00:00
|
|
|
|
-- file:setvbuf (mode [, size])
|
|
|
|
|
|
checkallpass('file.setvbuf',{{file},{"no","full","line"}})
|
|
|
|
|
|
checkallpass('file.setvbuf',{{file},{"full"},{1024,"512"}})
|
2010-05-12 05:00:09 +00:00
|
|
|
|
checkallerrors('file.setvbuf',{},'bad argument')
|
|
|
|
|
|
checkallerrors('file.setvbuf',{{file},notastring},'bad argument')
|
|
|
|
|
|
checkallerrors('file.setvbuf',{{file},{"full"},nonnumber},'bad argument')
|
2008-12-05 18:25:30 +00:00
|
|
|
|
|